Commit Graph

2029 Commits

Author SHA1 Message Date
Alexander Larsson
08dc7cb2aa dir: Remove unused non-_decomposed() helpers
This removes flatpak_dir_list_remote_refs() and
flatpak_dir_list_all_remote_refs() which have no more users, as everything
migrated to the _decomposed() versions.
2020-11-10 14:32:13 +01:00
Alexander Larsson
877cede50b decomposed: Store ref data inline if possible.
When we're not taking the string from elsewhere, store the string data
inline.
2020-11-10 14:32:13 +01:00
Alexander Larsson
cd34088969 Transaction: Convert internal refs to FlatpakDecomposed
We convert early in the API so that we can rely on the format everywhere
and use the faster getters for the parts of the refs.
2020-11-10 14:32:13 +01:00
Alexander Larsson
840cb2ed3d decomposed: Add id_has_suffix() helper 2020-11-10 14:32:13 +01:00
Alexander Larsson
db11607016 installation: Use the FlatpakDecomposed APIs to create FlatpakRef:s
This means we do a bit less string operations, but it also allows us
to pick up the collection-id when listing refs from a file: uri, fixing
the issues described in https://github.com/flatpak/flatpak/pull/3909

This slightly changes the behaviour of collection ids and remotes.
When listing regular remotes we only ever return the refs with the
collection id specified by the configuration of that remote. However,
when specifying a file: uri for the remote name we return all the refs
in the repo, with their corresponding collection id.

This means the test suite has to change a bit as before we returned
all the collrefs from the remote, not just the one matching the configured
collection id.
2020-11-05 10:43:10 +01:00
Alexander Larsson
247fed25ff remote-state: For local repos, set collection id for main ref table too
If you're listing a file: uri we (as before) add the collection-ref
tables, but we now also set the proper collection-id for the main ref
table if the ostree.summary.collection-id key is set.
2020-11-05 10:43:10 +01:00
Alexander Larsson
bd5029e72a dir: Add flatpak_dir_list_refs_decomposed() 2020-11-05 10:43:10 +01:00
Alexander Larsson
abb097f812 decomposed: Support defaults in flatpak_decomposed_new_from_parts
This allows NULL for arch and branch, similar to
e.g. flatpak_build_runtime_ref().
2020-11-05 10:43:10 +01:00
Alexander Larsson
3b63c51ce6 decomposed: Add support for FlatpakRefKind 2020-11-05 10:43:10 +01:00
Alexander Larsson
425147e4b1 Add flatpak_decomposed_new_from_parts() 2020-11-05 10:43:10 +01:00
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
7757b1dea7 RemoteState: For a local repos, add refs with all collection ids.
If you are listing a remote named (e.g.) file:///some/path/to/repo then we
have no idea what the actual collection id is for that remote, so we can't
pick the right part. In practice, this is typically done when listing
a side-load repo, such as described in
https://blogs.gnome.org/mclasen/2018/08/26/about-flatpak-installations/
or by the endless software installer that lists available offline apps.

This kinda abuses the FlatpakDecomposed object to store the collection
id, even if that doesn't normally carry this. This is not optimal, but it
is kind of a weird case and there isn't really any other place for it that
makes sense either, and having it there is efficient and keeps the APIs.
2020-11-05 10:43:10 +01:00
Alexander Larsson
089a5bebd5 Add flatpak_dir_list_remote_refs_decomposed() 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
Phaedrus Leeds
ce377e577f transaction: Tweak docs around eol-rebase 2020-11-05 09:33:26 +01:00
Alexander Larsson
97740ab3f6 remote state: Try loading non-index summary from memory cache before fetching
We used to go:
 * indexed summary memory cache
 * indexed summary fetch
 * compat summary memory cache
 * compat summary fetch

But now we go:
 * indexed summary memory cache
 * compat summary memory cache
 * indexed summary fetch
 * compat summary fetch

This means in the compat case we don't constantly have to fail the
summary fetch before using the memory cache.
2020-11-03 15:14:16 +01:00
Alexander Larsson
dddeaca8c3 transaction: Reuse FlatpakRemoteState when finding dependencies
This moves a bunch of code from FlatpakDir to FlatpakTransaction which was
only used to find dependencies. This allows us to reuse the existing
cache of FlatpakRemoteState objects in the transaction.
2020-11-03 14:19:58 +01:00
Alexander Larsson
3ebcd200ca Remove should-retry debug spew
Every http operation (even when successfull) was spewing info about
whether to retry it which made it hard to read the logs.
2020-11-03 12:57:37 +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
f647a5ea79 remote-modify: Clear cached summaries when the remote is modified.
This fixed some issues in the test where changing the url cause the
cache:ing to fail to update due to the mtimes being to new in combination
with the HTTP If-Modified-Since use.
2020-11-03 12:57:37 +01:00
Alexander Larsson
a3eaa36ce4 dir: Clear summary cache when updating metadata
For example, if the url changes we need to re-read the summary. This
was causing issues in a repo test where we re-wrote the url, and then
the new summary was not downloaded because of a st_mtime based
If-Modified-After check in the python httpd.
2020-11-03 12:57:37 +01:00
Alexander Larsson
a8fe3247e7 summary cache: Rename CachedSummary.remote to CachedSummary.name
This doesn't change the results but makes it more clear now that we don't
only use the remote name as the cache key.
2020-11-03 12:57:37 +01:00
Phaedrus Leeds
08e55a36aa transaction: Fix docs around op authentication 2020-10-29 20:26:08 -07:00
Alexander Larsson
7b5a0a5c86 Fix extra-data progress reporting
We were never calling the progress callback for extra-data downloaded
bytes.
2020-10-29 17:19:38 +01:00
Alexander Larsson
308e30c8f0 transaction: Remove transfer annotation for boolean
This doesn't do anything (and was causing warnings).
2020-10-29 16:08:12 +01:00
Alexander Larsson
c04df80ee1 Drop some spew from flatpak_dir_list_unused_refs()
This was showing up in every flatpak update, making it hard
to see the important stuff.
2020-10-29 16:08:12 +01:00
Alexander Larsson
e6d7a1148e summaries: Cache subsummaries per-arch
We store the cached subsummaries as `$remote-$arch-digest.sub`, this
way we can prune everything but the most recent (i.e. highest mtime)
rather than looking at the index. This way we don't prune old
subsummaries for other arches when we update one arch, which would not
let us use deltas for those.

Some details:
 * If mtimes are identical (mtime precision issue) for several
   subsummaries we keep all.
 * If we just saved a subsummary in the cache we don't prune that
   in case there is something wonky with mtimes.

The subsets for a remote are pruned every time we write a new cached
subsummary.
2020-10-29 15:30:35 +01:00
Alexander Larsson
2c8fe5b94c Use the new FlatpakDecomposed when mathing refs
This avoids lots of re-splitting and re-validation as well as strdups.
2020-10-29 15:30:35 +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
0221f5a1fa summaries: Ensure we can support non-default arches W/ indexed summaries
We need to load the ensure the right arch whenever we need it.

Also this restructures the RemoteState handling a bit in general so that
we avoid loading the same remote state multiple times when converting
partial refs to full refs.
2020-10-29 15:30:35 +01:00
Alexander Larsson
dce6f748bb summaries: Rework the debug spew for summary/cache loading
This way its easier to tell exactly what happens.
2020-10-29 15:30:35 +01:00
Alexander Larsson
5821f79d88 dir: Make flatpak_transaction_ensure_remote_state non-static
This moves it to fatpak-transaction-private.h so that we can use it
internally to be able to re-use the remote-states from the transaction
outside it.
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
57954e2efc summary: Enable use of indexed summaries in the client
We first try to download the index, then fall back to the old format.
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
Alexander Larsson
387bb8c64e Add flatpak_dir_get_remote_subset()
Reads the subset config for the remote, if any.
2020-10-29 15:30:35 +01:00
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