diff options
-rwxr-xr-x | lib/pure/os.nim | 15 | ||||
-rwxr-xr-x | tests/tester.nim | 7 | ||||
-rwxr-xr-x | web/news.txt | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 50c6ffeba..122b38c57 100755 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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. 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".} = - ## Removes the `file`. If this fails, `EOS` is raised. - if cremove(file) != 0'i32: OSError() + ## Removes the `file`. If this fails, `EOS` is raised. This does not fail + ## 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".} = ## Executes a `shell command`:idx:. @@ -855,13 +859,14 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string = proc rawRemoveDir(dir: string) = when defined(windows): - if RemoveDirectoryA(dir) == 0'i32: OSError() + if RemoveDirectoryA(dir) == 0'i32 and GetLastError() != 3'i32: OSError() else: - if rmdir(dir) != 0'i32: OSError() + if rmdir(dir) != 0'i32 and errno != ENOENT: OSError() proc removeDir*(dir: string) {.rtl, extern: "nos$1".} = ## 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): case kind of pcFile, pcLinkToFile, pcLinkToDir: removeFile(path) diff --git a/tests/tester.nim b/tests/tester.nim index 9bf16d84d..42516fe56 100755 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -272,12 +272,7 @@ proc run(r: var TResults, dir, options: string) = const rodfilesDir = "tests/rodfiles" -proc delNimCache() = - try: - removeDir(rodfilesDir / "nimcache") - except EOS: - nil - +proc delNimCache() = removeDir(rodfilesDir / "nimcache") proc plusCache(options: string): string = return options & " --symbolFiles:on" proc runRodFiles(r: var TResults, options: string) = diff --git a/web/news.txt b/web/news.txt index 7dc272d98..51d30fcbd 100755 --- a/web/news.txt +++ b/web/news.txt @@ -42,6 +42,8 @@ Changes affecting backwards compatibility - ``system.raiseHook`` is now split into ``system.localRaiseHook`` and ``system.globalRaiseHook`` to distinguish between thread local and global raise hooks. +- Changed exception handling/error reporting for ``os.removeFile`` and + ``os.removeDir``. Language Additions |