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
This commit is contained in:
ringabout 2022-10-22 03:53:44 +08:00 • committed by GitHub
commit 3c12b72168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 775 additions and 0 deletions

30
lib/std/symlinks.nim Normal file
View file

@ -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))