clean source path as well to allow directory rename cycle

This commit is contained in:
itchyny 2020-01-08 01:21:15 +09:00
parent e3710bd25c
commit 0926ef4faa
2 changed files with 21 additions and 0 deletions

5
mmv.go
View file

@ -47,6 +47,11 @@ func buildRenames(files map[string]string) ([]rename, error) {
if src == "" || dst == "" {
return nil, &emptyPathError{}
}
if d := filepath.Clean(src); d != src {
delete(files, src)
src = d
files[src] = dst
}
if d := filepath.Clean(dst); d != dst {
dst = d
files[src] = dst

View file

@ -170,6 +170,22 @@ func TestRename(t *testing.T) {
},
err: &sameDestinationError{"baz"},
},
{
name: "clean source path",
files: map[string]string{
"foo": "bar",
"bar/": "foo/",
},
cnt: 3,
contents: map[string]string{
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"bar": "0",
"foo": "1",
},
},
{
name: "cleaned path same destination error",
files: map[string]string{