mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-01 17:41:17 +00:00
Modified os.removeFile to act correctly when deleting a file that doesn't exist.
This commit is contained in:
@@ -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].} =
|
||||
|
||||
Reference in New Issue
Block a user