summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/os.nim4
-rw-r--r--tests/stdlib/tos.nim14
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 5c7d369c9..fabac8d95 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1048,7 +1048,7 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
   ## these platforms use `copyDirWithPermissions() <#copyDirWithPermissions>`_.
   createDir(dest)
   for kind, path in walkDir(source):
-    var noSource = path.substr(source.len()+1)
+    var noSource = splitPath(path).tail
     case kind
     of pcFile:
       copyFile(path, dest / noSource)
@@ -1232,7 +1232,7 @@ proc copyDirWithPermissions*(source, dest: string,
       if not ignorePermissionErrors:
         raise
   for kind, path in walkDir(source):
-    var noSource = path.substr(source.len()+1)
+    var noSource = splitPath(path).tail
     case kind
     of pcFile:
       copyFileWithPermissions(path, dest / noSource, ignorePermissionErrors)
diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim
index 10f439dfa..2c0db6953 100644
--- a/tests/stdlib/tos.nim
+++ b/tests/stdlib/tos.nim
@@ -43,6 +43,8 @@ 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")
 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
 # Should support at least microsecond resolution
 import times