Skip to content

never, ever overwrite files #49

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jrpie
Copy link
Contributor

@jrpie jrpie commented Jul 12, 2025

After PR #48 there still remains a case where vimv can overwrite files:
Suppose the directory structure is

.
├── myfile
└── t
    └── myfile

vimv will show

myfile
t

Renaming myfile to t/myfile will cause an overwrite.
Moreover the directory structure might have changed since the user started vimv.

This PR adds a check to never overwrite files ever. A warning is printed, but the renaming process continues, as it is probably easier to recover from a situation where one file was not moved correctly then from the situation where vimv stopped working in the middle of the renaming process.
Furthermore the PR reduces code duplication.

@thameera
Copy link
Owner

@jrpie Thanks. If I understand correctly, the return 1 in safeMove() combined with the set -eu on the top would cause the script to fail fast, rather than continuing the renaming process, correct?

@jrpie
Copy link
Contributor Author

jrpie commented Jul 16, 2025

oh, yes, you're right. Sorry, I was not familiar with set -e, should have properly tested the code. The idea of returning 1 was to only increase count when the file is actually moved. Failing fast is not what I wanted to do.
As in my first message, I'd argue that only printing a warning but continuing would be better (but that is certainly debatable…)

else
mv -- "${dest[i]}.${EXT}" "${dest[i]}"
fi
safeMove "${dest[i]}.${EXT}" "${dest[i]}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is safeMove "${dest[i]}.${EXT}" "${dest[i]}" || : ignore error idiomatic to avoid exiting on error due to set -e?

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

Successfully merging this pull request may close these issues.

2 participants