diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-10-11 11:43:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-11 20:43:01 +0200 |
commit | 3eac9b2344bda64b1f74e0475ce8a3b5afa63271 (patch) | |
tree | 415763fdbf3b92b88bdb474e7fc525c9e9fd610b /lib | |
parent | 992952d86844805231bcc8a92063c122f721658d (diff) | |
download | Nim-3eac9b2344bda64b1f74e0475ce8a3b5afa63271.tar.gz |
os: add overload copyFile*(source, dest: string, isDir = false) (#15537)
* os: add overload copyFile*(source, dest: string, isDir = false) * renamed to copyFileToDir
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 5efbde268..2601f9d47 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1682,7 +1682,7 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {. proc copyFile*(source, dest: string) {.rtl, extern: "nos$1", tags: [ReadIOEffect, WriteIOEffect], noWeirdTarget.} = - ## Copies a file from `source` to `dest`. + ## Copies a file from `source` to `dest`, where `dest.parentDir` must exist. ## ## If this fails, `OSError` is raised. ## @@ -1738,6 +1738,12 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1", flushFile(d) close(d) +proc copyFileToDir*(source, dir: string) {.noWeirdTarget, since: (1,3,7).} = + ## Copies a file `source` into directory `dir`, which must exist. + if dir.len == 0: # treating "" as "." is error prone + raise newException(ValueError, "dest is empty") + copyFile(source, dir / source.lastPathPart) + when not declared(ENOENT) and not defined(Windows): when NoFakeVars: when not defined(haiku): |