X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=cleanup.go;h=d0b508d44201a7645717f77192b653cd5f4f30ef;hb=4631e48a3b576942454e5534cd269ff3f5c1a56d;hp=d25aa3de02e91b31aabf7b758564f3de739eb244;hpb=b3631f17ba7427e538e8f6bd84ac4ead1aaab3f2;p=goredo.git diff --git a/cleanup.go b/cleanup.go index d25aa3d..d0b508d 100644 --- a/cleanup.go +++ b/cleanup.go @@ -1,6 +1,6 @@ /* goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2022 Sergey Matveev +Copyright (C) 2020-2023 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ const ( CleanupFull = "full" CleanupLog = "log" CleanupTmp = "tmp" + CleanupLock = "lock" ) var DryRun *bool @@ -54,7 +55,7 @@ func redoDirClean(root, what string) error { } defer dir.Close() for { - fis, err := dir.Readdir(1 << 10) + entries, err := dir.ReadDir(1 << 10) if err != nil { if err == io.EOF { break @@ -62,12 +63,21 @@ func redoDirClean(root, what string) error { return err } var pth string - for _, fi := range fis { - pth = cwdMustRel(root, fi.Name()) + for _, entry := range entries { + pth = cwdMustRel(root, entry.Name()) switch what { case CleanupLog: - if strings.HasSuffix(fi.Name(), LogSuffix) || - strings.HasSuffix(fi.Name(), LogRecSuffix) { + if strings.HasSuffix(entry.Name(), LogSuffix) || + strings.HasSuffix(entry.Name(), LogRecSuffix) { + fmt.Println(pth) + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } + } + } + case CleanupLock: + if strings.HasSuffix(entry.Name(), LockSuffix) { fmt.Println(pth) if !*DryRun { if err = os.Remove(pth); err != nil { @@ -76,7 +86,7 @@ func redoDirClean(root, what string) error { } } case CleanupTmp: - if strings.HasPrefix(fi.Name(), TmpPrefix) { + if strings.HasPrefix(entry.Name(), TmpPrefix) { fmt.Println(pth) if !*DryRun { if err = os.Remove(pth); err != nil { @@ -103,18 +113,18 @@ func cleanupWalker(root, what string) error { } defer dir.Close() for { - fis, err := dir.Readdir(1 << 10) + entries, err := dir.ReadDir(1 << 10) if err != nil { if err == io.EOF { break } return err } - for _, fi := range fis { - pth := path.Join(root, fi.Name()) - pthRel := cwdMustRel(root, fi.Name()) - if fi.IsDir() { - if fi.Name() == RedoDir { + for _, entry := range entries { + pth := path.Join(root, entry.Name()) + pthRel := cwdMustRel(root, entry.Name()) + if entry.IsDir() { + if entry.Name() == RedoDir { if what == CleanupFull { fmt.Println(pthRel) if !*DryRun { @@ -124,7 +134,7 @@ func cleanupWalker(root, what string) error { err = redoDirClean(pth, what) } } else if (what == CleanupTmp || what == CleanupFull) && - strings.HasPrefix(fi.Name(), TmpPrefix) { + strings.HasPrefix(entry.Name(), TmpPrefix) { fmt.Println(pthRel) if !*DryRun { err = os.RemoveAll(pth) @@ -138,7 +148,7 @@ func cleanupWalker(root, what string) error { continue } if (what == CleanupTmp || what == CleanupFull) && - strings.HasPrefix(fi.Name(), TmpPrefix) { + strings.HasPrefix(entry.Name(), TmpPrefix) { fmt.Println(pthRel) if !*DryRun { if err = os.Remove(pth); err != nil {