Skip to content

Commit e9b360c

Browse files
rominftimotheecour
andauthored
stdlib/os: handle symlinks in copy/move functions (#16709)
* stdlib/os: handle symlinks in copy/move functions - Added optional `options` argument to `copyFile`, `copyFileToDir`, and `copyFileWithPermissions`. By default, symlinks are followed (copy files symlinks point to). - `copyDir` and `copyDirWithPermissions` copy symlinks as symlinks (instead of skipping them as it was before). - `moveFile` and `moveDir` move symlinks as symlinks (instead of skipping them sometimes as it was before). - Added optional `followSymlinks` argument to `setFilePermissions`. See also: nim-lang/RFCs#319 Co-authored-by: Timothee Cour <[email protected]> * Address comments in #16709 Co-authored-by: Timothee Cour <[email protected]> * Address comments in #16709 (second iteration) Skip symlinks on Windows. Co-authored-by: Timothee Cour <[email protected]>
1 parent bb85bc7 commit e9b360c

File tree

5 files changed

+322
-107
lines changed

5 files changed

+322
-107
lines changed

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.
112112

113113
- Removed the optional `longestMatch` parameter of the `critbits._WithPrefix` iterators (it never worked reliably)
114114

115+
116+
- Added optional `options` argument to `copyFile`, `copyFileToDir`, and
117+
`copyFileWithPermissions`. By default, on non-Windows OSes, symlinks are
118+
followed (copy files symlinks point to); on Windows, `options` argument is
119+
ignored and symlinks are skipped.
120+
- On non-Windows OSes, `copyDir` and `copyDirWithPermissions` copy symlinks as
121+
symlinks (instead of skipping them as it was before); on Windows symlinks are
122+
skipped.
123+
- On non-Windows OSes, `moveFile` and `moveDir` move symlinks as symlinks
124+
(instead of skipping them sometimes as it was before).
125+
- Added optional `followSymlinks` argument to `setFilePermissions`.
126+
115127
## Language changes
116128

117129
- `nimscript` now handles `except Exception as e`.

lib/posix/posix.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ proc fstatvfs*(a1: cint, a2: var Statvfs): cint {.
586586
importc, header: "<sys/statvfs.h>".}
587587

588588
proc chmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
589+
when defined(osx) or defined(freebsd):
590+
proc lchmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
589591
proc fchmod*(a1: cint, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
590592
proc fstat*(a1: cint, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
591593
proc lstat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}

0 commit comments

Comments
 (0)