summaryrefslogtreecommitdiff
path: root/libs/samba/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'libs/samba/src/main/java')
-rw-r--r--libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt36
1 files changed, 33 insertions, 3 deletions
diff --git a/libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt b/libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt
index f5230b2..fc5b290 100644
--- a/libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt
+++ b/libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt
@@ -126,15 +126,45 @@ internal open class SambaDirectory(
}
override fun removeDirectory(name: String): Boolean {
- return conn.removeDir(SambaConnection.join(path, name))
+ val removePath = SambaConnection.join(path, name)
+ val entry = conn.entry(removePath) ?: return false
+ if (entry.type != NativeSamba.DirEntryType.DIR) return false
+ return removeRecursive(removePath)
+ }
+
+ private fun removeRecursive(removePath: String): Boolean {
+ val dir = conn.openDir(removePath) ?: return false
+ try {
+ dir.list().forEach { entry ->
+ val entryPath = SambaConnection.join(removePath, entry.name)
+ if (!when (entry.type) {
+ NativeSamba.DirEntryType.FILE,
+ NativeSamba.DirEntryType.LINK,
+ -> conn.unlink(entryPath)
+ NativeSamba.DirEntryType.DIR
+ -> removeRecursive(entryPath)
+ }) {
+ return false
+ }
+ }
+ return conn.removeDir(removePath)
+ } finally {
+ dir.destroy()
+ }
}
override fun removeFile(name: String): Boolean {
- return conn.unlink(SambaConnection.join(path, name))
+ val removePath = SambaConnection.join(path, name)
+ val entry = conn.entry(removePath) ?: return false
+ if (entry.type != NativeSamba.DirEntryType.FILE) return false
+ return conn.unlink(removePath)
}
override fun removeLink(name: String): Boolean {
- return conn.unlink(SambaConnection.join(path, name))
+ val removePath = SambaConnection.join(path, name)
+ val entry = conn.entry(removePath) ?: return false
+ if (entry.type != NativeSamba.DirEntryType.LINK) return false
+ return conn.unlink(removePath)
}
override fun openDir(name: String) = modifiableOpenDir(name)