Move Path.tryCreateSymbolicLinkTo to AbstractPathTest.kt

This commit is contained in:
Abduqodiri Qurbonzoda
2022-08-02 00:48:59 +03:00
committed by Space
parent 81d6fea0c4
commit f0da420b1f
3 changed files with 11 additions and 11 deletions
@@ -8,6 +8,7 @@ package kotlin.jdk7.test
import java.io.IOException
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
import kotlin.io.path.createSymbolicLinkPointingTo
import kotlin.io.path.deleteIfExists
import kotlin.io.path.exists
import kotlin.test.*
@@ -50,6 +51,16 @@ abstract class AbstractPathTest {
}
}
fun Path.tryCreateSymbolicLinkTo(original: Path): Path? {
return try {
this.createSymbolicLinkPointingTo(original)
} catch (e: Exception) {
// the underlying OS may not support symbolic links or may require a privilege
println("Creating a symbolic link failed with $e")
null
}
}
fun withRestrictedRead(vararg paths: Path, block: () -> Unit) {
try {
if (paths.all { it.toFile().setReadable(false) }) {