From 7eabb39c54b96fca347a0576f501239d89bd8ec6 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 22 Jan 2021 13:57:34 +0300 Subject: [PATCH] cleanup -dry-run --- cleanup.go | 27 ++++++++++++++++++++------- doc/news.texi | 7 +++++++ usage.go | 4 ++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cleanup.go b/cleanup.go index 2c4268c..61f028f 100644 --- a/cleanup.go +++ b/cleanup.go @@ -18,6 +18,7 @@ along with this program. If not, see . package main import ( + "flag" "fmt" "io" "log" @@ -33,6 +34,10 @@ const ( CleanupTmp = "tmp" ) +var ( + DryRun = flag.Bool("dry-run", false, "do no delete files during cleanup, just show them") +) + func redoDirClean(root, what string) error { root, err := filepath.Abs(root) if err != nil { @@ -57,15 +62,19 @@ func redoDirClean(root, what string) error { case CleanupLog: if strings.HasSuffix(fi.Name(), LogSuffix) { fmt.Println(pth) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } case CleanupTmp: if strings.HasPrefix(fi.Name(), TmpPrefix) { fmt.Println(pth) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } default: @@ -101,7 +110,9 @@ func cleanupWalker(root, what string) error { if fi.Name() == RedoDir { if what == CleanupFull { fmt.Println(pthRel) - err = os.RemoveAll(pth) + if !*DryRun { + err = os.RemoveAll(pth) + } } else { err = redoDirClean(pth, what) } @@ -116,8 +127,10 @@ func cleanupWalker(root, what string) error { if (what == CleanupTmp || what == CleanupFull) && strings.HasPrefix(fi.Name(), TmpPrefix) { fmt.Println(pthRel) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } } diff --git a/doc/news.texi b/doc/news.texi index 3d5a651..99faeda 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -1,6 +1,13 @@ @node News @unnumbered News +@anchor{Release 1.1.0} +@section Release 1.1.0 +@itemize +@item + @command{redo-cleanup} has @option{-dry-run} option. +@end itemize + @anchor{Release 1.0.0} @section Release 1.0.0 @itemize diff --git a/usage.go b/usage.go index 5948b69..d31db40 100644 --- a/usage.go +++ b/usage.go @@ -26,7 +26,7 @@ import ( ) const ( - Version = "1.0.0" + Version = "1.1.0" Warranty = `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 the Free Software Foundation, version 3 of the License. @@ -61,7 +61,7 @@ You can create them by running: goredo -symlinks. forcefully and *sequentially* build specified targets * redo-always always build current target. Unusable outside .do -* redo-cleanup {full,log,tmp} [...] +* redo-cleanup [-dry-run] {full,log,tmp} [...] remove either all goredo's related temporary files, or kept stderr logs, or everything (including .redo directories) related * redo-dot target [...] -- 2.44.0