mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
os: use unlink() to remove file (#9220)
removeFile() behavior should now be consistant between Windows and POSIX Fixes #9200
This commit is contained in:
@@ -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].} =
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user