fixes os.moveFile on Windows
This commit is contained in:
parent
b226618ce7
commit
fde16e6c3e
3 changed files with 18 additions and 2 deletions
0
build.sh
Executable file → Normal file
0
build.sh
Executable file → Normal file
|
|
@ -1010,8 +1010,16 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect, WriteIOEffect].} =
|
tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
## Moves a file from `source` to `dest`. If this fails, `OSError` is raised.
|
## Moves a file from `source` to `dest`. If this fails, `OSError` is raised.
|
||||||
if c_rename(source, dest) != 0'i32:
|
when defined(Windows):
|
||||||
raise newException(OSError, $strerror(errno))
|
when useWinUnicode:
|
||||||
|
let s = newWideCString(source)
|
||||||
|
let d = newWideCString(dest)
|
||||||
|
if moveFileW(s, d, 0'i32) == 0'i32: raiseOSError(osLastError())
|
||||||
|
else:
|
||||||
|
if moveFileA(source, dest, 0'i32) == 0'i32: raiseOSError(osLastError())
|
||||||
|
else:
|
||||||
|
if c_rename(source, dest) != 0'i32:
|
||||||
|
raise newException(OSError, $strerror(errno))
|
||||||
|
|
||||||
when not declared(ENOENT) and not defined(Windows):
|
when not declared(ENOENT) and not defined(Windows):
|
||||||
when NoFakeVars:
|
when NoFakeVars:
|
||||||
|
|
|
||||||
|
|
@ -284,6 +284,10 @@ when useWinUnicode:
|
||||||
bFailIfExists: cint): cint {.
|
bFailIfExists: cint): cint {.
|
||||||
importc: "CopyFileW", stdcall, dynlib: "kernel32".}
|
importc: "CopyFileW", stdcall, dynlib: "kernel32".}
|
||||||
|
|
||||||
|
proc moveFileW*(lpExistingFileName, lpNewFileName: WideCString,
|
||||||
|
bFailIfExists: cint): cint {.
|
||||||
|
importc: "MoveFileW", stdcall, dynlib: "kernel32".}
|
||||||
|
|
||||||
proc getEnvironmentStringsW*(): WideCString {.
|
proc getEnvironmentStringsW*(): WideCString {.
|
||||||
stdcall, dynlib: "kernel32", importc: "GetEnvironmentStringsW".}
|
stdcall, dynlib: "kernel32", importc: "GetEnvironmentStringsW".}
|
||||||
proc freeEnvironmentStringsW*(para1: WideCString): int32 {.
|
proc freeEnvironmentStringsW*(para1: WideCString): int32 {.
|
||||||
|
|
@ -308,6 +312,10 @@ else:
|
||||||
bFailIfExists: cint): cint {.
|
bFailIfExists: cint): cint {.
|
||||||
importc: "CopyFileA", stdcall, dynlib: "kernel32".}
|
importc: "CopyFileA", stdcall, dynlib: "kernel32".}
|
||||||
|
|
||||||
|
proc moveFileA*(lpExistingFileName, lpNewFileName: cstring,
|
||||||
|
bFailIfExists: cint): cint {.
|
||||||
|
importc: "MoveFileA", stdcall, dynlib: "kernel32".}
|
||||||
|
|
||||||
proc getEnvironmentStringsA*(): cstring {.
|
proc getEnvironmentStringsA*(): cstring {.
|
||||||
stdcall, dynlib: "kernel32", importc: "GetEnvironmentStringsA".}
|
stdcall, dynlib: "kernel32", importc: "GetEnvironmentStringsA".}
|
||||||
proc freeEnvironmentStringsA*(para1: cstring): int32 {.
|
proc freeEnvironmentStringsA*(para1: cstring): int32 {.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue