mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
added cleanup function to remove temporary file
This commit is contained in:
parent
95de3790d7
commit
0d8e4e10d6
4 changed files with 21 additions and 2 deletions
1
device-a/text.txt
Normal file
1
device-a/text.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
asdf
|
2
main.go
2
main.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/schollz/croc/v10/src/cli"
|
"github.com/schollz/croc/v10/src/cli"
|
||||||
|
"github.com/schollz/croc/v10/src/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -47,6 +48,7 @@ func main() {
|
||||||
|
|
||||||
// Perform any necessary cleanup here
|
// Perform any necessary cleanup here
|
||||||
log.Println("Performing cleanup...")
|
log.Println("Performing cleanup...")
|
||||||
|
utils.CleanupTempData()
|
||||||
|
|
||||||
// Exit the program gracefully
|
// Exit the program gracefully
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -446,9 +446,15 @@ func getStdin() (fnames []string, err error) {
|
||||||
fnames = []string{f.Name()}
|
fnames = []string{f.Name()}
|
||||||
return
|
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) {
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -610,3 +610,13 @@ func ValidFileName(fname string) (err error) {
|
||||||
}
|
}
|
||||||
return
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue