Test that Path.copyTo() copies the source file access permissions

This commit is contained in:
Abduqodiri Qurbonzoda
2022-08-02 00:55:54 +03:00
committed by Space
parent f0da420b1f
commit 6ddb0326bb
2 changed files with 66 additions and 1 deletions
+15 -1
View File
@@ -61,7 +61,7 @@ abstract class AbstractPathTest {
}
}
fun withRestrictedRead(vararg paths: Path, block: () -> Unit) {
fun withRestrictedRead(vararg paths: Path, alsoReset: List<Path> = emptyList(), block: () -> Unit) {
try {
if (paths.all { it.toFile().setReadable(false) }) {
block()
@@ -70,6 +70,20 @@ abstract class AbstractPathTest {
}
} finally {
paths.forEach { it.toFile().setReadable(true) }
alsoReset.forEach { it.toFile().setReadable(true) }
}
}
fun withRestrictedWrite(vararg paths: Path, alsoReset: List<Path> = emptyList(), block: () -> Unit) {
try {
if (paths.all { it.toFile().setWritable(false) }) {
block()
} else {
System.err.println("Couldn't restrict write access")
}
} finally {
paths.forEach { it.toFile().setWritable(true) }
alsoReset.forEach { it.toFile().setWritable(true) }
}
}
}