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

@ -344,6 +344,8 @@ block walkDirRec:
removeDir("walkdir_test")
import std/sequtils
block: # walkDir
doAssertRaises(OSError):
for a in walkDir("nonexistent", checkDir = true): discard
@ -358,6 +360,21 @@ block: # walkDir
doAssert k == pcLinkToDir
removeDir("walkdir_test")
when defined(posix):
block walkDirRegular:
createDir("walkdir_test")
doAssert execShellCmd("mkfifo walkdir_test/fifo") == 0
createSymlink("fifo", "walkdir_test/fifo_link")
let withSpecialFiles = toSeq(walkDir("walkdir_test", relative = true))
doAssert (withSpecialFiles.len == 2 and
(pcFile, "fifo") in withSpecialFiles and
(pcLinkToFile, "fifo_link") in withSpecialFiles)
# now Unix special files are excluded from walkdir output:
let onlyRegularFiles = toSeq(walkDir("walkdir_test", relative = true,
onlyRegular = true))
doAssert onlyRegularFiles.len == 0
removeDir("walkdir_test")
block normalizedPath:
doAssert normalizedPath("") == ""
block relative:
@ -708,8 +725,6 @@ block: # isAdmin
# In Azure on POSIX tests run as a normal user
if isAzure and defined(posix): doAssert not isAdmin()
import std/sequtils
when doslikeFileSystem:
import std/private/ntpath