diff --git a/main.go b/main.go index 31e81be..29d3dce 100644 --- a/main.go +++ b/main.go @@ -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)