mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-26 22:24:58 +08:00
check same source path after clean
This commit is contained in:
parent
7ab2aee878
commit
ac672113f2
2 changed files with 23 additions and 0 deletions
11
mmv.go
11
mmv.go
|
|
@ -31,6 +31,14 @@ func (err *emptyPathError) Error() string {
|
|||
return "empty path error"
|
||||
}
|
||||
|
||||
type sameSourceError struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (err *sameSourceError) Error() string {
|
||||
return fmt.Sprintf("duplicate source: %s", err.path)
|
||||
}
|
||||
|
||||
type sameDestinationError struct {
|
||||
path string
|
||||
}
|
||||
|
|
@ -57,6 +65,9 @@ func buildRenames(files map[string]string) ([]rename, error) {
|
|||
if d := filepath.Clean(src); d != src {
|
||||
delete(files, src)
|
||||
src = d
|
||||
if _, ok := files[src]; ok {
|
||||
return nil, &sameSourceError{src}
|
||||
}
|
||||
files[src] = dst
|
||||
}
|
||||
if d := filepath.Clean(dst); d != dst {
|
||||
|
|
|
|||
12
mmv_test.go
12
mmv_test.go
|
|
@ -186,6 +186,18 @@ func TestRename(t *testing.T) {
|
|||
"foo": "1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cleaned path same source error",
|
||||
files: map[string]string{
|
||||
"foo": "baz",
|
||||
"bar/../foo": "bar",
|
||||
},
|
||||
contents: map[string]string{
|
||||
"foo": "0",
|
||||
"bar": "1",
|
||||
},
|
||||
err: &sameSourceError{"foo"},
|
||||
},
|
||||
{
|
||||
name: "cleaned path same destination error",
|
||||
files: map[string]string{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue