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: https://github.com/nim-lang/RFCs/issues/319 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments in #16709 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments in #16709 (second iteration) Skip symlinks on Windows. Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
parent
bb85bc7ebc
commit
e9b360c5df
5 changed files with 321 additions and 106 deletions
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
{.warning[UnusedImport]: off.}
|
||||
|
||||
from stdtest/specialpaths import buildDir
|
||||
|
||||
import std/[
|
||||
# Core:
|
||||
bitops, typetraits, lenientops, macros, volatile,
|
||||
|
|
@ -87,3 +89,28 @@ block:
|
|||
try: doAssert false
|
||||
except Exception as e:
|
||||
discard
|
||||
|
||||
block: # cpDir, cpFile, dirExists, fileExists, mkDir, mvDir, mvFile, rmDir, rmFile
|
||||
const dname = buildDir/"D20210121T175016"
|
||||
const subDir = dname/"sub"
|
||||
const subDir2 = dname/"sub2"
|
||||
const fpath = subDir/"f"
|
||||
const fpath2 = subDir/"f2"
|
||||
const fpath3 = subDir2/"f"
|
||||
mkDir(subDir)
|
||||
writeFile(fpath, "some text")
|
||||
cpFile(fpath, fpath2)
|
||||
doAssert fileExists(fpath2)
|
||||
rmFile(fpath2)
|
||||
cpDir(subDir, subDir2)
|
||||
doAssert fileExists(fpath3)
|
||||
rmDir(subDir2)
|
||||
mvFile(fpath, fpath2)
|
||||
doAssert not fileExists(fpath)
|
||||
doAssert fileExists(fpath2)
|
||||
mvFile(fpath2, fpath)
|
||||
mvDir(subDir, subDir2)
|
||||
doAssert not dirExists(subDir)
|
||||
doAssert dirExists(subDir2)
|
||||
mvDir(subDir2, subDir)
|
||||
rmDir(dname)
|
||||
Loading…
Add table
Add a link
Reference in a new issue