better exception behavior for os.removeFile and os.removeDir
This commit is contained in:
parent
089e287c6e
commit
0ce9d49601
3 changed files with 13 additions and 11 deletions
|
|
@ -613,9 +613,13 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1".} =
|
||||||
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
|
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
|
||||||
if crename(source, dest) != 0'i32: OSError()
|
if crename(source, dest) != 0'i32: OSError()
|
||||||
|
|
||||||
|
when not defined(ENOENT):
|
||||||
|
var ENOENT* {.importc, header: "<errno.h>".}: cint
|
||||||
|
|
||||||
proc removeFile*(file: string) {.rtl, extern: "nos$1".} =
|
proc removeFile*(file: string) {.rtl, extern: "nos$1".} =
|
||||||
## Removes the `file`. If this fails, `EOS` is raised.
|
## Removes the `file`. If this fails, `EOS` is raised. This does not fail
|
||||||
if cremove(file) != 0'i32: OSError()
|
## if the file never existed in the first place.
|
||||||
|
if cremove(file) != 0'i32 and errno != ENOENT: OSError()
|
||||||
|
|
||||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1".} =
|
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1".} =
|
||||||
## Executes a `shell command`:idx:.
|
## Executes a `shell command`:idx:.
|
||||||
|
|
@ -855,13 +859,14 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string =
|
||||||
|
|
||||||
proc rawRemoveDir(dir: string) =
|
proc rawRemoveDir(dir: string) =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
if RemoveDirectoryA(dir) == 0'i32: OSError()
|
if RemoveDirectoryA(dir) == 0'i32 and GetLastError() != 3'i32: OSError()
|
||||||
else:
|
else:
|
||||||
if rmdir(dir) != 0'i32: OSError()
|
if rmdir(dir) != 0'i32 and errno != ENOENT: OSError()
|
||||||
|
|
||||||
proc removeDir*(dir: string) {.rtl, extern: "nos$1".} =
|
proc removeDir*(dir: string) {.rtl, extern: "nos$1".} =
|
||||||
## Removes the directory `dir` including all subdirectories and files
|
## Removes the directory `dir` including all subdirectories and files
|
||||||
## in `dir` (recursively). If this fails, `EOS` is raised.
|
## in `dir` (recursively). If this fails, `EOS` is raised. This does not fail
|
||||||
|
## if the directory never existed in the first place.
|
||||||
for kind, path in walkDir(dir):
|
for kind, path in walkDir(dir):
|
||||||
case kind
|
case kind
|
||||||
of pcFile, pcLinkToFile, pcLinkToDir: removeFile(path)
|
of pcFile, pcLinkToFile, pcLinkToDir: removeFile(path)
|
||||||
|
|
|
||||||
|
|
@ -272,12 +272,7 @@ proc run(r: var TResults, dir, options: string) =
|
||||||
const
|
const
|
||||||
rodfilesDir = "tests/rodfiles"
|
rodfilesDir = "tests/rodfiles"
|
||||||
|
|
||||||
proc delNimCache() =
|
proc delNimCache() = removeDir(rodfilesDir / "nimcache")
|
||||||
try:
|
|
||||||
removeDir(rodfilesDir / "nimcache")
|
|
||||||
except EOS:
|
|
||||||
nil
|
|
||||||
|
|
||||||
proc plusCache(options: string): string = return options & " --symbolFiles:on"
|
proc plusCache(options: string): string = return options & " --symbolFiles:on"
|
||||||
|
|
||||||
proc runRodFiles(r: var TResults, options: string) =
|
proc runRodFiles(r: var TResults, options: string) =
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ Changes affecting backwards compatibility
|
||||||
- ``system.raiseHook`` is now split into ``system.localRaiseHook`` and
|
- ``system.raiseHook`` is now split into ``system.localRaiseHook`` and
|
||||||
``system.globalRaiseHook`` to distinguish between thread local and global
|
``system.globalRaiseHook`` to distinguish between thread local and global
|
||||||
raise hooks.
|
raise hooks.
|
||||||
|
- Changed exception handling/error reporting for ``os.removeFile`` and
|
||||||
|
``os.removeDir``.
|
||||||
|
|
||||||
|
|
||||||
Language Additions
|
Language Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue