summaryrefslogtreecommitdiff
path: root/libs/local/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-10-14 21:41:06 +0200
committerJoel Klinghed <the_jk@spawned.biz>2024-10-14 22:45:57 +0200
commitea9621389bfa62cb4e63688249c52ac0e41ff282 (patch)
tree4932900d0c058aa7e187fc02b214a024f801db18 /libs/local/src
parent2be5a5171de2ecd51973862c243aecc0be4a0876 (diff)
Add tests for create dir/file/link that already exists
Fix implementations to work as expected (that createDirectory/File/Link fails if an entry with that name already exists).
Diffstat (limited to 'libs/local/src')
-rw-r--r--libs/local/src/main/java/org/the_jk/cleversync/io/local/PathDirectory.kt3
1 files changed, 3 insertions, 0 deletions
diff --git a/libs/local/src/main/java/org/the_jk/cleversync/io/local/PathDirectory.kt b/libs/local/src/main/java/org/the_jk/cleversync/io/local/PathDirectory.kt
index 9899f02..516d5ed 100644
--- a/libs/local/src/main/java/org/the_jk/cleversync/io/local/PathDirectory.kt
+++ b/libs/local/src/main/java/org/the_jk/cleversync/io/local/PathDirectory.kt
@@ -9,6 +9,7 @@ import org.the_jk.cleversync.io.File
import org.the_jk.cleversync.io.ModifiableDirectory
import org.the_jk.cleversync.io.ModifiableFile
import org.the_jk.cleversync.io.ModifiableLink
+import java.nio.file.FileAlreadyExistsException
import java.nio.file.LinkOption
import java.nio.file.NoSuchFileException
import java.nio.file.Path
@@ -17,6 +18,7 @@ import kotlin.io.path.createDirectory
import kotlin.io.path.createSymbolicLinkPointingTo
import kotlin.io.path.deleteIfExists
import kotlin.io.path.deleteRecursively
+import kotlin.io.path.exists
import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile
import kotlin.io.path.isSymbolicLink
@@ -82,6 +84,7 @@ internal open class PathDirectory(
override fun createFile(name: String): ModifiableFile {
val path = path.resolve(name)
+ if (path.exists(options = arrayOf(LinkOption.NOFOLLOW_LINKS))) throw FileAlreadyExistsException(name)
return PathFile(path)
}