@@ -1725,8 +1725,9 @@ proc copyFile*(source, dest: string, options = {cfSymlinkFollow}) {.rtl,
1725
1725
noWeirdTarget .} =
1726
1726
# # Copies a file from `source` to `dest`, where `dest.parentDir` must exist.
1727
1727
# #
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.
1730
1731
# #
1731
1732
# # If this fails, `OSError` is raised.
1732
1733
# #
@@ -1759,30 +1760,17 @@ proc copyFile*(source, dest: string, options = {cfSymlinkFollow}) {.rtl,
1759
1760
doAssert card (copyFlagSymlink * options) == 1 , " There should be exactly " &
1760
1761
" one cfSymlink* in options"
1761
1762
let isSymlink = source.symlinkExists
1762
- if isSymlink and cfSymlinkIgnore in options:
1763
+ if isSymlink and ( cfSymlinkIgnore in options or defined (windows)) :
1763
1764
return
1764
1765
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
-
1776
- let dwCopyFlags = if cfSymlinkAsIs in options: COPY_FILE_COPY_SYMLINK else : 0 'i32
1777
- var pbCancel = 0 'i32
1778
1766
when useWinUnicode:
1779
1767
let s = newWideCString (source)
1780
1768
let d = newWideCString (dest)
1781
- if copyFileExW (s, d, nil , nil , addr pbCancel, dwCopyFlags ) == 0 'i32 :
1782
- handleOSError ( )
1769
+ if copyFileW (s, d, 0 'i32 ) == 0 'i32 :
1770
+ raiseOSError ( osLastError (), $ (source, dest) )
1783
1771
else :
1784
- if copyFileExA (source, dest, nil , nil , addr pbCancel, dwCopyFlags ) == 0 'i32 :
1785
- handleOSError ( )
1772
+ if copyFileA (source, dest, 0 'i32 ) == 0 'i32 :
1773
+ raiseOSError ( osLastError (), $ (source, dest) )
1786
1774
elif hasCCopyfile:
1787
1775
let state = copyfile_state_alloc ()
1788
1776
# xxx `COPYFILE_STAT` could be used for one-shot `copyFileWithPermissions`.
@@ -1824,8 +1812,9 @@ proc copyFileToDir*(source, dir: string, options = {cfSymlinkFollow})
1824
1812
{.noWeirdTarget , since : (1 ,3 ,7 ).} =
1825
1813
# # Copies a file `source` into directory `dir`, which must exist.
1826
1814
# #
1827
- # # `options` specify the way file is copied; by default, if `source` is a
1828
- # # symlink, copies the file symlink points to.
1815
+ # # On non-Windows OSes, `options` specify the way file is copied; by default,
1816
+ # # if `source` is a symlink, copies the file symlink points to. `options` is
1817
+ # # ignored on Windows: symlinks are skipped.
1829
1818
# #
1830
1819
# # See also:
1831
1820
# # * `CopyFlag enum <#CopyFlag>`_
@@ -2460,7 +2449,8 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
2460
2449
tags : [ReadDirEffect , WriteIOEffect , ReadIOEffect ], benign , noWeirdTarget .} =
2461
2450
# # Copies a directory from `source` to `dest`.
2462
2451
# #
2463
- # # Symlinks are copied as symlinks.
2452
+ # # On non-Windows OSes, symlinks are copied as symlinks. On Windows, symlinks
2453
+ # # are skipped.
2464
2454
# #
2465
2455
# # If this fails, `OSError` is raised.
2466
2456
# #
@@ -2491,8 +2481,8 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
2491
2481
proc moveDir * (source, dest: string ) {.tags : [ReadIOEffect , WriteIOEffect ], noWeirdTarget .} =
2492
2482
# # Moves a directory from `source` to `dest`.
2493
2483
# #
2494
- # # Symlinks are not followed: if `source` contains symlinks, they itself are
2495
- # # moved, not theirs target.
2484
+ # # Symlinks are not followed: if `source` contains symlinks, they themself are
2485
+ # # moved, not their target.
2496
2486
# #
2497
2487
# # If this fails, `OSError` is raised.
2498
2488
# #
@@ -2536,8 +2526,9 @@ proc copyFileWithPermissions*(source, dest: string,
2536
2526
options = {cfSymlinkFollow}) {.noWeirdTarget .} =
2537
2527
# # Copies a file from `source` to `dest` preserving file permissions.
2538
2528
# #
2539
- # # `options` specify the way file is copied; by default, if `source` is a
2540
- # # symlink, copies the file symlink points to.
2529
+ # # On non-Windows OSes, `options` specify the way file is copied; by default,
2530
+ # # if `source` is a symlink, copies the file symlink points to. `options` is
2531
+ # # ignored on Windows: symlinks are skipped.
2541
2532
# #
2542
2533
# # This is a wrapper proc around `copyFile <#copyFile,string,string>`_,
2543
2534
# # `getFilePermissions <#getFilePermissions,string>`_ and
@@ -2576,7 +2567,8 @@ proc copyDirWithPermissions*(source, dest: string,
2576
2567
benign , noWeirdTarget .} =
2577
2568
# # Copies a directory from `source` to `dest` preserving file permissions.
2578
2569
# #
2579
- # # Symlinks are copied as symlinks.
2570
+ # # On non-Windows OSes, symlinks are copied as symlinks. On Windows, symlinks
2571
+ # # are skipped.
2580
2572
# #
2581
2573
# # If this fails, `OSError` is raised. This is a wrapper proc around `copyDir
2582
2574
# # <#copyDir,string,string>`_ and `copyFileWithPermissions
0 commit comments