Implement Unix file regularity check (#20448) (#20628)

* Implement Unix file regularity check

* update std/dirs also
This commit is contained in:
Andrey Makarov 2022-10-25 08:42:47 +03:00 • committed by GitHub
commit 8ed2431db0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 45 deletions

View file

@ -77,14 +77,17 @@ type
when defined(posix) and not weirdTarget:
proc getSymlinkFileKind*(path: string): PathComponent =
proc getSymlinkFileKind*(path: string):
tuple[pc: PathComponent, isRegular: bool] =
# Helper function.
var s: Stat
assert(path != "")
if stat(path, s) == 0'i32 and S_ISDIR(s.st_mode):
result = pcLinkToDir
else:
result = pcLinkToFile
result = (pcLinkToFile, true)
if stat(path, s) == 0'i32:
if S_ISDIR(s.st_mode):
result = (pcLinkToDir, true)
elif not S_ISREG(s.st_mode):
result = (pcLinkToFile, false)
proc tryMoveFSObject*(source, dest: string, isDir: bool): bool {.noWeirdTarget.} =
## Moves a file (or directory if `isDir` is true) from `source` to `dest`.