Reduce redundancy
authorLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Apr 2024 16:04:29 +0000 (12:04 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Apr 2024 16:07:08 +0000 (12:07 -0400)
src/jvmMain/kotlin/info/mechyrdia/route/ResourceWebDav.kt

index 67b7e1cd138142945eab8a9c15250fe46645f272..81f2c6acdbb611e29faf68cd73f9f7aa7895ab57 100644 (file)
@@ -94,10 +94,13 @@ private suspend fun getWebDavPropertiesWithIncludeTags(path: StoragePath, webRoo
                        ) to (depth >= 0)
                )
        } ?: FileStorage.instance.listDir(path)?.let { subEntries ->
-               val subPaths = subEntries.keys.map { path / it }
-               val subProps = subPaths.mapSuspend { subPath ->
-                       getWebDavPropertiesWithIncludeTags(subPath, webRoot, depth - 1)
-               }.filterNotNull().flatten()
+               val subProps = subEntries.keys
+                       .map { path / it }
+                       .mapSuspend { subPath ->
+                               getWebDavPropertiesWithIncludeTags(subPath, webRoot, depth - 1)
+                       }
+                       .filterNotNull()
+                       .flatten()
                
                val pathWithSuffix = path.elements.joinToString(separator = "") { "$it/" }
                listOf(
@@ -119,12 +122,13 @@ suspend fun getWebDavProperties(path: StoragePath, webRoot: String, depth: Int =
 
 suspend fun FileStorage.copyWebDav(source: StoragePath, target: StoragePath): Boolean {
        return when (getType(source)) {
-               StoredFileType.DIRECTORY -> createDir(target) && (listDir(source)?.let { subPaths ->
-                       val copyActions = subPaths.keys.map { (source / it) to (target / it) }
-                       copyActions.mapSuspend { (subSource, subTarget) ->
+               StoredFileType.DIRECTORY -> createDir(target) && (listDir(source)
+                       ?.keys
+                       ?.map { (source / it) to (target / it) }
+                       ?.mapSuspend { (subSource, subTarget) ->
                                copyWebDav(subSource, subTarget)
-                       }.all { it }
-               } == true)
+                       }
+                       ?.all { it } == true)
                
                StoredFileType.FILE -> copyFile(source, target)