Commit Graph

1227 Commits

Author SHA1 Message Date
Matthew Leeds
5cff4500a2 transaction: Fix error handling for related refs
This commit fixes the handling of errors from installing/updating
related refs during a transaction, so that they're treated as non-fatal,
and so that the operation is skipped if the primary operation fails. The
current behavior is that a failure to install/update a related ref
causes the whole transaction to fail, and even after a failure to
install/update the primary ref the related ref install/update is
attempted.

I hit this error when doing an offline USB app install, when the USB
repo has an older version of the runtime and the runtime's locale
extension than what's in the local repo. Without this commit, the
failure to update the runtime (due to it being a downgrade) is treated
as a warning, but the failure to update the runtime locale is treated as
an error. With this commit, the runtime update failure is still treated
as a warning, and the locale update is not attempted. This is better
behavior because the locale extension update (or even install) is not
critical to the app install.

Closes: #1979
Approved by: alexlarsson
2018-08-17 09:34:34 +00:00
Alexander Larsson
ef9297a0f1 dbus-proxy: Fix handling of broadcasts
In https://github.com/flatpak/flatpak/pull/1689 we were meant to
have limited the receiving of broadcasts on portals, but die to a
bug in the proxy we accidentally allowed all broadcasts anyway.

The change which ignores all applied filters < POLICY_TALK fixes that.

However, it also turns out that the desktop portal actually *does*
rely on signals. For example the network portal uses property change
notification.

So, to make sure this works we allow all signal from the portal
names, but only if they are on a object path starting under
/org/freedesktop/portal (which incidentally all portal object are).
This means there is no real change in anything that is currently
deployed, but it does allow portals to opt out of this global signal
visiblity if they want by using a different object path, which we
want to use in dconf.

Closes: #1976
Approved by: alexlarsson
2018-08-17 09:24:13 +00:00
Matthew Leeds
cbc0046554 transaction: Fix a regression in installing bundles
This commit fixes a regression that causes installing from a bundle to
fail if the bundled app's runtime was itself installed from a bundle, or
otherwise has a non-working remote (such as when the user is offline).

The fix is to treat a failure of flatpak_dir_find_latest_rev() as
non-fatal in resolve_ops() if the ref in question is already installed.
In other words, if we don't need to fetch a ref for the transaction to
succeed, errors in fetching remote info about the ref shouldn't be
fatal.

Closes: #1973
Approved by: alexlarsson
2018-08-17 09:14:26 +00:00
Matthew Leeds
9616737c0b dir: Fix a subpath checkout error message
In this loop we're checking out a subpath under /files, not /metadata,
so fix the error message.

Closes: #1970
Approved by: alexlarsson
2018-08-17 08:45:36 +00:00
Matthew Leeds
4c5fc20d60 common: Improve "No xa.metadata" error messages
When I run `flatpak update` I get messages saying "Warning: No
xa.metadata in commit" which isn't very helpful without knowing what
commit is being referred to. So this commit adds the checksum and ref to
such error messages.

Closes: #1978
Approved by: alexlarsson
2018-08-17 08:35:07 +00:00
Alexander Larsson
341ad02193 flatpak_dir_remote_make_oci_summary: Actually use cache
We need to return early on cache hits.

Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Alexander Larsson
9cc0f0d404 Fix leak in flatpak_cache_http_uri
Need to free the return value of soup_header_parse_param_list

Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Alexander Larsson
3d9a616632 flatpakref: Fix leak of gpg key string
Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Matthew Leeds
c3a0617557 NULL initialize g_auto variables
It's a good idea to NULL initialize g_autoptr/g_autofree variables, so
we can be sure uninitialized memory isn't passed to g_free or similar.

Closes: #1968
Approved by: alexlarsson
2018-08-17 08:06:51 +00:00
Matthew Leeds
745287e48f dir: Fix another GVariant leak
g_variant_builder_end() returns a floating reference, so sink it.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:10 +00:00
Alexander Larsson
75adff05f4 flatpak-json: Don't leak empty optional nodes.
Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
4b8624e705 flatpak_yes_no_prompt: Fix leak of formated string
Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
a6bec60d24 flatpak_dir_find_remote_related_for_metadata: Fix leak
Move extension_ref into the loop so its freed every iteration.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
335f69675e Fix leak in flatpak_transaction_ensure_remote_state
We return a ref now, and free it in all callers, otherwise
the non-caching codepath of this leaks the state.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
cbbc98b50d Make FlatpakRemoteState refcounted
This is needed to fix a memory leak

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
c70078b7eb flatpak_dir_read_latest: Fix leak
Make sure we free res if we exit early

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
ebb3ff532d Fix GVariant leak
ostree_async_progress_get_variant returns a ref, so free it.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
7df3f9f1ba appstream: Fix leak
Move some autoptr to the inner scope of the loop over each
appstream branch to avoid leaking.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
ed1d7eacf4 Fix regression from #1961 which broke the tests
Sometimes (for example in some test-repo-collections.sh test that broke) we
update from a remote with an older ostree-metadata branch, and the
check for downgrades broke in this case.

Its unclear exactly what it the best solution here, maybe to silently
disallow the update. However, this change instead just re-allows the
downgrade for this particular case so we get the old behaviour.
2018-08-13 12:10:22 +02:00
Owen W. Taylor
09d0e83c43 Handle switching a remote type between OCI and non-OCI
When we switch the remote type, we need to clean up cached files
(appstream, OCI index/summary) because they are stored differently
for the two types of remote.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
df431fe4b0 Remove unused calls to ostree_repo_remote_get_url 2018-08-13 11:23:28 +02:00
Owen W. Taylor
d7d05a8619 Use oci+http[s]:// as an URL to identify OCI registries
The old pattern of using a separate 'OCI' flag was very ugly
internally in the code once it was extended to flatpak bundles and
flatpakrefs - using a different URI scheme means that the nature
of the remote can't be accidentally lost in some part of the code.

Probing would be possible as well, but would make it difficult to
add a remote when offline, and also doesn't deal well with the
fact that our data layout is different for the two types of remotes -
the type of remote could change at any point!

As a side effect this change enables flatpakrefs and flatpak bundles for OCI
registries.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
b283084826 Improvements to index URI generation for OCI registries
* Restrict the queried images to the desired architecture
* Sort query parameters as the spec requests
* Allow a fragment on the remote URI to mean "tag to query for
  in the registry"
* Tweak flatpak_oci_index_ensure_cached() not to return the
  index URL in the normal error case.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
d64c1c1b95 flatpak_dir_remove_oci_file(): be tolerant of missing files
If a remote is removed before we ever fetched content, the OCI
index and summary files won't exist.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
8fe9bf4d86 Look at all refs when verifying a ref for flatpak-system-helper
The normal behavior where we only list already installed refs for
a noenumerate remote doesn't work for the case where flatpak-system-helper
verifies a ref on an OCI server during installation - in that case, the
ref being installed to does not *yet* exist locally.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
70776b0eaf Fix args to flatpak_bundle_load 2018-08-13 11:23:28 +02:00
Owen W. Taylor
00b5f568ec Clean up properly when pruning an origin remote
Using flatpak_dir_remove_remote() rather than ostree_repo_remove_remote()
means that appstream and OCI index/summary files will be properly
removed.
2018-08-13 11:23:28 +02:00
Matthew Leeds
5b21a5b7fc dir: Fix detection of downgrades for P2P operations
In general Flatpak tries to prevent downgrades of anything: apps,
runtimes, repo metadata, etc. with some exceptions such as when the user
specifies a commit they want. However at the moment the detection of a
downgrade is broken if both of the following are true: (1) a collection
ID is enabled on the relevant remote, and (2) a per-user installation
is being used instead of the system-wide one (or the system-helper is
otherwise being circumvented, such as by running flatpak as root).

This bug is a security vulnerability, but it's one with limited impact
because very few people have collection IDs enabled yet, and the
downgrade attack would require either a MITM on the network connection
(which HTTPS should prevent) or a malicious USB drive or local network
peer.
2018-08-13 11:21:46 +02:00
Alexander Larsson
3fa34ebd8a Work around libsoup recursive type hang in tests
Closes: #1952
Approved by: alexlarsson
2018-08-09 15:45:08 +00:00
Owen W. Taylor
65770d800f system-helpers: When deploying OCI's, verify refs against summary, not server
We previously made a separate request to the registry index to see if
the manifest hash of an image was the hash of the image in the registry.

Since the summary is now downloaded by the system helper and trusted, just
check if the hash matches the hash in the summary data. This is as good,
and in is a lot more efficient if the index is statically generated,
and we can't get the index data for just one image.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:36 +00:00
Owen W. Taylor
1cbae3d1af Cache the downloaded registry index in compressed form
The OCI index information should be highly compressable (especially if
icons are remote URI's rather than data URI's) so downloading it and
storing it compressed will provide sigificant efficiency gains.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:36 +00:00
Owen W. Taylor
c4c06b7be4 Allow using a compressed cache for HTTP downloads
Add a new flag for flatpak_cache_http_uri() that adds Accept-Encoding: gzip
to the request, and if the result is returned compressed, stores the data
compressed. If the data result is return uncompressed, it's compressed.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
4dfa7721bb Remove unused etag functionality
Checking the registry against a previous etag is now handled inside
flatpak_cache_http_uri(), so remove the etag parameters that were
previously passed around in various places for simplicity.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
baa7d35ca1 Extract the appstream data from the OCI registry index
Previously the code assumed that appstream data was stored in a separate
OCI image in the registry. Replace that with storing the appstream data
and icons as image annotations. When we download a new version of the
image index, the appstream data is combined, and icons are downloaded
as necessary.

Since there is no longer a content hash for the appstream data, it's
not practical for the user to download the appstream data and pass it
to the system helper, instead the system helper just downloads the
appstream data directly.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
926678b736 Use http-driven caching for summary generation
Redo the handling of generating summary information from an OCI registry
to be a two step process. First download the index, using the newly
added HTTP caching functionality. Then regenerate the summary from the
index, using mtimes to avoid duplicate work.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
951aed561a Add flatpak_cache_http_uri: cache downloads based on HTTP headers
Add a new function, flatpak_cache_http_uri() that when passed an URL and
a local destination location, either a) downloads the content and stores
it at the destination location, storing HTTP cache header information
like Last-Modified, Etag into user xattrs (if available) or a separate
file or b) if the downloaded content is already present, checks the
header information to decide whether the downloaded content can be used
or needs to be revalidated witha conditional request.

Tests are added that use a special case test server that adds HTTP caching
headers and reacts to them based on query parameters. A small test binary
'httpcache' is added for the tests to use.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
cd6a10cb66 flatpak-utils-http.c: Split HTTP functionality into a separate file
In preparation for extending the HTTP downloading function to include
caching, split HTTP related utilities into a separate file with a
separate header.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
66f618fa83 Remove support for OCI image layouts on remote servers
The code checked whether an OCI registry URI was an OCI image layout accessed
via HTTP by looking for /oci-layout, but distributing OCI images in this way
is not really a thing anybody does. It would be inefficient way to store
large numbers of images, since all versions need to be listed in index.json.

The code still uses OCI image layouts to represent "local registries" in
analogy to local ostree repositories.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
9916280f02 Fix various double / in generated OCI index URIs
In a couple different places, double slashes were inserted into the
generated OCI index URIs - e..g, index//static instead of index/static.
While most HTTP servers/applications will normalize double slashes,
this is not required, and such URIs are, in any case, ugly.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Matthew Leeds
69fc58d345 dir: Fallback to the system default locale, not all
When Flatpak is fetching a locale extension it has to decide which
subpaths to fetch based on what language is being used on the computer.
This happens in flatpak_dir_get_locale_subpaths() which indirectly uses
the org.freedesktop.Accounts D-Bus object to check what language is
configured for each user. The problem is that if any user doesn't have a
language set, Flatpak falls back to pulling all languages, rather than
checking the system default using localed. The effect is that on Endless
OS systems, Flatpak is pulling entire locale extensions rather than just
the subset for the configured language, which is a significant waste of
bandwidth. In my testing, the "Language" property on the primary user
account is not set on Endless, but it is set on Fedora.

A side effect of this bug is to cause offline USB app installs to
sometimes fail, because if the USB only has a partial locale and you try
to pull the whole thing, the pull fails.

This commit fixes the issue by doing another D-Bus call to localed to get
the system default(s), then checking AccountsService as before, treating
an unset language for a user account as meaning "use the system
default". Then only if no languages are set for the users or the system,
fall back to pulling all languages. The code to communicate with localed
is based on the code in gnome-control-center in
panels/region/cc-region-panel.c

This extra synchronous D-Bus call adds some overhead which might be able
to be avoided; see https://github.com/flatpak/flatpak/issues/1938

Using this patch I can see that Flatpak is pulling partial locales now,
based on the output of `flatpak list -a | grep partial` after installing
Bijiben from Flathub.

Closes: #1937
Approved by: alexlarsson
2018-08-08 15:04:11 +00:00
Matthew Leeds
a42af4a795 dir: Remove unused GDBusConnection variable
We're using g_dbus_proxy_new_for_bus_sync() not g_dbus_proxy_new_sync()
so we don't need a GDBusConnection.

Closes: #1937
Approved by: alexlarsson
2018-08-08 15:04:11 +00:00
Matthew Leeds
8292732e65 Add a system-helper UpdateSummary method
This system-helper method will allow flatpak to update the ostree repo
summary while running as a non-root user that's in the "sudo" group.
This will allow the `flatpak create-usb` command to work without
requiring the user to first run `sudo ostree summary -u`, and without
requiring the system to have `core.auto-update-summary` set to true in
the ostree repo config. This is also much more efficient than
`core.auto-update-summary` because it allows us to only update the
summary when we need it rather than after every transaction.

Generating the summary basically just involves traversing the repo to
enumerate all the refs and putting this information into a file, so I
don't think there are security concerns with allowing it to happen
without authentication.

Closes: #1945
Approved by: alexlarsson
2018-08-08 14:42:16 +00:00
Umang Jain
153720a737 common/dir: min-free-space-size should be honored for child repos too
https://github.com/flatpak/flatpak/issues/1826

Closes: #1912
Approved by: alexlarsson
2018-08-08 14:29:45 +00:00
Umang Jain
13610e3ed3 common/dir: Port to min-free-space-size
Use min-free-space-size as a replacement for min-free-space-percent.

Previously, flatpak used to disable min-free-space-percent by re-writing
the config with min-free-space-percent=0. As the new version of ostree (2018.7)
now supports min-free-space-size, we should use that and migrate from -percent
option in existing repos to -size=500MB.

Config is rewritten with min-free-space-size in case of:
1) It has min-free-space-percent=0 only. (That is probably from the
   previous re-writes).
2) If there are no min-free-space-* options.

Other than that, the config remains unchanged and the co-existence(if any)
of these options is governed by ostree.

https://github.com/flatpak/flatpak/issues/1826

Closes: #1912
Approved by: alexlarsson
2018-08-08 14:29:45 +00:00
Umang Jain
d34d117ae4 utils: Copy g_ascii_string_to_unsigned from glib-2.54.0
This avoids the glib's version bump needed for the subsequent min-free-space-size
porting patches.

Closes: #1912
Approved by: alexlarsson
2018-08-08 14:29:45 +00:00
Matthias Clasen
1efc0ac49f Avoid a crash in the absence of session bus
When the system bus is not available, we set
system_helper_bus to (gpointer)1. And then we
segfault in finalize, trying to unref it.

Thats not nice, so avoid it.

Closes: #1940
Approved by: alexlarsson
2018-08-06 07:55:34 +00:00
Matthias Clasen
fa9aad2e09 Warn when skipping installations
When we fail to parse an installation, emit some
warnings that give the user a chance to figure out
what is going wrong. I ran into the missing quotes
issue myself when I first tried to create a custom
installation.

Closes: #1939
Approved by: alexlarsson
2018-08-06 07:34:40 +00:00
Matthew Leeds
f8bb76cd30 common: Fix a couple typos 2018-08-02 15:42:07 -07:00
Matthias Clasen
9783472eaa Fix error pileup
All the error handling in the for loop is meant to
use local_error, not error.

Closes: #1936
Approved by: mwleeds
2018-08-01 16:50:11 +00:00
Richard Hughes
0afef8a38a Fix a memory leak when calling flatpak_build_file()
Closes: #1898
Approved by: mwleeds
2018-07-12 13:14:03 +00:00