relative.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # Test "ln --relative".
  3. # Copyright (C) 2012-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ln
  16. mkdir -p usr/bin || framework_failure_
  17. mkdir -p usr/lib/foo || framework_failure_
  18. touch usr/lib/foo/foo || framework_failure_
  19. ln -sr usr/lib/foo/foo usr/bin/foo
  20. test $(readlink usr/bin/foo) = '../lib/foo/foo' || fail=1
  21. ln -sr usr/bin/foo usr/lib/foo/link-to-foo
  22. test $(readlink usr/lib/foo/link-to-foo) = 'foo' || fail=1
  23. # Correctly update an existing link, which was broken in <= 8.21
  24. ln -s dir1/dir2/f existing_link
  25. ln -srf here existing_link
  26. test $(readlink existing_link) = 'here' || fail=1
  27. # Demonstrate resolved symlinks used to generate relative links
  28. # so here, 'web/latest' will not be linked to the intermediate 'latest' link.
  29. # You'd probably want to use realpath(1) in conjunction
  30. # with ln(1) without --relative to give greater control.
  31. ln -s release1 alpha
  32. ln -s release2 beta
  33. ln -s beta latest
  34. mkdir web
  35. ln -sr latest web/latest
  36. test $(readlink web/latest) = '../release2' || fail=1
  37. # Expect this to fail with exit status 1, or to succeed quietly (freebsd).
  38. # Prior to coreutils-8.23, it would segfault.
  39. ln -sr '' F
  40. case $? in [01]) ;; *) fail=1;; esac
  41. Exit $fail