clean up std/os related modules (#20651)

* clean up `std/os` related modules

* use `cmpPaths`

* reset

* cleanup
This commit is contained in:
ringabout 2022-10-25 17:56:11 +08:00 • committed by GitHub
commit 69eaa4f14c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 157 deletions

View file

@ -1,7 +1,7 @@
from paths import Path, ReadDirEffect, WriteDirEffect
from std/private/osdirs import dirExists, createDir, existsOrCreateDir, removeDir,
moveDir, walkPattern, walkFiles, walkDirs, walkDir,
moveDir, walkDir, setCurrentDir,
walkDirRec, PathComponent
export PathComponent
@ -76,51 +76,6 @@ proc moveDir*(source, dest: Path) {.inline, tags: [ReadIOEffect, WriteIOEffect].
## * `createDir proc`_
moveDir(source.string, dest.string)
iterator walkPattern*(pattern: Path): Path {.tags: [ReadDirEffect].} =
## Iterate over all the files and directories that match the `pattern`.
##
## On POSIX this uses the `glob`:idx: call.
## `pattern` is OS dependent, but at least the `"*.ext"`
## notation is supported.
##
## See also:
## * `walkFiles iterator`_
## * `walkDirs iterator`_
## * `walkDir iterator`_
## * `walkDirRec iterator`_
for p in walkPattern(pattern.string):
yield Path(p)
iterator walkFiles*(pattern: Path): Path {.tags: [ReadDirEffect].} =
## Iterate over all the files that match the `pattern`.
##
## On POSIX this uses the `glob`:idx: call.
## `pattern` is OS dependent, but at least the `"*.ext"`
## notation is supported.
##
## See also:
## * `walkPattern iterator`_
## * `walkDirs iterator`_
## * `walkDir iterator`_
## * `walkDirRec iterator`_
for p in walkFiles(pattern.string):
yield Path(p)
iterator walkDirs*(pattern: Path): Path {.tags: [ReadDirEffect].} =
## Iterate over all the directories that match the `pattern`.
##
## On POSIX this uses the `glob`:idx: call.
## `pattern` is OS dependent, but at least the `"*.ext"`
## notation is supported.
##
## See also:
## * `walkPattern iterator`_
## * `walkFiles iterator`_
## * `walkDir iterator`_
## * `walkDirRec iterator`_
for p in walkDirs(pattern.string):
yield Path(p)
iterator walkDir*(dir: Path; relative = false, checkDir = false,
onlyRegular = false):
tuple[kind: PathComponent, path: Path] {.tags: [ReadDirEffect].} =
@ -179,3 +134,11 @@ iterator walkDirRec*(dir: Path,
for p in walkDirRec(dir.string, yieldFilter, followFilter, relative,
checkDir, onlyRegular):
yield Path(p)
proc setCurrentDir*(newDir: Path) {.inline, tags: [].} =
## Sets the `current working directory`:idx:; `OSError`
## is raised if `newDir` cannot been set.
##
## See also:
## * `getCurrentDir proc`_
osdirs.setCurrentDir(newDir.string)