@@ -1725,8 +1725,9 @@ proc copyFile*(source, dest: string, options = {cfSymlinkFollow}) {.rtl,
17251725 noWeirdTarget .} =
17261726 # # Copies a file from `source` to `dest`, where `dest.parentDir` must exist.
17271727 # #
1728- # # `options` specify the way file is copied; by default, if `source` is a
1729- # # symlink, copies the file symlink points to.
1728+ # # On non-Windows OSes, `options` specify the way file is copied; by default,
1729+ # # if `source` is a symlink, copies the file symlink points to. `options` is
1730+ # # ignored on Windows: symlinks are skipped.
17301731 # #
17311732 # # If this fails, `OSError` is raised.
17321733 # #
@@ -1759,30 +1760,19 @@ proc copyFile*(source, dest: string, options = {cfSymlinkFollow}) {.rtl,
17591760 doAssert card (copyFlagSymlink * options) == 1 , " There should be exactly " &
17601761 " one cfSymlink* in options"
17611762 let isSymlink = source.symlinkExists
1762- if isSymlink and cfSymlinkIgnore in options:
1763+ if isSymlink and ( cfSymlinkIgnore in options or defined (windows)) :
17631764 return
17641765 when defined (Windows ):
1765- proc handleOSError =
1766- const ERROR_PRIVILEGE_NOT_HELD = 1314
1767- let errCode = osLastError ()
1768- let context = $ (source, dest, options)
1769- if isSymlink and errCode.int32 == ERROR_PRIVILEGE_NOT_HELD :
1770- stderr.write (" Failed copy the symlink: error " & $ errCode & " : " &
1771- osErrorMsg (errCode) & " Additional info: " & context &
1772- " \n " )
1773- else :
1774- raiseOSError (errCode, context)
1775-
17761766 let dwCopyFlags = if cfSymlinkAsIs in options: COPY_FILE_COPY_SYMLINK else : 0 'i32
17771767 var pbCancel = 0 'i32
17781768 when useWinUnicode:
17791769 let s = newWideCString (source)
17801770 let d = newWideCString (dest)
17811771 if copyFileExW (s, d, nil , nil , addr pbCancel, dwCopyFlags) == 0 'i32 :
1782- handleOSError ( )
1772+ raiseOSError ( osLastError (), $ (source, dest) )
17831773 else :
17841774 if copyFileExA (source, dest, nil , nil , addr pbCancel, dwCopyFlags) == 0 'i32 :
1785- handleOSError ( )
1775+ raiseOSError ( osLastError (), $ (source, dest) )
17861776 elif hasCCopyfile:
17871777 let state = copyfile_state_alloc ()
17881778 # xxx `COPYFILE_STAT` could be used for one-shot `copyFileWithPermissions`.
@@ -1824,8 +1814,9 @@ proc copyFileToDir*(source, dir: string, options = {cfSymlinkFollow})
18241814 {.noWeirdTarget , since : (1 ,3 ,7 ).} =
18251815 # # Copies a file `source` into directory `dir`, which must exist.
18261816 # #
1827- # # `options` specify the way file is copied; by default, if `source` is a
1828- # # symlink, copies the file symlink points to.
1817+ # # On non-Windows OSes, `options` specify the way file is copied; by default,
1818+ # # if `source` is a symlink, copies the file symlink points to. `options` is
1819+ # # ignored on Windows: symlinks are skipped.
18291820 # #
18301821 # # See also:
18311822 # # * `CopyFlag enum <#CopyFlag>`_
@@ -2460,7 +2451,8 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
24602451 tags : [ReadDirEffect , WriteIOEffect , ReadIOEffect ], benign , noWeirdTarget .} =
24612452 # # Copies a directory from `source` to `dest`.
24622453 # #
2463- # # Symlinks are copied as symlinks.
2454+ # # On non-Windows OSes, symlinks are copied as symlinks. On Windows, symlinks
2455+ # # are skipped.
24642456 # #
24652457 # # If this fails, `OSError` is raised.
24662458 # #
@@ -2491,8 +2483,8 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
24912483proc moveDir * (source, dest: string ) {.tags : [ReadIOEffect , WriteIOEffect ], noWeirdTarget .} =
24922484 # # Moves a directory from `source` to `dest`.
24932485 # #
2494- # # Symlinks are not followed: if `source` contains symlinks, they itself are
2495- # # moved, not theirs target.
2486+ # # Symlinks are not followed: if `source` contains symlinks, they themself are
2487+ # # moved, not their target.
24962488 # #
24972489 # # If this fails, `OSError` is raised.
24982490 # #
@@ -2536,8 +2528,9 @@ proc copyFileWithPermissions*(source, dest: string,
25362528 options = {cfSymlinkFollow}) {.noWeirdTarget .} =
25372529 # # Copies a file from `source` to `dest` preserving file permissions.
25382530 # #
2539- # # `options` specify the way file is copied; by default, if `source` is a
2540- # # symlink, copies the file symlink points to.
2531+ # # On non-Windows OSes, `options` specify the way file is copied; by default,
2532+ # # if `source` is a symlink, copies the file symlink points to. `options` is
2533+ # # ignored on Windows: symlinks are skipped.
25412534 # #
25422535 # # This is a wrapper proc around `copyFile <#copyFile,string,string>`_,
25432536 # # `getFilePermissions <#getFilePermissions,string>`_ and
@@ -2576,7 +2569,8 @@ proc copyDirWithPermissions*(source, dest: string,
25762569 benign , noWeirdTarget .} =
25772570 # # Copies a directory from `source` to `dest` preserving file permissions.
25782571 # #
2579- # # Symlinks are copied as symlinks.
2572+ # # On non-Windows OSes, symlinks are copied as symlinks. On Windows, symlinks
2573+ # # are skipped.
25802574 # #
25812575 # # If this fails, `OSError` is raised. This is a wrapper proc around `copyDir
25822576 # # <#copyDir,string,string>`_ and `copyFileWithPermissions
0 commit comments