mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-26 14:14:57 +08:00
clean source path as well to allow directory rename cycle
This commit is contained in:
parent
e3710bd25c
commit
0926ef4faa
2 changed files with 21 additions and 0 deletions
5
mmv.go
5
mmv.go
|
|
@ -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
|
||||
|
|
|
|||
16
mmv_test.go
16
mmv_test.go
|
|
@ -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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue