Commit Graph

763 Commits

Author SHA1 Message Date
Matthew Leeds
2558b086d7 dir: Fix wrong extension refspecs
Currently Flatpak only supports extensions which come from the same
remote as the thing being extended; for discussion on this see
https://github.com/flatpak/flatpak/issues/861

However in general it isn't clear from the metadata what remote provides
an extension. For example com.endlessm.apps.Platform//5 defines the
extension org.freedesktop.Platform.VAAPI.Intel (inherited from
org.freedesktop.Platform) which can be found on flathub not eos-sdk. So
we don't want to add an extension refspec to the transaction if the
current remote is not the one that actually provides it. In
flatpak_dir_find_remote_related_for_metadata() this invariant is
maintained because we check if the ref exists in the remote before
adding it with add_related(). However in
flatpak_dir_find_local_related_for_metadata() we check for existing
deploy data but omit checking that the deploy origin matches the origin
passed in, and in that case can accidentally add an incorrect refspec to
a transaction. So this commit adds the missing origin check.

One way to reproduce this issue is with this command, having both the
Endless platform and the VAAPI extension already installed:
$ flatpak update --no-pull com.endlessm.apps.Platform//5
Looking for updates…
error: Refspec 'eos-sdk:runtime/org.freedesktop.Platform.VAAPI.Intel/x86_64/1.6' not found

This issue also affects GNOME Software which does a no-deploy
transaction followed by a no-pull transaction (this issue occurs in the
latter) and is treated as fatal causing updates not to be applied.
However it only happens in some niche circumstances, because
flatpak_transaction_add_op() will only use the first remote passed to it
if called more than once for the same ref from different remotes. This
is normally fine; refs generally only come from one remote. But it does
mean this issue only occurs if the extension in question was not already
added to the transaction with a correct origin.
2020-06-30 09:07:19 +02:00
Matthew Leeds
5a646117c9 Don't mention $FLATPAK_RUN_DIR in docs
We only want the run dir to be overridable in unit tests because we
depend on it being /run/flatpak in flatpak-create-sideload-symlinks.sh,
so don't mention it in the flatpak man page.
2020-06-23 09:37:10 +02:00
Matthew Leeds
e84b75629d Allow sideload-repos to link to the root of a USB
Currently we only support links in /var/lib/flatpak/sideload-repos,
/run/flatpak/sideload-repos, etc. to be actual ostree repos, but this
commit makes it so you can also link to the root directory of a USB,
and Flatpak will check the subpaths "ostree/repo", ".ostree/repo", and
".ostree/repos.d" for compatibility with "flatpak create-usb". This will
allow the logic in the following commit to be much simpler, where we're
linking to hot-plugged drives in a script run by systemd.

Note that we still only allow actual repos in the other places where a
sideload path can be specified, such as the --sideload-repo CLI option.
2020-06-23 09:37:10 +02:00
Alexander Larsson
c63645f038 dir: Change find_remote_auto_install_refs to get_remote_auto_install_authenticator_ref
We only ever returned this one ref anyway, and we want to use it in were
its *only* for the authenticator.
2020-06-22 10:51:36 +02:00
Matthew Leeds
2d2a05621a dir: Fix an error path in pull_untrusted_local
GError conventions require we set the error pointer on error code paths.
2020-06-17 09:49:03 +02:00
Léo Stefanesco
66dfb63075 Fix segfault when reporting error during install
flatpak_dir_install was returning FALSE but leaving error to NULL, which
would crash when printing the error.

Fixes #3646
2020-06-05 17:02:45 +02:00
Alexander Larsson
b042abc71c oci: Handle io.github.containers.DeltaUrl in index
If the magical io.github.containers.DeltaUrl label is set in the
index, then try to download this to use as the delta manifest for the
image. This allows servers to store deltas outside the registry
itself. The label is propagated to the xa.delta-url metadata in the
generated "fake summary" for the remote, and read back on pull.

Note that the delta manifest layers descriptor will need to have a
"urls" key where it references the blobs if the blobs are also not
stored on the registry.

If the specified manifest doesn't exist or doesn't apply to the target
image we fall back to resolving via the _deltaindex tag.
2020-06-05 09:35:30 +02:00
Alexander Larsson
fd197300b9 oci: Fix potential crash
Call flatpak_remote_state_ensure_summary() before dereferencing
RemoteState->summary to return an error instead of crashing if
downloading the summary failed.
2020-06-05 09:35:30 +02:00
Alexander Larsson
47daa077c2 OCI: Support (and use) alternative urls specified in OCI descriptors 2020-06-05 09:35:30 +02:00
Alexander Larsson
aaa36bab45 oci: Support deltas when using system-helper
When mirroring to a local OCI dir we apply deltas and generate
uncompressed layer blobs instead of regular blobs. Then we pick this
up on the system-helper side.
2020-06-05 09:35:30 +02:00
Alexander Larsson
5d8fd2d1be oci: Set token on child oci registry and pass to system-helper
When we create a system child registry we also set the current token on
it. This is not used directly in the client, however its saved in a
file called .token and re-read in the system-helper, allowing it to
also do the remote registry operations it needs to verify the child
registry.
2020-06-05 09:35:30 +02:00
Alexander Larsson
0fce4c6d7f oci: Pass FlatpakPullFlags to pull_from_oci()
We want to handle FLATPAK_PULL_FLAGS_NO_STATIC_DELTAS
2020-06-05 09:35:30 +02:00
Alexander Larsson
7820057336 Add content_type output to flatpak_load_uri()
We want this to get the oci mimetypes
2020-06-05 09:35:30 +02:00
Alexander Larsson
e3c31309a4 Rename internal error FLATPAK_OCI_ERROR to FLATPAK_HTTP_ERROR
This is what it is really, and I want to extend it with more http errors
that are not necessarily oci related.
2020-05-05 13:08:57 +02:00
Alexander Larsson
6c3f150a05 oci: Don't crash when loading manifest by digest with no ref label 2020-05-05 11:26:20 +02:00
Alexander Larsson
a94e36d002 oci: Actually respect the commit argument when pulling
We now allow this to be set with update --commit=123abc in the oci case
too.
2020-05-05 09:33:09 +02:00
Alexander Larsson
cf49bd4ac8 oci: Support reconstructure individual commit objects (sorta)
This downloads a manifest by digest and reconstructs the commit except
for the tree/metadata reference. This allows things like flatpak remote-info
and flatpak update --commit=xxx to work.
2020-05-05 09:33:09 +02:00
Alexander Larsson
56f530ca1f dir: Add flatpak_remote_state_new_oci_registry helper
This is duplicated in a few places
2020-05-05 09:33:09 +02:00
Alexander Larsson
2028a5323f dir: Share some code that downloads commit objects
Only have the single function flatpak_remote_state_load_ref_commit()
that loads the commit objects (and don't support loading other types
of objects as that is not used).

This is a minor cleanup, but it also will be useful later when
we want to be able to "load" commits from OCI repositories.
2020-05-05 09:33:09 +02:00
Alexander Larsson
fdfcae7a91 By default, always try to auth to OCI remotes
This makes for instance docker hub work.
2020-05-04 16:32:22 +02:00
Abderrahim Kitouni
d145723fe3 dir: set cache directory when creating child repos 2020-05-04 12:15:21 +02:00
Matthew Leeds
e847bb31b6 installation: Re-implement list_installed_refs_for_update()
Re-implement flatpak_installation_list_installed_refs_for_update() using
a FlatpakTransaction, so we can guarantee it always gives the same set
of things to update as the update command. This API is used by GNOME
Software and many times in the past g-s has not shown the same list of
apps to be updated as the flatpak CLI. See:
- https://gitlab.gnome.org/GNOME/gnome-software/issues/539
- https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/430

This commit also expands the unit tests for this API, which were already
quite good. Now we test that missing subpaths of locale extensions show
up as updates, and updates that have been pulled but not deployed show
up as well. The latter is a break from how this function used to behave,
but it seems unlikely to break any application.
2020-04-16 09:22:11 +02:00
Alexander Larsson
b4b72b8de2 Use extra-data download size from summary if available
This avoids an extra download when new new extra-data information is
available in the summary.
2020-04-03 16:45:45 +02:00
Alexander Larsson
3eaec588d7 Don't always create commitpartial files in child repos
We used to always create a commitpartial file in child repo, because
ostree doesn't follow parent repos when loading commitpartial state,
and when the commit was in the parent repo it would find the commit
but no commitpartial and assume the commit was complete and do nothing.

However, having a commitpartial file seems to break delta downloads in
ostree, as per: https://github.com/ostreedev/ostree/issues/2053
causing us to download too much data when using deltas.

So, we now only create a commitpartial if there is one in the parent
repo.  This still means we will get the ostree problems in case there
is one, but in the much more common case we avoid the issue.

In order to "fix" the uncommon case we also (separately) cap the
reported progress at 100%. (We should probably also fix the upstream
ostree issue too.)
2020-04-03 12:56:59 +02:00
Alexander Larsson
ee702c8a91 Remove outdated comments
We no longer create a transaction in flatpak_dir_setup_extra_data since
203a10ae25, so don't claim to.
2020-04-03 12:55:44 +02:00
Alexander Larsson
203a10ae25 Revert "Revert "extra-data: Simplify extra-data progress setup""
This reverts commit 2120b99ac6.
2020-04-03 09:32:21 +02:00
Alexander Larsson
401cd4b2a5 Merge pull request #3523 from flatpak/fix-install-gpg-error
Fix "Can't pull from untrusted non-gpg verified remote" error
2020-04-01 15:56:34 +02:00
Matthew Leeds
2120b99ac6 Revert "extra-data: Simplify extra-data progress setup"
This reverts commit 6deb23a322.

This commit has two unintended side effects:
1. It breaks progress bars
(https://github.com/flatpak/flatpak/issues/3448)
2. It causes us not to use static deltas
2020-03-30 16:58:14 -07:00
Matthew Leeds
8571111e13 dir: Reload remote state after migrating config
Fixes https://github.com/flatpak/flatpak/issues/3496
2020-03-30 14:07:46 -07:00
Alexander Larsson
b28271bb5e Merge pull request #3498 from alexlarsson/use-symlinks-for-sideload-config
Use symlinks instead of xa.sideload-repos config option
2020-03-30 16:03:54 +02:00
Alexander Larsson
8cf75df52a dir: Rename variable to make things clearer 2020-03-30 15:37:26 +02:00
Alexander Larsson
c9878f040e dir: Add define for "sideload-repos" dir name 2020-03-30 15:36:54 +02:00
Alexander Larsson
527e6b247b Pass token to using flatpak_dir_fetch_remote_commit() when available 2020-03-30 15:03:55 +02:00
Alexander Larsson
0ef69c96db http-utils: Rename flatpak_load_http_uri to flatpak_load_uri and support file:
Various places (like the new load-commit-for-extra-data-setup) needs to
support file: uris, lets make it available generically.
2020-03-30 15:00:51 +02:00
Alexander Larsson
6deb23a322 extra-data: Simplify extra-data progress setup
We need to get the commit object to setup the extra-data progress information,
and this is currently done using a complex pull operation to a temporary
repo. According to https://github.com/flatpak/flatpak/issues/3515 it
even causes an unecessary download of the summary in some cases.

Now that we don't need to support p2p we can instead directly download
the commit object using a simple http operation (or from the sideload
repos), as we know the commit id at this point anyway.
2020-03-30 13:24:15 +02:00
Alexander Larsson
c222f03c10 FlatpakProgress: Clean up APIs for handling extra data
We don't need to keep recalculating the nr of extra_data items remaining.
We know the initial value and can just decrement it each time one
completes.
2020-03-27 17:23:13 +01:00
Alexander Larsson
ed3ba39a06 Fix calculation of extra-data total size
This is a bug introduced in b03916f5bd
where we check the extra_data refs against app/ or runtime/ prefix with
arguments in the wrong order.
2020-03-27 17:21:17 +01:00
Alexander Larsson
b7f0c17762 FlatpakProgress: Handle NULL in most methods
I noticed several places in flatpak-dir.c that didn't check for
NULL progress, so lets move the check inside the implementation so
we can ensure its always checked.
2020-03-27 16:04:36 +01:00
Alexander Larsson
52224b0463 FlatpakProgress: Move default value into FlatpakProgress 2020-03-27 16:04:36 +01:00
Alexander Larsson
4ef12c5bc9 FlatpakProgress: No need to allocate FlatpakMainContext
We store it on the stack instead and free with
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC.
2020-03-27 14:44:00 +01:00
Abderrahim Kitouni
192d31d315 Add a FlatpakProgress object
To avoid the complexities of passing (and chaining) OstreeAsyncProgress
objects around, we only create one just before calling to ostree.
The rest of flatpak only ever uses the new FlatpakProgress object.

Co-authored by: Philip Chimento <philip@endlessm.com>
2020-03-26 21:09:19 +01:00
Simon McVittie
09f05a6f87 dir: Format 64-bit ints correctly
%ld is only 32 bits long on ILP32 (32-bit) platforms.

This partially addresses #3499.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-03-26 11:38:13 +00:00
Alexander Larsson
15c761d482 Use symlinks instead of xa.sideload-repos config option
Instead of having a global config option we scan a directory for
symlinks into the sideload repos. These come from
/var/lib/flatpak/sideload-repos and /run/flatpak/sideload-repos (for
default system installation).

This is much easier to update atomically, and the two different
options are useful for persistant (the first) or dynamic (the second)
usescase.

Fixes https://github.com/flatpak/flatpak/issues/3494
2020-03-26 11:50:54 +01:00
Alexander Larsson
c092fa4cb7 installation: Reimplement flatpak_installation_list_installed_refs_for_update
Instead of doing a lot of FlatpakInstallation calls we do lower level
FlatpakDir calls, sharing a single RemoteState per remote for the
entire operation. Also, some parts of the checks are moved to FlatpakDir
as flatpak_dir_check_if_installed_ref_needs_update()
2020-03-25 08:27:18 +01:00
Alexander Larsson
56158a0087 DeployData: Add commit timestamp to deploy data
We want to use this to do quick checks if we need to do an update.
2020-03-24 20:12:50 +01:00
Alexander Larsson
83795c210c Remove unused variable 2020-03-24 17:29:19 +01:00
Alexander Larsson
9c6bdc5bfd dir: Add flatpak_remote_state_load_data() function
This is similar to lookup_cache() but it also works for
sideloaded refs. Additionally it returns an allocated metadata
pointer rather than a pointer to the cache.

Also convert some callers to use this when it makes sense.
2020-03-24 16:15:23 +01:00
Alexander Larsson
8999e70c4a RemoteState: Try the sideload paths even for local-only states
This is so we can use these for listing sideloaded refs.
2020-03-24 16:13:24 +01:00
Alexander Larsson
a843d2d594 sideload: Add api and CLI support to specify sideload repos dynamically 2020-03-24 14:01:20 +01:00
Alexander Larsson
e4df0fa6a6 sideload: Support pulling individual objects from sideload repos
We use the localcache-repos option to ostree_repo_pull to make ostree
directly import any files that are locally available in the sideload
repo even when pulling the main commit from upstream.

This also adds a test that verifies that such files are not
pulled via http.
2020-03-24 11:46:33 +01:00