mirror of https://github.com/fmartingr/rnmr.git
Check if the path to rename is too broad as safety measure
This commit is contained in:
parent
58bba89588
commit
25652f0d87
13
main.go
13
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)
|
||||
|
|
Loading…
Reference in New Issue