os: use unlink() to remove file (#9220)
removeFile() behavior should now be consistant between Windows and POSIX Fixes #9200
This commit is contained in:
parent
c0266e1afa
commit
dad290accb
2 changed files with 10 additions and 3 deletions
|
|
@ -33,8 +33,6 @@ else:
|
||||||
import ospaths
|
import ospaths
|
||||||
export ospaths
|
export ospaths
|
||||||
|
|
||||||
proc c_remove(filename: cstring): cint {.
|
|
||||||
importc: "remove", header: "<stdio.h>".}
|
|
||||||
proc c_rename(oldname, newname: cstring): cint {.
|
proc c_rename(oldname, newname: cstring): cint {.
|
||||||
importc: "rename", header: "<stdio.h>".}
|
importc: "rename", header: "<stdio.h>".}
|
||||||
proc c_system(cmd: cstring): cint {.
|
proc c_system(cmd: cstring): cint {.
|
||||||
|
|
@ -652,7 +650,7 @@ proc tryRemoveFile*(file: string): bool {.rtl, extern: "nos$1", tags: [WriteDirE
|
||||||
deleteFile(f) != 0:
|
deleteFile(f) != 0:
|
||||||
result = true
|
result = true
|
||||||
else:
|
else:
|
||||||
if c_remove(file) != 0'i32 and errno != ENOENT:
|
if unlink(file) != 0'i32 and errno != ENOENT:
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ false
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
Raises
|
Raises
|
||||||
|
Raises
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
|
@ -119,6 +120,14 @@ except IOError:
|
||||||
echo "Raises"
|
echo "Raises"
|
||||||
removeFile(dname)
|
removeFile(dname)
|
||||||
|
|
||||||
|
# removeFile should not remove directory
|
||||||
|
createDir(dname)
|
||||||
|
try:
|
||||||
|
removeFile(dname)
|
||||||
|
except OSError:
|
||||||
|
echo "Raises"
|
||||||
|
removeDir(dname)
|
||||||
|
|
||||||
# test copyDir:
|
# test copyDir:
|
||||||
createDir("a/b")
|
createDir("a/b")
|
||||||
open("a/b/file.txt", fmWrite).close
|
open("a/b/file.txt", fmWrite).close
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue