summary refs log tree commit diff stats
path: root/lib/std/symlinks.nim
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-22 03:53:44 +0800
committerGitHub <noreply@github.com>2022-10-21 21:53:44 +0200
commit3c12b72168d9fe9916f471fa17d2c24c52b33066 (patch)
tree067a76c67e104b2d4d1e31bc9d0ea4b193824233 /lib/std/symlinks.nim
parent66cbcaab8474f5ff3480e7a9bc55df249548a90c (diff)
downloadNim-3c12b72168d9fe9916f471fa17d2c24c52b33066.tar.gz
add typesafe `std/paths`, `std/files`, `std/dirs`, `std/symlinks` (#20582)
* split std/os; add typesafe std/paths
* add more files, dirs, paths
* add documentation
* add testcase
* remove tryRemoveFile
* clean up
* Delete test.nim
* apply changes
* add `add` and fixes
Diffstat (limited to 'lib/std/symlinks.nim')
-rw-r--r--lib/std/symlinks.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/std/symlinks.nim b/lib/std/symlinks.nim
new file mode 100644
index 000000000..cb469d8c3
--- /dev/null
+++ b/lib/std/symlinks.nim
@@ -0,0 +1,30 @@
+from paths import Path, ReadDirEffect
+
+from std/private/ossymlinks import symlinkExists, createSymlink, expandSymlink
+
+
+proc symlinkExists*(link: Path): bool {.inline, tags: [ReadDirEffect].} =
+  ## Returns true if the symlink `link` exists. Will return true
+  ## regardless of whether the link points to a directory or file.
+  result = symlinkExists(link.string)
+
+proc createSymlink*(src, dest: Path) {.inline.} =
+  ## Create a symbolic link at `dest` which points to the item specified
+  ## by `src`. On most operating systems, will fail if a link already exists.
+  ##
+  ## .. warning:: Some OS's (such as Microsoft Windows) restrict the creation
+  ##   of symlinks to root users (administrators) or users with developer mode enabled.
+  ##
+  ## See also:
+  ## * `createHardlink proc`_
+  ## * `expandSymlink proc`_
+  createSymlink(src.string, dest.string)
+
+proc expandSymlink*(symlinkPath: Path): Path {.inline.} =
+  ## Returns a string representing the path to which the symbolic link points.
+  ##
+  ## On Windows this is a noop, `symlinkPath` is simply returned.
+  ##
+  ## See also:
+  ## * `createSymlink proc`_
+  result = Path(expandSymlink(symlinkPath.string))