1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-10 21:01:02 +02:00

added cleanup function to remove temporary file

This commit is contained in:
Prince 2024-09-03 18:56:46 -07:00
parent 95de3790d7
commit 0d8e4e10d6
4 changed files with 21 additions and 2 deletions

1
device-a/text.txt Normal file
View file

@ -0,0 +1 @@
asdf

View file

@ -11,6 +11,7 @@ import (
"syscall"
"github.com/schollz/croc/v10/src/cli"
"github.com/schollz/croc/v10/src/utils"
)
func main() {
@ -47,6 +48,7 @@ func main() {
// Perform any necessary cleanup here
log.Println("Performing cleanup...")
utils.CleanupTempData()
// Exit the program gracefully
os.Exit(0)

View file

@ -446,9 +446,15 @@ func getStdin() (fnames []string, err error) {
fnames = []string{f.Name()}
return
}
func makeTempFolder() {
path := "temp"
if _, err := os.Stat(path); os.IsNotExist(err) {
os.Mkdir(path, os.ModePerm)
}
}
func makeTempFileWithString(s string) (fnames []string, err error) {
f, err := os.CreateTemp(".", "croc-stdin-")
makeTempFolder()
f, err := os.CreateTemp("temp", "croc-stdin-")
if err != nil {
return
}

View file

@ -610,3 +610,13 @@ func ValidFileName(fname string) (err error) {
}
return
}
func CleanupTempData() {
path := "temp"
// Remove the directory and its contents
err := os.RemoveAll(path)
if err != nil {
log.Fatal(err)
} else {
log.Println("Directory and its contents deleted successfully")
}
}