Skip to content

Commit

Permalink
files: avoid surprises when linking files
Browse files Browse the repository at this point in the history
In the unlikely (but possible) event that a directory is created in
place of a target file *after* `checkLinkTargets` but *before*
`linkGeneration`, currently the link is created *inside* the directory,
which is surprising.

To avoid this, use `ln -T` and bail if it fails.

Also bail if backing up the target fails.

Ideally, `checkLinkTargets` and `linkGeneration` should be more tightly
coupled.
  • Loading branch information
ncfavier committed Jun 12, 2022
1 parent 64ab7d6 commit a77d089
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ in
if [[ -e "$targetPath" && ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
# The target exists, back it up
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
$DRY_RUN_CMD mv $VERBOSE_ARG "$targetPath" "$backup" || errorEcho "Moving '$targetPath' failed!"
$DRY_RUN_CMD mv $VERBOSE_ARG "$targetPath" "$backup" || exit 1
fi
if [[ -e "$targetPath" && ! -L "$targetPath" ]] && cmp -s "$sourcePath" "$targetPath" ; then
Expand All @@ -186,7 +186,7 @@ in
else
# Place that symlink, --force
$DRY_RUN_CMD mkdir -p $VERBOSE_ARG "$(dirname "$targetPath")"
$DRY_RUN_CMD ln -nsf $VERBOSE_ARG "$sourcePath" "$targetPath"
$DRY_RUN_CMD ln -Tsf $VERBOSE_ARG "$sourcePath" "$targetPath" || exit 1
fi
done
'';
Expand Down

0 comments on commit a77d089

Please sign in to comment.