summaryrefslogtreecommitdiff
path: root/src/ln.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-06-29 03:58:48 +0000
committerJim Meyering <jim@meyering.net>1996-06-29 03:58:48 +0000
commite81d02baf15b7132b2b28439e81c71652f4667cf (patch)
tree7903a07efe53f07b633e8e061d8be5daeda41a91 /src/ln.c
parentb73817cc6e47d32a61e5304fa407c97235ae9be8 (diff)
downloadcoreutils-e81d02baf15b7132b2b28439e81c71652f4667cf.tar.xz
(do_link): Allow `ln -sf --backup k k' to succeed in creating the
self-referential symlink, doing so doesn't remove the source but merely renames it.
Diffstat (limited to 'src/ln.c')
-rw-r--r--src/ln.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/ln.c b/src/ln.c
index c193bd52c..ee3e793fc 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -190,11 +190,19 @@ do_link (const char *source, const char *dest)
return 1;
}
- /* If --force (-f) has been specified, before making a link ln must
- remove the destination file if it exists. But if the source and
- destination are the same, don't remove anything and fail right here. */
+ /* If --force (-f) has been specified without --backup, then before
+ making a link ln must remove the destination file if it exists.
+ (with --backup, it just renames any existing destination file)
+ But if the source and destination are the same, don't remove
+ anything and fail right here. */
if (remove_existing_files
&& lstat_status == 0
+ /* Allow `ln -sf --backup k k' to succeed in creating the
+ self-referential symlink, but don't allow the hard-linking
+ equivalent: `ln -f k k' (with or without --backup) to get
+ beyond this point, because the error message you'd get is
+ misleading. */
+ && (backup_type == none || !symlink)
&& (!symlink || stat (source, &source_stats) == 0)
&& source_stats.st_dev == dest_stats.st_dev
&& source_stats.st_ino == dest_stats.st_ino