diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-08-25 02:30:36 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-08-25 02:30:36 +0200 |
| commit | a15cfde0fcbdb29dafdb9ebe39fe53c8da4073be (patch) | |
| tree | ae7894796099d34381990d5230ebb22be16e897c /libs/samba/src/main/java | |
| parent | 855a23136973313a656bfaf60afd8b98833a05c0 (diff) | |
Combine tests from both local and samba
Most the tests test the Tree implementation and thus should work
on all such implementations. Current exception is symlinks which
Samba backend doesn't (currently?) support.
Improve the Samba remove methods to better match the expected behavior.
Diffstat (limited to 'libs/samba/src/main/java')
| -rw-r--r-- | libs/samba/src/main/java/org/the_jk/cleversync/io/samba/SambaDirectory.kt | 36 |
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) |
