summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorClay Sweetser <clay.sweetser@gmail.com>2013-12-17 18:03:08 -0500
committerClay Sweetser <clay.sweetser@gmail.com>2013-12-17 18:03:08 -0500
commitab2eb884a0d440796b0c712346a17bbe1ff54e94 (patch)
tree5e0a21a1e2ba2cf57a52535ac489076b5a6eb2ea /lib/pure
parent30aef21defbebc4ea72454774ff0a833105794af (diff)
downloadNim-ab2eb884a0d440796b0c712346a17bbe1ff54e94.tar.gz
Modified os.removeFile to act correctly when deleting a file that doesn't exist.
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/os.nim12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 71639d821..ecab692cf 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -972,15 +972,21 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
 
 when not defined(ENOENT):
   var ENOENT {.importc, header: "<errno.h>".}: cint
+when not defined(EACCES):
+  var EACCES {.importc, header: "<errno.h>".}: cint
 
 proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
   ## Removes the `file`. If this fails, `EOS` is raised. This does not fail
   ## if the file never existed in the first place.
   ## On Windows, ignores the read-only attribute.
-  when defined(Windows):
-    setFilePermissions(file, {fpUserWrite})
   if cremove(file) != 0'i32 and errno != ENOENT:
-    raise newException(EOS, $strerror(errno))
+    when defined(Windows):
+      if errno == EACCES:  # Turn this into a case stmt?
+        setFilePermissions(file, {fpUserWrite}) # Use lower level code?
+        if cremove(file) != 0'i32 and errno != ENOENT:
+          raise newException(EOS, $strerror(errno))
+    else:
+      raise newException(EOS, $strerror(errno))
 
 proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
   tags: [FExecIO].} =