Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmv can overwrite a file over already existing with the same name if it wasn't included in rename. #16

Closed
MahouShoujoMivutilde opened this issue Dec 18, 2021 · 2 comments

Comments

@MahouShoujoMivutilde
Copy link

How to reproduce

  1. Create some files that you could track by content
/tmp/test ❯ for i in $(seq 1 4); do echo $i > "test_$i.txt"; done

/tmp/test ❯ ls
test_1.txt  test_2.txt  test_3.txt  test_4.txt

/tmp/test ❯ cat test_1.txt
1
  1. Move test_1.txt -> test_3.txt and test_2.txt -> test_4.txt
/tmp/test ❯ mmv test_1.txt test_2.txt
  1. Notice, original 3 and 4 .txt are gone without any warning, replaced by 1 and 2
/tmp/test took 9s ❯ ls
test_3.txt  test_4.txt

/tmp/test ❯ cat test_3.txt
1

/tmp/test ❯ cat test_4.txt
2

/tmp/test ❯

I think expected behavior here is for mmv to abort rename to prevent unintended data loss, or e.g. -f flag if overwrite is truly expected and desired.

@itchyny
Copy link
Owner

itchyny commented Dec 19, 2021

This is an expected behavior of mmv for now.

@itchyny itchyny closed this as completed Dec 19, 2021
@MahouShoujoMivutilde
Copy link
Author

Got it.


Ironically, after finishing implementing my own and 2 days after creating this issue, I found already existing project that has all the features I wanted, including such protection.

I'll leave the link here for anyone who comes from the search.

Docs:

...
  Use the --force flag to overwrite existing files that aren't part
  of a renaming cycle. (Existing directories are never overwritten.
  If you attempt to overwrite a directory the program will exit with
  an error message and a non-zero status code.)
...

I hope you won't find this too offensive...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants