Skip to content

Commit

Permalink
When running ACS and Shizuku in combination we have an overlap betwee…
Browse files Browse the repository at this point in the history
…n `InaccessibleCache` (contains public and private default caches) and `DefaultCachesPublicFilter`.

Both affect each other and this needs to be taken into account when deleting either, i.e. remove entries and recalculate sizes.
  • Loading branch information
d4rken committed Aug 21, 2024
1 parent ac25dbb commit 4bfd3ef
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions app/src/main/java/eu/darken/sdmse/appcleaner/core/AppCleaner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ class AppCleaner @Inject constructor(
updateProgressSecondary(appJunk.label)
// Remove all files we deleted or children of deleted files

val deletedInaccessible = mutableSetOf<ExpendablesFilter.Match>()

val updatedExpendables = appJunk.expendables?.mapValues { (type, matches) ->
if (type == DefaultCachesPublicFilter::class && inaccessibleSuccesses.contains(appJunk.identifier)) {
// It's inaccessible caches were deleted, this included the default public caches
Expand All @@ -292,20 +294,33 @@ class AppCleaner @Inject constructor(
val isDeleted = accessibleDeletionMap.getOrDefault(appJunk.identifier, emptySet()).any {
it.path.isAncestorOf(match.path) || it.path.matches(match.path)
}
if (isDeleted) deleted.add(match.path)
if (isDeleted) {
deleted.add(match.path)
if (match.identifier == DefaultCachesPublicFilter::class) {
// We need path and size to update the size of `InaccessibleCache` later
deletedInaccessible.add(match)
}
}
!isDeleted
}
}?.filterValues { it.isNotEmpty() }

val updatedInaccessible = when {
inaccessibleSuccesses.contains(appJunk.identifier) -> {
deleted.addAll(appJunk.inaccessibleCache?.theoreticalPaths!!)
null
val updatedInaccessible = appJunk.inaccessibleCache?.let { inacc ->
if (inaccessibleSuccesses.contains(appJunk.identifier)) {
// Inaccessible were deleted, `expendables` should have been updated correctly by above code
deleted.addAll(inacc.theoreticalPaths)
return@let null
}

else -> appJunk.inaccessibleCache
val deletedSize = deletedInaccessible.sumOf { it.expectedGain }
inacc.copy(
itemCount = 1,
totalSize = inacc.totalSize - deletedSize,
publicSize = inacc.publicSize?.let { it - deletedSize }?.coerceAtLeast(0L),
)
}


appJunk.copy(
expendables = updatedExpendables,
inaccessibleCache = updatedInaccessible,
Expand All @@ -316,7 +331,7 @@ class AppCleaner @Inject constructor(
// Force check via !! because we should not have ran automation for any junk without inaccessible data
val automationSize = inaccessibleSuccesses
.map { inaccessible -> snapshot.junks.single { it.identifier == inaccessible }.inaccessibleCache!! }
.sumOf { it.cacheBytes }
.sumOf { it.totalSize }

return AppCleanerProcessingTask.Success(
affectedSpace = accessibleDeletionMap.values.sumOf { contents -> contents.sumOf { it.expectedGain } } + automationSize,
Expand Down

0 comments on commit 4bfd3ef

Please sign in to comment.