Merge pull request #9134 from komainu8/fix_issues_9126

Fix #9126: use splitPath instead of substr
This commit is contained in:
Andreas Rumpf 2018-10-01 16:50:09 +02:00 • committed by GitHub
commit fcbb00b97a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -1048,7 +1048,7 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
## these platforms use `copyDirWithPermissions() <#copyDirWithPermissions>`_. ## these platforms use `copyDirWithPermissions() <#copyDirWithPermissions>`_.
createDir(dest) createDir(dest)
for kind, path in walkDir(source): for kind, path in walkDir(source):
var noSource = path.substr(source.len) var noSource = splitPath(path).tail
case kind case kind
of pcFile: of pcFile:
copyFile(path, dest / noSource) copyFile(path, dest / noSource)
@ -1232,7 +1232,7 @@ proc copyDirWithPermissions*(source, dest: string,
if not ignorePermissionErrors: if not ignorePermissionErrors:
raise raise
for kind, path in walkDir(source): for kind, path in walkDir(source):
var noSource = path.substr(source.len()+1) var noSource = splitPath(path).tail
case kind case kind
of pcFile: of pcFile:
copyFileWithPermissions(path, dest / noSource, ignorePermissionErrors) copyFileWithPermissions(path, dest / noSource, ignorePermissionErrors)

View file

@ -43,6 +43,8 @@ true
true true
true true
true true
true
true
''' '''
""" """
@ -132,6 +134,18 @@ echo fileExists("../dest/a/b/file.txt")
echo fileExists("../dest/a/b/c/fileC.txt") echo fileExists("../dest/a/b/c/fileC.txt")
removeDir("../dest") removeDir("../dest")
# test copyDir:
# if separator at the end of a path
createDir("a/b")
open("a/file.txt", fmWrite).close
copyDir("a/", "../dest/a/")
removeDir("a")
echo dirExists("../dest/a/b")
echo fileExists("../dest/a/file.txt")
removeDir("../dest")
# Test get/set modification times # Test get/set modification times
# Should support at least microsecond resolution # Should support at least microsecond resolution
import times import times