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:
committed by
Space Team
parent
1844869e8a
commit
80b48eed0b
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user