Skip to content

Commit

Permalink
Code fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Feb 7, 2024
1 parent 330d3bb commit e2b7b7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import eu.darken.sdmse.common.files.saf.crumbsTo
import eu.darken.sdmse.common.files.saf.isAncestorOf
import eu.darken.sdmse.common.files.saf.isParentOf
import eu.darken.sdmse.common.files.saf.startsWith
import kotlinx.coroutines.flow.Flow
import okio.Sink
import okio.Source
import java.io.File
Expand Down Expand Up @@ -39,11 +40,11 @@ fun APath.asFile(): File = when (this) {
else -> File(this.path)
}

fun <P : APath, PL : APathLookup<P>, PLE : APathLookupExtended<P>, GT : APathGateway<P, PL, PLE>> P.walk(
suspend fun <P : APath, PL : APathLookup<P>, PLE : APathLookupExtended<P>, GT : APathGateway<P, PL, PLE>> P.walk(
gateway: GT,
filter: suspend (PL) -> Boolean = { true }
): PathTreeFlow<P, PL, PLE, GT> {
return PathTreeFlow(gateway, this, filter)
filter: (suspend (PL) -> Boolean)? = null
): Flow<PL> {
return PathTreeFlow(gateway, this, filter ?: { true })
}

suspend fun <T : APath> T.exists(gateway: APathGateway<T, out APathLookup<T>, out APathLookupExtended<T>>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.darken.sdmse.common.files

import eu.darken.sdmse.common.debug.logging.Logging.Priority.VERBOSE
import eu.darken.sdmse.common.debug.logging.log
import kotlinx.coroutines.flow.Flow
import okio.Sink
import okio.Source

Expand All @@ -15,10 +16,10 @@ val APathLookup<*>.isSymlink: Boolean
val APathLookup<*>.isFile: Boolean
get() = fileType == FileType.FILE

fun <P : APath, PL : APathLookup<P>, PLE : APathLookupExtended<P>, GT : APathGateway<P, PL, PLE>> PL.walk(
suspend fun <P : APath, PL : APathLookup<P>, PLE : APathLookupExtended<P>, GT : APathGateway<P, PL, PLE>> PL.walk(
gateway: GT,
filter: suspend (PL) -> Boolean = { true }
): PathTreeFlow<P, PL, PLE, GT> = lookedUp.walk(gateway, filter)
filter: (suspend (PL) -> Boolean)? = null
): Flow<PL> = lookedUp.walk(gateway, filter)

suspend fun <P : APath, PL : APathLookup<P>> PL.exists(
gateway: APathGateway<P, out APathLookup<P>, out APathLookupExtended<P>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class PathTreeFlow<
.filter {
val allowed = onFilter(it)
if (Bugs.isTrace) {
if (allowed) log(tag, VERBOSE) { "Walking: $it" }
else log(tag, VERBOSE) { "Not walking (filter): $it" }
if (!allowed) log(tag, VERBOSE) { "Skipping (filter): $it" }
}
allowed
}
.forEach { child ->
if (child.isDirectory) queue.addFirst(child)
if (child.isDirectory) {
if (Bugs.isTrace) log(tag, VERBOSE) { "Walking: $child" }
queue.addFirst(child)
}
collector.emit(child)
}
}
Expand Down

0 comments on commit e2b7b7a

Please sign in to comment.