add -real flag to really run repo deletions

This commit is contained in:
Shawn Smith
2017-11-09 15:35:24 +09:00
parent 3cd9b78af3
commit 64fe3a2238

View File

@@ -1,13 +1,17 @@
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"time"
)
var real = flag.Bool("real", false, "run the deletions")
func main() {
flag.Parse()
files, err := ioutil.ReadDir("_repos/src")
if err != nil {
log.Fatal(err)
@@ -22,8 +26,12 @@ func main() {
for _, d := range dirs {
if time.Now().Sub(d.ModTime()) > 30*24*time.Hour {
path := "_repos/src/" + f.Name() + "/" + d.Name()
log.Printf("Deleting %s...", path)
os.RemoveAll(path)
if *real {
log.Printf("Deleting %s...", path)
os.RemoveAll(path)
} else {
log.Printf("Would delete %s", path)
}
}
}
}