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

@ -548,3 +548,21 @@ proc moveDir*(source, dest: string) {.tags: [ReadIOEffect, WriteIOEffect], noWei
# Fallback to copy & del
copyDir(source, dest)
removeDir(source)
proc setCurrentDir*(newDir: string) {.inline, tags: [], noWeirdTarget.} =
## Sets the `current working directory`:idx:; `OSError`
## is raised if `newDir` cannot been set.
##
## See also:
## * `getHomeDir proc`_
## * `getConfigDir proc`_
## * `getTempDir proc`_
## * `getCurrentDir proc`_
when defined(windows):
when useWinUnicode:
if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
raiseOSError(osLastError(), newDir)
else:
if setCurrentDirectoryA(newDir) == 0'i32: raiseOSError(osLastError(), newDir)
else:
if chdir(newDir) != 0'i32: raiseOSError(osLastError(), newDir)