do a scan for possibly missed temp zip files and del

if they exist
This commit is contained in:
Evan Su 2025-04-12 20:27:55 -04:00
parent c8b25c04a2
commit 95ee00dd6b

View file

@ -185,7 +185,7 @@ func compress() int {
return 1
}
dir = filepath.ToSlash(dir)
file, err = os.CreateTemp("", "picocrypt-cli-v2-*.tmp")
file, err = os.CreateTemp("", "picocrypt-cli-v2-*.zip.tmp")
if err != nil {
fmt.Println("Cannot create temporary file!")
return 1
@ -193,6 +193,8 @@ func compress() int {
pzip = file.Name()
writer = zip.NewWriter(file)
fmt.Println("Info: creating temporary zip file " + pzip)
for i, path := range files {
stat, err := os.Stat(path)
if err != nil {
@ -344,7 +346,7 @@ func work() int {
hkdfSalt = make([]byte, 32)
serpentIV = make([]byte, 16)
nonce = make([]byte, 24)
_, errs[0] = fout.Write(rsEncode(rs5, []byte("v1.46")))
_, errs[0] = fout.Write(rsEncode(rs5, []byte("v1.48")))
_, errs[1] = fout.Write(rsEncode(rs5, []byte("00000")))
flags := make([]byte, 5)
if *p {
@ -685,4 +687,13 @@ func main() {
}
os.Exit(1)
}
td := os.TempDir()
matches, err := filepath.Glob(filepath.Join(td, "picocrypt-cli-v2-*.zip.tmp"))
if err != nil {
panic(err)
}
for _, v := range matches {
os.Remove(v)
}
}