From a77d089f02c92d565970b1f2399b16c5a358b079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sun, 12 Jun 2022 16:26:29 +0200 Subject: [PATCH] files: avoid surprises when linking files 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. --- modules/files.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/files.nix b/modules/files.nix index a7fd67f57a0b..5ff8d7228c03 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -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 @@ -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 '';