symlinks.nim 1.1 KB

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