Commit Graph

1983 Commits

Author SHA1 Message Date
Alexander Larsson
3d65276f79 Add --enable-internal-checks option and use in CI
This enables the internal checks in the generated variant parser.
2020-10-29 15:30:35 +01:00
Simon McVittie
1a58a86676 Skip parental controls checks on ServiceUnknown or NameHasNoOwner
If accountsservice isn't available on the system bus, then we can't
ask it for the user's parental controls settings, and we also can't
ask it whether it even has the malcontent extension. Since this is
not a real security boundary, fail open.

This can be dropped if we depend on a version of libmalcontent that maps
these errors to MCT_APP_FILTER_ERROR_DISABLED.

Resolves: https://github.com/flatpak/flatpak/issues/3902
Bug-Debian: https://bugs.debian.org/972138
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-15 09:24:14 +01:00
Philip Withnall
6c79a57114 http: Return HOST_UNREACHABLE on error 500
Sometimes a server might return a HTTP error 500 (this seems to happen
sometimes with Microsoft’s VSCode server, for example). Map this to
`G_IO_ERROR_HOST_UNREACHABLE` for now, which is a bit more specific than
returning `G_IO_ERROR_FAILED`, but without the hassle of introducing a
new public error domain which could give more detail.

In particular, this should allow gnome-software to show an error message
to the user for such failed downloads, rather than hiding the error and
logging the following:
```
not handling error failed for action download: While downloading http://packages.microsoft.com/repos/vscode/pool/main/c/code/code_1.45.1-1589445302_amd64.deb: Server returned status 500: Internal Server Error
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-12 11:04:40 +02:00
Alexander Larsson
33d1d7b1a5 transaction: Fix error handling in authentication failures
We were not correctly returning in case of error, which caused
a cascading "owerwrite gerror" problem.
2020-10-09 16:57:57 +02:00
Alexander Larsson
d7716f41ac libflatpak: Report available updates for password-protected refs too.
flatpak_installation_list_installed_refs_for_update() now uses the
ready-pre-auth signal instead of the ready signal. This means we will
report updates even for refs that require authentication to install.
2020-10-09 16:57:57 +02:00
Alexander Larsson
bf8ac3cc1c Transaction: Add ready-pre-auth signal
This is similar to the ready signal, except it is called before
per-ref authentication. Apps can use this if they want to be able
to ask for user input on progress before asking for authentication.

This is nice to be able to do in general, but it is also required for
the implementation of
flatpak_installation_list_installed_refs_for_update(), as it doesn't
install any authentication handler, so it will never report updates
for protected refs if using the ready signal.

Note: In special cases we will require authentication even earlier
if authenticating is needed during the resolve operation. This happens
for instance if you are doing a update to a particular commit (rather
than the lastest commit) where we need to get the commit object directly.
2020-10-09 16:57:57 +02:00
Ryan Gonzalez
ff2e7d6e90 transaction: Don't crash on invalid ref names
It is very much possible for an invalid ref name to occur, either due to
lack of validation on Flatpak creation like #3887, or just any
manually-written ref name due to skipping Flatpak tooling or malicious
intent. Regardless, this shouldn't crash, so check the names before
creating the transaction ops.

Fixes #3887.
2020-10-08 09:46:49 +02:00
Phaedrus Leeds
036aba8cb8 common: Fix docs for FLATPAK_QUERY_FLAGS_ONLY_SIDELOADED 2020-10-08 09:15:20 +02:00
Alexander Larsson
3001cb3174 Fix some clang errors 2020-10-08 09:14:51 +02:00
Alexander Larsson
a5d86b8acb transaction: inject eol status to flatpak_dir_list_unused_refs()
This way we can get the proper eol status for the new to-be-installed
refs, rather than whatever was previously installed. This allows us to
detect when a runtime is updated and the new one is eol, and nothing
uses it, so it can be auto-uninstalled.
2020-10-08 09:14:51 +02:00
Alexander Larsson
05a7bda140 transaction: Simplify add_uninstall_unused_ops()
Rather than trying to figure out which runtimes are affected byt
the current setup of ops we run flatpak_dir_list_unused_refs() twice,
once with and once without the changes the transaction will cause.

Any unused refs after the transaction that were not unused before are
caused by the transaction and we start uninstall ops for those.

Also rename flatpak_dir_list_unused_refs_with_options() to
flatpak_dir_list_unused_refs() as it need not be so long.
2020-10-08 09:14:51 +02:00
Alexander Larsson
6bdc364e95 find-unused: Don't care about origin when finding used deps
If we're auto-installing dependencies we want to limit them to those
from the same remote. However you can still (manually) install such
dependencies, so when we're looking for things to possibly uninstall
we need to check dependencies from all remotes.
2020-10-08 09:14:51 +02:00
Alexander Larsson
3642f59ea8 Fix some clang warnings for FlatpakRefPrivate atomic use 2020-10-08 09:14:51 +02:00
Alexander Larsson
478bcc0b12 Rewrite flatpak_dir_list_unused_refs_with_options()
This simplifies the implementation and makes it more effective in
avoiding to re-scan the same things several times.
2020-10-08 09:14:51 +02:00
Alexander Larsson
84da902443 transaction: Add flatpak_transaction_set_disable_auto_pin()
This disables the automatic pinning of explicitly installed runtimes.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
7691fc77eb app: Remove EOL unused runtimes in update command
In case a runtime becomes unused and then later becomes End-Of-Life, it
is currently not removed. So this commit removes such runtimes in the
update command, as discussed in #2639. A unit test is included.

I am planning to propose to use the FlatpakTransaction API added here in
gnome-software, so that users don't have to use the CLI at all for
runtimes to be cleaned up. KDE Discover already removes unused runtimes
periodically.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
617f614d50 Remove EOL runtimes upon app uninstall/upgrade
We normally don't remove a runtime when the last app using it is
uninstalled, since runtimes are large and re-downloading it in the
future may be difficult. But if the runtime is end-of-life, there's a
reasonable chance it won't be used again, so uninstall it in that case.

Similarly, if the last app using a runtime is upgraded to a different
runtime, and the runtime is EOL, uninstall it.

A unit test is included, and the subsequent unit test also had to be
modified. Otherwise we get a "Update is older than current version"
error, since the runtime is installed from test-repo but
setup_repo_no_add() calls make_runtime() which uses the one in
runtime-repo instead, which is older than the one in test-repo.
2020-10-08 09:14:51 +02:00
Phaedrus Leeds
44aa0d6830 Add internal API for list_unused_refs() and add _with_options()
In a few places we are using
flatpak_installation_list_unused_refs() and then only
using the ref strings not the FlatpakInstalledRef objects, so the
resources used to construct those objects are wasted. Add a flatpak_dir_
function to be used internally instead. One day we will figure out how
to make flatpak-dir.c less of a wilderness.

This also adds the flatpak_installation_list_unused_refs_with_options()
verion that has extended features.
2020-10-08 09:14:51 +02:00
Alexander Larsson
b6bd4472c5 flatpak_ref_format_ref_cached: Don't unnecessarily use g_object_set_data 2020-10-02 15:30:58 +02:00
Phaedrus Leeds
55f6abe578 Avoid string duplication in FlatpakRef
Allocate a full ref string once per object rather than once per call.
This is similar to what we do in flatpak_dir_get_name_cached().
2020-10-02 15:30:58 +02:00
Phaedrus Leeds
929fe68f55 flatpak-ref: Don't free immutable struct members
These are only set at object construction time not after.
2020-10-02 15:30:58 +02:00
Phaedrus Leeds
ce2e36d8ea dir: Remove unused variable
This is no longer needed since commit 124b0be92
2020-10-02 15:30:58 +02:00
Phaedrus Leeds
6985bf27ac installation: Fix a Since annotation
Apparently unstable release series start with a micro version of 1.
2020-10-02 15:30:58 +02:00
Kalev Lember
34bb5592c9 common: Allow skewered to camelcase DConf path conversion both ways
commit 6b46d9a0ed that added DConf path
skewering to camelcase conversion only allowed it in one direction
(skewered path1 and camelcase path2).

That turned out to be not enough to allow /org/gnome/sound-juicer/ to
/org/gnome/SoundJuicer/ conversion as the caller had the
flatpak_dconf_path_is_similar() arguments the other way around.

This commit implements it both ways to avoid confusion which way it
should be called.

F: Ignoring D-Conf migrate-path setting /org/gnome/sound-juicer/
2020-10-01 11:15:54 +02:00
Bastien Nocera
6b46d9a0ed common: Allow skewering when converting in app-id for DConf migration
Allow a snake-case in the app-id to convert to a '-' or '_' in the
DConf path to be considered similar enough for DConf migration purposes.

This allows the org.gnome.SoundJuicer app-id to migrate its
/org/gnome/sound-juicer DConf path.

F: Ignoring D-Conf migrate-path setting /org/gnome/sound-juicer/
2020-09-15 08:59:53 +02:00
Bastien Nocera
c6802d2c0e common: Prepare DConf path parsing for changes
Separate the variables used to keep track of which character we were
checking in each of the paths.

No functional changes.
2020-09-15 08:59:53 +02:00
Phaedrus Leeds
92742d8387 dir: Remove superfluous flatpak_dir_ensure_repo()
This is no longer needed since a FlatpakRemoteState is passed in, which
ensures the repo exists. The similar call was already removed from
flatpak_dir_install().
2020-09-15 08:58:49 +02:00
Phaedrus Leeds
08f692962e Avoid shadowing local variables
Avoid shadowing variables that are already declared in a previous scope,
and make such occurrences compile-time errors. These are not functional
changes.

In a few places do related code cleanup.

A similar ostree PR is here:
https://github.com/ostreedev/ostree/pull/2195
2020-09-15 08:58:49 +02:00
Simon McVittie
5af5700af8 exports: Allow redirecting /etc, /usr from the host to an alternative
This is primarily for test coverage ("design for test"): it will let us
pretend a temporary directory is the host for the purposes of testing
--filesystem=host-etc, --filesystem=host-os, and the os-release handling
from #3733.

It can also be used to build a bwrap command-line that will be used on
the host, while already inside a container, which will be useful for
Steam's pressure-vessel tool (which copies some of the Flatpak code).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-14 11:12:25 +02:00
Phaedrus Leeds
238317d99b Avoid critical error in remote-info command
Without this patch, the remote-info command will sometimes emit a
critical error "g_utf8_strlen: assertion 'p != NULL || max == 0' failed"
and print (null) for the "Commit:" field, since the commit doesn't get
initialized properly.
2020-09-14 09:32:27 +02:00
Alexander Larsson
d8086141fb Don't loop authentincating if updating to the current version
In case we need to authenticate for updates (in my test case i was
doing an OCI downgrade) we might need to download a commit object (or
in the OCI case a manifest json), so it did a request_required_tokens(),
but that noticed during the flatpak_transaction_normalize_ops() call
that the partial resolve to a particular commit actually was the
same as the local installed commit and marked op->skip = TRUE.

However, when we got back to resolving the op again we didn't actually
look at the skip, so it kept looping wanting (but never doing) auth.

The fix is to just directly resolve ops marked as skipped.
2020-09-14 09:30:30 +02:00
Alexander Larsson
7622aab962 OCI: Fix progress reporting
Somewhere during the progress reporting cleanup we lost the progress
for OCI pulls, this puts it back.
2020-09-14 09:30:14 +02:00
Owen W. Taylor
25ff00994f OCI: extract appstream data for runtimes
Runtimes also have appstream data - with description, license information,
and so forth, so we should extract the appstream data from the index
for refs that start with runtime/ as well.
2020-09-11 09:35:05 +02:00
Phaedrus Leeds
a70b7a7628 installation: Clarify that SDKs aren't considered used
The docs claimed that SDK runtimes are considered used even if there is
no app using them or runtime for which they are the SDK, but the
implementation does not match that.

We could change the implementation to always consider SDK runtimes used,
but that would be problematic because some apps use an SDK as their
runtime, and in that case the runtime would persist forever after the
app is uninstalled, instead of eventually being garbage collected by the
subsequent commits to this one.
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
097faa8411 uninstall: Note pinned runtimes in --unused output
When "flatpak uninstall --unused" is run, we don't remove unused
runtimes that are pinned. List them in the output so the user knows they
are being left installed.

This commit also adds new library API,
flatpak_installation_list_pinned_refs().
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
7cd1990196 Automatically pin explicitly installed runtimes
If a runtime is installed explicitly rather than as a dependency, pin it
so it doesn't get automatically removed when unused runtimes are being
removed. We do this because the runtime might be installed for
development or other uses.

This commit also rearranges some code in the mask and pin commands, and
adds a unit test.
2020-08-31 16:29:03 +02:00
Matthew Leeds
d2d5397cc1 Add pin command to keep unused runtimes
As discussed here [1], we want a way to mark runtimes to be kept even
when they are unused by any apps and we are removing such runtimes.
Currently this is a command that can be run manually; a subsequent
commit will pin runtimes automatically if they are installed
independently of any app.

A unit test is included.

[1] https://github.com/flatpak/flatpak/issues/2639#issuecomment-662311756
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
84a8c30e55 transaction: Remove an unused error parameter 2020-08-31 16:26:12 +02:00
Phaedrus Leeds
c6647c2b14 transaction: Fix ordering of runtime uninstallation
In case a transaction is uninstalling both an app and its runtime,
properly ensure the app is uninstalled first.
2020-08-31 16:26:12 +02:00
Phaedrus Leeds
ebcad3a402 dir: Fix a typo of .changed 2020-08-31 16:26:12 +02:00
Simon McVittie
5a83c73ed8 context: Implement MODE_NONE in unparse_filesystem_flags
flatpak doesn't yet use -Wswitch-enum, but perhaps it should at some
point. Now that FLATPAK_FILESYSTEM_MODE_NONE is a member of the enum,
it should be handled; and if we're doing that, we might as well make
the same function fully responsible for it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-28 11:00:49 +02:00
Simon McVittie
09424423b9 context: Normalize home/path to ~/path, and ~ to home
Historically we didn't accept them, but there's no real reason why not.
They're normalized to the form in which earlier Flatpak releases would
want to see them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
02094b4f39 context: Forbid --filesystem=/
Making it an equivalent of --filesystem=host would be misleading,
because it wouldn't do what you'd think it does: host mounts some host
system directories in their usual places, but others below /run/host.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
aafe1d36e0 context: Do some syntactic normalization on filesystems
Paths containing ".." are rejected: they're almost certainly a
terrible idea.

Paths containing "." or multiple slashes are syntactically normalized.

This assumes that nobody is going to use "--filesystem=/foo/bar/" to
mean "make /foo/bar available, unless it's a non-directory, in which
case fail".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
55b27b1393 context: Expose flatpak_context_parse_filesystem for testing
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
115d82e6ff exports: Add assertions to distinguish between mode representations
When we're talking about a "mode", sometimes we mean a
FlatpakFilesystemMode, sometimes we mean a FlatpakFilesystemMode that
must be strictly greater than NONE, and sometimes we're willing to
accept the FAKE_MODE constants too.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
517ad25b5f context: Only parse filesystem/mode strings in one place
This gives us the ability for the parse function (the former verify
function) to carry out a normalization step as well.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
414671a666 run: Tell processes in container that the container manager is Flatpak
https://systemd.io/CONTAINER_INTERFACE/ describes a generic way to tell
programs and libraries that they are running in a container: set
pid 1's ${container} to the name of the container manager in lower case,
and populate /run/host/container-manager with the same string followed
by a newline. Let's be nice to application code by doing that, instead
of requiring it to look at /.flatpak-info.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 11:29:52 +02:00
Philip Withnall
78a2e45610 flatpak-dir: Pass cached summary{,.sig} to OSTree
This allows OSTree to avoid re-checking the `summary.sig` for freshness
once per pull in a transaction, since flatpak has already done that.
This avoids latency in a transaction (especially on high latency or
lossy network connections) and avoids the potential race condition of
the `summary` file changing on the server part-way through a
transaction.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
95bef8e4a5 flatpak-dir: Cache the summary GBytes in FlatpakRemoteState
`FlatpakRemoteState` already caches the parsed `GVariant` form of the
summary, but it will be useful (in the following commits) to also have a
pointer to the `GBytes` which backs that variant. The `GBytes` will be
passed into OSTree in the following commits, to allow it to avoid
unnecessarily re-downloading the `summary` file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00