]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: add details on ln --relative symlink resolution
authorPádraig Brady <P@draigBrady.com>
Wed, 3 Apr 2013 17:33:43 +0000 (18:33 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 4 Apr 2013 01:46:52 +0000 (02:46 +0100)
* doc/coreutils.texi (ln invocation): Describe how symlinks are
resolved with --relative, and give an example showing the greater
control available through realpath(1).
* tests/ln/relative.sh: Add a test to demonstrate full symlink
resolution, in a case where it might not be wanted.

doc/coreutils.texi
tests/ln/relative.sh

index dfa9b1c21e45425a966799a95197e64d7a218379..4cfe4c50ce15dd07762fa5c3dadf070cee8016cd 100644 (file)
@@ -9798,8 +9798,24 @@ ln -srv /a/file /tmp
 '/tmp/file' -> '../a/file'
 @end smallexample
 
+Relative symbolic links are generated based on their canonicalized
+containing directory, and canonicalized targets.  I.E. all symbolic
+links in these file names will be resolved.
 @xref{realpath invocation}, which gives greater control
-over relative file name generation.
+over relative file name generation, as demonstrated in the following example:
+
+@example
+@verbatim
+ln--relative() {
+  test "$1" = --no-symlinks && { nosym=$1; shift; }
+  target="$1";
+  test -d "$2" && link="$2/." || link="$2"
+  rtarget="$(realpath $nosym -m "$target" \
+              --relative-to "$(dirname "$link")")"
+  ln -s -v "$rtarget" "$link"
+}
+@end verbatim
+@end example
 
 @item -s
 @itemx --symbolic
index 818da8392d1b41e65a2dbf66cea94bc824ea4ddd..8d4f1e7e0d8172f4c1020624f280e4d54676af91 100755 (executable)
@@ -34,4 +34,15 @@ ln -s dir1/dir2/f existing_link
 ln -srf here existing_link
 test $(readlink existing_link) = 'here' || fail=1
 
+# Demonstrate resolved symlinks used to generate relative links
+# so here, 'web/latest' will not be linked to the intermediate 'latest' link.
+# You'd probably want to use realpath(1) in conjunction
+# with ln(1) without --relative to give greater control.
+ln -s release1 alpha
+ln -s release2 beta
+ln -s beta latest
+mkdir web
+ln -sr latest web/latest
+test $(readlink web/latest) = '../release2' || fail=1
+
 Exit $fail