Skip to content

Commit a5efb6a

Browse files
authored
Merge pull request #63 from utgheith/master
os.copy honors the followLinks flag when copying symbolic links to dirs
2 parents 77a8b9e + cc02355 commit a5efb6a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

os/src/FileOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object copy {
174174
}
175175

176176
copyOne(from)
177-
if (stat(from).isDir) walk(from).map(copyOne)
177+
if (stat(from, followLinks = followLinks).isDir) walk(from).map(copyOne)
178178
}
179179

180180
/**

os/test/src-jvm/ManipulatingFilesFoldersTests.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ object ManipulatingFilesFoldersTests extends TestSuite {
106106
os.list(wd / "folder2") ==> Seq(wd / "folder2" / "one.txt")
107107
}
108108
}
109+
test("symlinks") {
110+
val src = os.temp.dir(deleteOnExit = true)
111+
112+
os.makeDir(src / "t0")
113+
os.write(src / "t0" / "file", "hello")
114+
os.symlink(src / "t1", os.rel / "t0")
115+
116+
val dest = os.temp.dir(deleteOnExit = true)
117+
118+
os.copy(src / "t0", dest / "t0", followLinks = false, replaceExisting = false)
119+
os.copy(src / "t1", dest / "t1", followLinks = false, replaceExisting = false)
120+
121+
val src_list = os.walk(src, includeTarget = false, followLinks = false)
122+
.map(_ relativeTo src)
123+
.sorted
124+
val dest_list = os.walk(dest, includeTarget = false, followLinks = false)
125+
.map(_ relativeTo dest)
126+
.sorted
127+
128+
assert(dest_list == src_list)
129+
130+
src_list.foreach { r =>
131+
val src_path = src / r
132+
val dest_path = dest / r
133+
134+
if (os.isFile(src_path, followLinks = false)) {
135+
assert(os.isFile(dest_path, followLinks = false))
136+
assert(os.read(src_path) == os.read(dest_path))
137+
} else if (os.isLink(src_path)) {
138+
assert(os.isLink(dest_path))
139+
assert(os.readLink(src_path) == os.readLink(dest_path))
140+
} else if (os.isDir(src_path, followLinks = false)) {
141+
assert(os.isDir(dest_path, followLinks = false))
142+
val s = os.list(src_path, sort = true).map(_ relativeTo src).toList
143+
val d = os.list(dest_path, sort = true).map(_ relativeTo dest).toList
144+
assert(d == s)
145+
} else {
146+
assert(false)
147+
}
148+
149+
}
150+
}
109151
}
110152
test("makeDir"){
111153
test - prep{ wd =>

0 commit comments

Comments
 (0)