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.

Ideally, `checkLinkTargets` and `linkGeneration` should be more tightly
coupled.
  • Loading branch information
ncfavier committed Jan 3, 2023
1 parent c1a830c commit af4d6e7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ in
$VERBOSE_ECHO "Skipping '$targetPath' as it is identical to '$sourcePath'"
else
# Place that symlink, --force
# This can still fail if the target is a directory, in which case we bail out.
$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 af4d6e7

Please sign in to comment.