Skip to content

Commit 9feec5c

Browse files
Roman Inflianskastimotheecour
andcommitted
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]>
1 parent eef2948 commit 9feec5c

File tree

12 files changed

+326
-98
lines changed

12 files changed

+326
-98
lines changed

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.
111111

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

114+
115+
- Added optional `options` argument to `copyFile`, `copyFileToDir`, and
116+
`copyFileWithPermissions`. By default, symlinks are followed (copy files
117+
symlinks point to).
118+
- `copyDir` and `copyDirWithPermissions` copy symlinks as symlinks (instead of
119+
skipping them as it was before).
120+
- `moveFile` and `moveDir` move symlinks as they are (instead of skipping them
121+
sometimes as it was before).
122+
- Added optional `followSymlinks` argument to `setFilePermissions`.
123+
114124
## Language changes
115125

116126
- `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 hasLchmod:
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.}

lib/posix/posix_haiku.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
1313
const
1414
hasSpawnH = true # should exist for every Posix system nowadays
1515
hasAioH = defined(linux)
16+
hasLchmod* = false
1617

1718
when defined(linux) and not defined(android):
1819
# On Linux:

lib/posix/posix_linux_amd64.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const
1616
hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays
1717
hasAioH = defined(linux)
18+
hasLchmod* = false
1819

1920
# On Linux:
2021
# timer_{create,delete,settime,gettime},

lib/posix/posix_macos_amd64.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
1313
const
1414
hasSpawnH = true # should exist for every Posix system nowadays
1515
hasAioH = false
16+
hasLchmod* = true
1617

1718
type
1819
DIR* {.importc: "DIR", header: "<dirent.h>",

lib/posix/posix_nintendoswitch.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
const
1313
hasSpawnH = true
1414
hasAioH = false
15+
hasLchmod* = false
1516

1617
type
1718
DIR* {.importc: "DIR", header: "<dirent.h>",

lib/posix/posix_openbsd_amd64.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
1313
const
1414
hasSpawnH = true # should exist for every Posix system nowadays
1515
hasAioH = false
16+
hasLchmod* = false
1617

1718
type
1819
DIR* {.importc: "DIR", header: "<dirent.h>",

lib/posix/posix_other.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ when defined(freertos):
1414
const
1515
hasSpawnH = false # should exist for every Posix system nowadays
1616
hasAioH = false
17+
hasLchmod* = false
1718
else:
1819
const
1920
hasSpawnH = true # should exist for every Posix system nowadays
2021
hasAioH = defined(linux)
22+
hasLchmod* = false
2123

2224
when defined(linux) and not defined(android):
2325
# On Linux:

0 commit comments

Comments
 (0)