symlinks.nim 1.2 KB

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