Check if the path to rename is too broad as safety measure

This commit is contained in:
Felipe Martin 2019-08-05 19:30:41 +02:00
parent 58bba89588
commit 25652f0d87
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
1 changed files with 13 additions and 0 deletions

13
main.go
View File

@ -11,6 +11,7 @@ import (
const defaultAllowedExtensions = "jpg,jpeg,png,gif,avi,mp4,mov"
var extensions = flag.String("extensions", defaultAllowedExtensions, "Comma separated extensions to allow")
var force = flag.Bool("force", false, "Force execution without safety checks")
func stringInSlice(a string, list []string) bool {
for _, b := range list {
@ -50,6 +51,18 @@ func main() {
panic(err)
}
if !*force {
// Count the number of paths separators and don't allow executing
// if the path is too close to the root folder without the force
// flag
sublevels := strings.Split(path, string(filepath.Separator))[1:]
if len(sublevels) < 3 {
fmt.Printf("%s seems too broad.\n", path)
fmt.Println("If you're sure use the -force flag.")
os.Exit(1)
}
}
fmt.Printf("Walking by %s...\n", path)
err2 := filepath.Walk(path, readDir)