Last active
March 7, 2020 02:45
-
-
Save z4yx/476e4d34c3e87721f6b94deffaee1482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// bash -c 'CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o clean clean.go' | |
// Usage: | |
// bandersnatch -c /tmp/b.conf verify --delete --dry-run &>verify-dry-run.log | |
// ./clean <verify-dry-run.log >clean.log | |
import ( "fmt";"log"; "os"; "time";"bufio";"strings" ) | |
func main() { | |
now := time.Now() | |
size:=int64(0) | |
thr := 48.0 //time.Duration(48)*time.Hour | |
reader := bufio.NewReader(os.Stdin) | |
for { | |
text, err := reader.ReadString('\n') | |
if err !=nil || strings.Contains(text, "We have"){ | |
break | |
} | |
} | |
for i:=0;;i++ { | |
text, _, err := reader.ReadLine() | |
line := string(text) | |
if err !=nil { | |
break | |
} | |
fileinfo, err := os.Stat(line) | |
if err != nil { | |
continue | |
// log.Fatal(err) | |
} | |
dur := now.Sub(fileinfo.ModTime()) | |
sz := fileinfo.Size() | |
fmt.Printf("%d %s %d %s", i, dur, sz, line) | |
if dur.Hours() > thr { | |
size += sz | |
fmt.Printf(" deleting\n"); | |
err = os.Remove(line) | |
if err != nil { | |
log.Fatal(err) | |
} | |
}else{ | |
fmt.Printf(" skipping\n"); | |
} | |
} | |
fmt.Printf("%d bytes removed\n", size) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment