Fix Path.copyToRecursively when copying across file systems #KT-55935

Merge-request: KT-MR-8705
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
Abduqodiri Qurbonzoda
2023-02-07 08:25:54 +00:00
committed by Space Team
parent 1844869e8a
commit 80b48eed0b
2 changed files with 57 additions and 6 deletions
@@ -161,11 +161,13 @@ public fun Path.copyToRecursively(
// TODO: KT-38678
// source and target files are the same entry, continue recursive copy operation
} else {
val realPath = this.toRealPath()
val isSubdirectory = if (targetExistsAndNotSymlink) {
target.toRealPath().startsWith(realPath)
} else {
target.parent?.let { it.exists() && it.toRealPath().startsWith(realPath) } ?: false
val isSubdirectory = when {
this.fileSystem != target.fileSystem ->
false
targetExistsAndNotSymlink ->
target.toRealPath().startsWith(this.toRealPath())
else ->
target.parent?.let { it.exists() && it.toRealPath().startsWith(this.toRealPath()) } ?: false
}
if (isSubdirectory)
throw FileSystemException(
@@ -178,7 +180,7 @@ public fun Path.copyToRecursively(
fun destination(source: Path): Path {
val relativePath = source.relativeTo(this@copyToRecursively)
return target.resolve(relativePath)
return target.resolve(relativePath.pathString)
}
fun error(source: Path, exception: Exception): FileVisitResult {