os: use unlink() to remove file (#9220)

removeFile() behavior should now be consistant between Windows and POSIX

Fixes #9200
This commit is contained in:
alaviss
2018-10-09 20:37:36 +07:00
committed by Andreas Rumpf
parent c0266e1afa
commit dad290accb
2 changed files with 10 additions and 3 deletions

View File

@@ -33,8 +33,6 @@ else:
import ospaths
export ospaths
proc c_remove(filename: cstring): cint {.
importc: "remove", header: "<stdio.h>".}
proc c_rename(oldname, newname: cstring): cint {.
importc: "rename", header: "<stdio.h>".}
proc c_system(cmd: cstring): cint {.
@@ -652,7 +650,7 @@ proc tryRemoveFile*(file: string): bool {.rtl, extern: "nos$1", tags: [WriteDirE
deleteFile(f) != 0:
result = true
else:
if c_remove(file) != 0'i32 and errno != ENOENT:
if unlink(file) != 0'i32 and errno != ENOENT:
result = false
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =

View File

@@ -39,6 +39,7 @@ false
true
true
Raises
Raises
true
true
true
@@ -119,6 +120,14 @@ except IOError:
echo "Raises"
removeFile(dname)
# removeFile should not remove directory
createDir(dname)
try:
removeFile(dname)
except OSError:
echo "Raises"
removeDir(dname)
# test copyDir:
createDir("a/b")
open("a/b/file.txt", fmWrite).close