X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=cleanup.go;h=e00e3ff299842929f37ea8a5129abe82d36b68ea;hb=0d0e69d21056fe2c199beb7e7ce82572ae688825;hp=61f028f2d56dc6d600a1146ff1ac7d640f5cef56;hpb=7eabb39c54b96fca347a0576f501239d89bd8ec6;p=goredo.git diff --git a/cleanup.go b/cleanup.go index 61f028f..e00e3ff 100644 --- a/cleanup.go +++ b/cleanup.go @@ -1,6 +1,6 @@ /* goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2021 Sergey Matveev +Copyright (C) 2020-2022 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 @@ -34,9 +34,14 @@ const ( CleanupTmp = "tmp" ) -var ( - DryRun = flag.Bool("dry-run", false, "do no delete files during cleanup, just show them") -) +var DryRun *bool + +func init() { + if CmdName() != CmdNameRedoCleanup { + return + } + DryRun = flag.Bool("n", false, "do no delete files during cleanup, just show them") +} func redoDirClean(root, what string) error { root, err := filepath.Abs(root) @@ -60,7 +65,8 @@ func redoDirClean(root, what string) error { pth = cwdMustRel(root, fi.Name()) switch what { case CleanupLog: - if strings.HasSuffix(fi.Name(), LogSuffix) { + if strings.HasSuffix(fi.Name(), LogSuffix) || + strings.HasSuffix(fi.Name(), LogRecSuffix) { fmt.Println(pth) if !*DryRun { if err = os.Remove(pth); err != nil { @@ -116,6 +122,12 @@ func cleanupWalker(root, what string) error { } else { err = redoDirClean(pth, what) } + } else if (what == CleanupTmp || what == CleanupFull) && + strings.HasPrefix(fi.Name(), TmpPrefix) { + fmt.Println(pthRel) + if !*DryRun { + err = os.RemoveAll(pth) + } } else { err = cleanupWalker(pth, what) }