flatpak-dir: Avoid false "changed" notitications for empty installations #5252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is related to downstream bug:
https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1989
The gnome-software could pass an already cancelled GCancellable into the libflatpak functions, which can end at
_flatpak_dir_ensure_repo
, which unconditionally callsflatpak_dir_mark_changed()
to create the.changed
file, even when it exists, because the earlier call tog_file_query_exists()
returnsFALSE
also when therepodir
GFile
exists, but thecancellable
is cancelled.This exhibits the most with empty installations, which have no refs installed nor any remote configured, because (it seems, though I did not check it in the code) the FlatpakDir is freed early when the installation is completely empty (like my
--user
installation here). Having there at least a remote configured theFlatpakDir
is not freed early, thus it's not recreated on demand.The first commit adds a test to not call
flatpak_dir_mark_changed()
when the file already exists. The second commit adds checks for the cancelled state of the cancellable, which can stop the function earlier. As it's not assured when exactly the other thread can cancel the cancellable, I added it into multiple places.One such place, where the FlatpakDir instance is periodically recreated, is when calling
flatpak_installation_list_remotes()
, as shown in the following backtrace snippet:The false "changed" notifications are wrong for the gnome-software, because there is no granularity on the signal (having a set of flags for "app/remote $ID added/removed/updated" would be a great improvement), the gnome-software simply reloads everything in the GUI, which can take its time and which is pretty bad user experience, but as there's currently no easy way to recognize what precisely changed, then there's no better option either.