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

Allow multiple backups files #6243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions modules/files/check-link-targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ for sourcePath in "$@" ; do
elif [[ ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
# Next, try to move the file to a backup location if configured and possible
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
if [[ -e "$backup" ]]; then
errorEcho "Existing file '$backup' would be clobbered by backing up '$targetPath'"
collision=1
else
warnEcho "Existing file '$targetPath' is in the way of '$sourcePath', will be moved to '$backup'"
fi

# Check for backup existence and iterate until finding an available filename
counter=1
while [[ -e "$backup" ]]; do
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT.$counter"
counter=$((counter + 1))
done
Comment on lines +38 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

stat tends to be slow in some systems (especially in macOS), and considering that this is affecting you at every new generation it means you will eventually end up having multiple files and your switch taking longer and longer.

I concur with @teto here, it is better to use force in your case.


warnEcho "Existing file '$targetPath' is in the way of '$sourcePath', will be moved to '$backup'"
mv "$targetPath" "$backup"
else
# Fail if nothing else works
errorEcho "Existing file '$targetPath' is in the way of '$sourcePath'"
Expand Down
Loading