Skip to content

Commit

Permalink
stdlib/os: handle symlinks in copy/move functions
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
Roman Inflianskas and timotheecour committed Jan 31, 2021
1 parent eef2948 commit 9feec5c
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 98 deletions.
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.

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


- 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 they are (instead of skipping them
sometimes as it was before).
- Added optional `followSymlinks` argument to `setFilePermissions`.

## Language changes

- `nimscript` now handles `except Exception as e`.
Expand Down
2 changes: 2 additions & 0 deletions lib/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ proc fstatvfs*(a1: cint, a2: var Statvfs): cint {.
importc, header: "<sys/statvfs.h>".}

proc chmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
when hasLchmod:
proc lchmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
proc fchmod*(a1: cint, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
proc fstat*(a1: cint, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
proc lstat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
Expand Down
1 change: 1 addition & 0 deletions lib/posix/posix_haiku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
const
hasSpawnH = true # should exist for every Posix system nowadays
hasAioH = defined(linux)
hasLchmod* = false

when defined(linux) and not defined(android):
# On Linux:
Expand Down
1 change: 1 addition & 0 deletions lib/posix/posix_linux_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const
hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays
hasAioH = defined(linux)
hasLchmod* = false

# On Linux:
# timer_{create,delete,settime,gettime},
Expand Down
1 change: 1 addition & 0 deletions lib/posix/posix_macos_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
const
hasSpawnH = true # should exist for every Posix system nowadays
hasAioH = false
hasLchmod* = true

type
DIR* {.importc: "DIR", header: "<dirent.h>",
Expand Down
1 change: 1 addition & 0 deletions lib/posix/posix_nintendoswitch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
const
hasSpawnH = true
hasAioH = false
hasLchmod* = false

type
DIR* {.importc: "DIR", header: "<dirent.h>",
Expand Down
1 change: 1 addition & 0 deletions lib/posix/posix_openbsd_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ when defined(nimHasStyleChecks):
const
hasSpawnH = true # should exist for every Posix system nowadays
hasAioH = false
hasLchmod* = false

type
DIR* {.importc: "DIR", header: "<dirent.h>",
Expand Down
2 changes: 2 additions & 0 deletions lib/posix/posix_other.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ when defined(freertos):
const
hasSpawnH = false # should exist for every Posix system nowadays
hasAioH = false
hasLchmod* = false
else:
const
hasSpawnH = true # should exist for every Posix system nowadays
hasAioH = defined(linux)
hasLchmod* = false

when defined(linux) and not defined(android):
# On Linux:
Expand Down
Loading

0 comments on commit 9feec5c

Please sign in to comment.