Skip to content

Commit

Permalink
Fix: Not showing backups of uninstalled packages
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Feb 26, 2025
1 parent a072c42 commit 2405a54
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 14 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/machiav3lli/backup/NeoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,6 @@ class NeoApp : Application(), KoinStartup {
}
}

fun emptyBackupsForMissingPackages(packageNames: List<String>) {
get<PackageRepository>(PackageRepository::class.java).apply {
deleteBackupsNotIn(packageNames)
}
}

fun emptyBackupsForAllPackages(packageNames: List<String>) {
get<PackageRepository>(PackageRepository::class.java).apply {
packageNames.forEach { packageName ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ class PackageRepository(
}
}

fun deleteBackupsNotIn(packageNames: List<String>) = runBlocking(jcc) {
mutex.withLock {
theBackupsMap.keys.removeAll { it !in packageNames }
}
}


suspend fun deleteBackup(pkg: Package?, backup: Backup, onDismiss: () -> Unit) =
withContext(jcc) {
pkg?.let { pkg ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fun Context.findBackups(
NeoApp.setBackups(backupsMap)

// preset installed packages that don't have backups with empty backups lists
NeoApp.emptyBackupsForMissingPackages(installedNames)
//NeoApp.emptyBackupsForMissingPackages(installedNames)

} else {
if (NeoApp.startup)
Expand Down

2 comments on commit 2405a54

@hg42
Copy link
Collaborator

@hg42 hg42 commented on 2405a54 Mar 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original code was:

(packageNames - theBackupsMap.keys).forEach {
                    theBackupsMap.put(it, emptyList())
}

not sure how you define the packages in PackageRepository (could have a better name?), but at least this code doesn't look like it does the same:

get<PackageRepository>(PackageRepository::class.java).apply {
    deleteBackupsNotIn(packageNames)
}

the original code adds entries with empty backups for packages, that are installed (packageNames parameter) but are not yet in the map. This makes the keys of the map match all installed packages.

The new code removes entries...

So this commit fixes the problem of the newer code, but it does not restore the old behavior (at least it had a purpose at that time, not sure if it is necessary today, it might have solved null pointer problems or assumptions about the keys in the map).

@machiav3lli
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty lists into a map is as much useless when considering the safety of the get calls as it gets.

Originally I stuck into the naming logic and went with it and didn't really look at the original implementation (late night), which resulted the bug in alpha01.

Please sign in to comment.