mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
repo cleanup tool delete repos < 15M
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -24,16 +25,41 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, d := range dirs {
|
||||
path := "_repos/src/" + f.Name() + "/" + d.Name()
|
||||
if time.Now().Sub(d.ModTime()) > 30*24*time.Hour {
|
||||
path := "_repos/src/" + f.Name() + "/" + d.Name()
|
||||
if *real {
|
||||
log.Printf("Deleting %s...", path)
|
||||
log.Printf("Deleting %s (repo is old)...", path)
|
||||
os.RemoveAll(path)
|
||||
continue
|
||||
} else {
|
||||
log.Printf("Would delete %s (repo is old)", path)
|
||||
}
|
||||
}
|
||||
|
||||
size, err := DirSize(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if size < 15*1000*1000 {
|
||||
if *real {
|
||||
log.Printf("Deleting %s (repo size < 15M)...", path)
|
||||
os.RemoveAll(path)
|
||||
} else {
|
||||
log.Printf("Would delete %s", path)
|
||||
log.Printf("Would delete %s (repo size < 15M)", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DirSize(path string) (int64, error) {
|
||||
var size int64
|
||||
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
size += info.Size()
|
||||
}
|
||||
return err
|
||||
})
|
||||
return size, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user