symlinks.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. ## This module implements symlink (symbolic link) handling.
  2. from paths import Path, ReadDirEffect
  3. from std/private/ossymlinks import symlinkExists, createSymlink, expandSymlink
  4. proc symlinkExists*(link: Path): bool {.inline, tags: [ReadDirEffect].} =
  5. ## Returns true if the symlink `link` exists. Will return true
  6. ## regardless of whether the link points to a directory or file.
  7. result = symlinkExists(link.string)
  8. proc createSymlink*(src, dest: Path) {.inline.} =
  9. ## Create a symbolic link at `dest` which points to the item specified
  10. ## by `src`. On most operating systems, will fail if a link already exists.
  11. ##
  12. ## .. warning:: Some OS's (such as Microsoft Windows) restrict the creation
  13. ## of symlinks to root users (administrators) or users with developer mode enabled.
  14. ##
  15. ## See also:
  16. ## * `createHardlink proc`_
  17. ## * `expandSymlink proc`_
  18. createSymlink(src.string, dest.string)
  19. proc expandSymlink*(symlinkPath: Path): Path {.inline.} =
  20. ## Returns a string representing the path to which the symbolic link points.
  21. ##
  22. ## On Windows this is a noop, `symlinkPath` is simply returned.
  23. ##
  24. ## See also:
  25. ## * `createSymlink proc`_
  26. result = Path(expandSymlink(symlinkPath.string))