Added support for an alternative current dir mode in pkldoc (#824)

Some systems have trouble with handling symlinks, which breaks the current directory links created by Pkldoc. In this PR, we add an alternative mode which creates a full copy of the latest published version contents in the current directory instead.

Co-authored-by: Dan Chao <dan.chao@apple.com>
This commit is contained in:
Vladimir Matveev
2025-02-19 08:52:32 -08:00
committed by GitHub
parent 2ffd201172
commit baa34a6dd1
11 changed files with 143 additions and 19 deletions
@@ -20,6 +20,9 @@ import java.nio.charset.Charset
import java.nio.file.*
import java.nio.file.attribute.FileAttribute
import java.util.stream.Stream
import kotlin.io.path.copyTo
import kotlin.io.path.createParentDirectories
import kotlin.io.path.exists
// not stored to avoid build-time initialization by native-image
val currentWorkingDir: Path
@@ -51,6 +54,19 @@ fun Path.writeString(
@Throws(IOException::class)
fun Path.readString(charset: Charset = Charsets.UTF_8): String = Files.readString(this, charset)
@Throws(IOException::class)
fun Path.copyRecursively(target: Path) {
if (exists()) {
target.createParentDirectories()
walk().use { paths ->
paths.forEach { src ->
val dst = target.resolve(this@copyRecursively.relativize(src))
src.copyTo(dst, overwrite = true)
}
}
}
}
private val isWindows by lazy { System.getProperty("os.name").contains("Windows") }
/** Copy implementation from IoUtils.toNormalizedPathString */