Commit Graph

397 Commits

Author SHA1 Message Date
Alexander Larsson
5dae1fc6bc Break out ref helper functions to separate file
flatpak-utils.c is getting large, and also I got some issues with
include order, so split out things that are purely handling ref stings
in various ways to its own file.
2020-11-05 10:43:10 +01:00
Alexander Larsson
ed192e1044 remote-ls: Add a smarter fallback for names if appstream is missing
Rather than just taking the last element of the name we also
look at known extensions like .Platform, .Sdk, .Debug, .Locale, etc.
2020-11-05 10:43:10 +01:00
Alexander Larsson
7465ba0f18 Various FlatpakDecomposed API updates
getters now have three forms:
  const char *foo_peek() returns pointer into data and length
  const char* foo_get() returns zero terminated pointer into data
  char *foo_dup() returns allocated zero terminated pointer

Not everything has all of these (as that is not always possible), but
it is clear what each one does.

We also now support storing a collection id for a
FlatpakDecomposed. This is not typically done (as we use the source
remote to define the collecion id and don't expose this concept to the
user). However, for the case when directly listing a local repo (such as
a side-load repo) we need this.

We now validate the arch string. The valid chars are a-z, A-Z, 0-9 and
_. This was't previously verified, but no arches in existance have other
chars.

There is a new flatpak_decomposed_new_from_decomposed() which lets you
modify part of another ref. Say replace the arch or the branch and
keep the rest the same.
2020-11-05 10:43:10 +01:00
Alexander Larsson
3522d183bc summaries: When regenerating summaries, ensure they get newer mtimes
The st_mtime field is all we can guarantee to keep, so whenever we
write a new summary file for a repo we ensure it is newer than the old
by checking if st_mtime is equal (or less) and if so, use the old
st_mtime plus one.

This means sometimes the generated summary files will be in the future but
that only happens in the corner case of multiple changes inside one
second, and in that particular case we need this change.

This fixes some issues I had with the mtime chacking in the tests due to
the python httpd handling If-Modified-Since based on st_mtime.
2020-11-03 12:57:37 +01:00
Alexander Larsson
472939f538 utils: Add FlatpakDecomposed helper
This is a ref-counted version of a ref string that is guaranteed
to be in the proper form, and is pre-decomposed for efficient partial
matches.
2020-10-29 15:30:35 +01:00
Alexander Larsson
7483a98769 utils: Allow passing sizes to more utils
These now take (optional) string length args:
  flatpak_id_has_subref_suffix()
  flatpak_levenshtein_distance()
  flatpak_is_valid_name()
  flatpak_is_valid_branch()
2020-10-29 15:30:35 +01:00
Alexander Larsson
5b52b64cd1 Export flatpak_repo_load_summary_index() and flatpak_repo_load_digested_summary() 2020-10-29 15:30:35 +01:00
Alexander Larsson
98e20c18f9 summaries: Support using summary deltas on client
Also prune old unreferenced subsummaries on each transaction.
2020-10-29 15:30:35 +01:00
Alexander Larsson
2c6fec556f summaries: Generate summary deltas when updating repo 2020-10-29 15:30:35 +01:00
Alexander Larsson
0d2cf085af Add option to disable generating summary index
This is mainly useful for the tests
2020-10-29 15:30:35 +01:00
Alexander Larsson
0597f246c8 build-update-repo: Generate new summary format
In addition to the old summary file we create a summary.idx and
a set of per-arch subsummaries (and extra copies of these if any commit
specify a subset). These are much smaller, and eventually we will also
get deltas for them.

We are not yet using these new formats, although the code is there
to use them once we start downloading them.
2020-10-29 15:30:35 +01:00
Alexander Larsson
096daf91f2 summary: Implement a new, more efficient, summary format
This drops the deltas from the summary and uses the per-commit
metadata field to add the cache data to avoid the need for the separate
xa.cache and xa.sparse-cache indexes. This way we avoid repeating the
refs in multiple places.

Nothing uses this format yet, but we still pass make check if we enable
it.
2020-10-29 15:30:35 +01:00
Alexander Larsson
b094585545 utils: Expose get_compat_arch_reverse() and get_arch_for_ref()
We need to use these from some other files too.
2020-10-29 15:30:35 +01:00
Alexander Larsson
c5d76e5a85 summary: Extract the summary generation code to helper 2020-10-29 15:30:35 +01:00
Alexander Larsson
b7e90d3809 summaries: Add support for limiting which arches end up in summary
This is in preparation for adding other formats for summary and we
might not want all the arches in the fallback summary format.
2020-10-29 15:30:35 +01:00
Alexander Larsson
f84b48ac58 utils: Reimplement summary generation
This moves the generation of the summary files completely into flatpak
allowing us to (later) customise what goes into it in more detail and
generate other forms of summaries.
2020-10-29 15:30:35 +01: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
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
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
332f75494b Properly validate configured collection IDs
This commit is a follow-up for the commit "dir: Validate locally
configured collection IDs". Whereas in that commit we validate the
collection ID in flatpak_remote_state_fetch_commit_object(), here we do
it in _flatpak_dir_get_remote_state(), since fetch_commit_object() is
not called on the code path normally taken for a transaction (only if
try_resolve_op_from_metadata() fails and in other niche scenarios).

This should ensure that if someone erroneously sets a collection ID on a
remote, the error will be caught quickly. It also helps the eos-updater
unit tests pass.
2020-08-21 09:35:49 +02:00
Alexander Larsson
52f33bc3f6 flatpak_switch_symlink_and_remove don't remove old if same as new
If we're switching to a target which happens to be the same as the old
one, don't remove the old one (as it is also the new one).
2020-06-08 11:35:14 +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
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
f2cb157294 oci: Use the correct progress layer size when using deltas 2020-06-05 09:35:30 +02:00
Alexander Larsson
8c454f99f2 oci: Add debug spew when using deltas 2020-06-05 09:35:30 +02:00
Alexander Larsson
7be653a14d oci: Find and apply available deltas when pulling 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
29da4ca430 oci: Store the last layer diff-id in the commit metadata (xa.diff-id)
We an use the commit content as original data for deltas going from
this diff-id, so this will be useful later.
2020-06-05 09:35:30 +02:00
Alexander Larsson
bf0bd3874b Add extra data download size to sparse cache in summary
This adds the nr of extra datas, as well as the total size in the sparse
cache for all refs that has them. This is what we need for in the download,
and having it in the summary means we don't have to separately download
the commit.

Additionally we add a cache version field to the summary so that we
can know if we can rely on the existance of the new data.
2020-04-03 16:27:33 +02:00
Matthew Leeds
e7fd267ac7 common: Delete no longer relevant comment 2020-03-30 13:55:47 -07: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
Alexander Larsson
05eba2b32c Merge pull request #3474 from flatpak/wip/hadess/more-similar-appids
common: Allow version numbers in app-id for DConf migration
2020-03-25 09:57:43 +01:00
Alexander Larsson
d30e902d9f Add build-update-repo --deploy-sideload-collection-id option
This is a new version of --deploy-collection-id that only applies
the collection id update for new (1.7.x+) version of flatpak clients.
This allows you to enable collection ids for sideload use but not
affect older clients where the p2p codepaths are not as tested.
2020-03-23 17:58:04 +01:00
Alexander Larsson
316baff539 Don't enforce gpg-verify false when using collection id
With the new sideload approach to collection ids it is fine to require
gpg signed summaries. (Not for the child repos or the sideload repos
though, but thoser are either trusted (sideload) or safe for other
reasons like ref-bindings and signed commits).
2020-03-23 17:58:04 +01:00
Bastien Nocera
98c4b07322 common: Allow version numbers in app-id for DConf migration
Allow the app-id or the DConf path to finish with a digit and still be
considered similar enough for DConf migration purposes.

This allows the org.gnome.Rhythmbox3 app-id to migrate its
/org/gnome/rhythmbox DConf path.

See https://github.com/flathub/org.gnome.Rhythmbox3/pull/26
2020-03-17 13:12:57 +01:00
Alexander Larsson
ff317fd4fb Enforce little endian for token-type
When storing the token-type in the commit and the summary cache we
hardcode it to little-endian.

In theory this breaks the "ABI", but in practice this change is a
no-op on little-endian systems which is what most are. Additionally as most
servers are little-endian this also fixes using big-endian clients with
such servers.

This fixes:
https://github.com/flatpak/flatpak/issues/3434
2020-03-16 11:26:10 +01:00
Matthew Leeds
6aa3ff0d6f common: Don't shadow parameter variables 2020-03-16 09:29:31 +01:00
Alexander Larsson
61da44a5e3 Convert flatpak_summary_lookup_ref from GVariants
Now it returns a VarRefInfoRef instead of a GVariant
2020-02-17 16:10:50 +01:00
Alexander Larsson
9f6c60405d utils: Convert summary ref lookup code to variant codegen
We can't use the built-in bsearch from the codegen because its an array
instead of a dict, so we have to keep that but its now not using
variant at least.
2020-02-17 16:10:50 +01:00
Alexander Larsson
7c4fd8891e Convert deploy data to use variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
ebca05ff10 utils: Add flatpak_bytes_save() 2020-02-17 16:10:50 +01:00
Alexander Larsson
3c6c51f46b build-commit-from: Fix generation of download-size
In flatpak-builtins-build-commit-from.c we call flatpak_repo_collect_sizes()
without initializing the passed in download size to zero, which mean
we sum with sizes with some random value as the start.

This is fixed by having flatpak_repo_collect_sizes() always initialize
the counters to 0 at the start.

Fixes https://github.com/flatpak/flatpak/issues/3362
2020-01-23 09:04:29 +01:00
Alexander Larsson
a98d655f4f Fix build on older glib
Don't use G_VARIANT_BUILDER_INIT() which is glib 2.50 only
2019-12-20 13:25:20 +01:00
Alexander Larsson
202b2508d5 filters: Fix some leaks 2019-12-20 11:15:39 +01:00
Alexander Larsson
7a8801da50 Fix leak in flatpak_repo_update() 2019-12-19 16:53:14 +01:00
Alexander Larsson
04162f3286 repo support for setting authenticator options
flatpak build-update-repo now lets you modify the
autenticator-name/install/options keys, and these are migrated to
the summary/metadata during update.
2019-12-19 10:33:21 +01:00
Alexander Larsson
798d90ef0c flatpakrepo files: Support Authenticator keys
This parses AuthenticatorName and AuthenticatorInstall
2019-12-19 10:33:21 +01:00