Commit Graph

6513 Commits

Author SHA1 Message Date
Simon McVittie
17b6c31c7c Add missing G_GNUC_PRINTF attributes
This allows callers to be checked for mismatches between format string
and arguments, and also means gcc can assume that the format string and
the arguments match up correctly when forwarding them to functions
like g_strdup_vprintf, removing the need to suppress -Wformat-nonliteral
warnings.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Simon McVittie
0592caca8a completion: Always pass a format string to flatpak_completion_debug
In principle this could have been subject to a format string attack
via an argument containing %n, although in practice the code that uses
this format string is #if 0.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Simon McVittie
3d5725f9d3 testcommon: Use unusual architectures where it doesn't matter
If we use x86_64 and i386 in places where any architecture would do,
it's harder to recognise whether the test is assuming every machine
is x86 and would fail elsewhere (e.g. as fixed in #4142). When just
parsing abstract strings where any syntactically valid architecture
would do, let's use rare/niche architectures that none of the maintainers
are running on, so that hard-coding x86_64 or i386 stands out more.

I've used mips64 and m68k because they happen to be the same length as
x86_64 and i386, avoiding re-indentation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:31:38 +02:00
scootergrisen
2bb9a8a198 Update Danish translation 2021-05-25 10:30:48 +02:00
Phaedrus Leeds
4f04f92e6f Merge pull request #4256 from flatpak/remote-ls-all-arches
Add FLATPAK_QUERY_FLAGS_ALL_ARCHES for list_remote_refs()
2021-05-19 16:26:29 -07:00
Alexander Larsson
515ae5e5df CLI: List arch if it is not the primary arch (even if unique)
Currenly we only list arch in the list of things to install from a
transaction if not all the refs are the same arch. It makes more sense
to show the arch even if its unique if they are not the primary arch.
2021-05-19 09:54:59 +02:00
Alexander Larsson
0a9d5ac7f2 Include more architectures when listing installed refs.
It turns out that we can't currently uninstall a ref from a
non-standard arch without specifying the arch even if there is no similar
ref installed for the main arch. (#4264)

The fundamental reason for this that `flatpak_dir_find_installed_ref(s)`
currently only returns refs with standard arches unless you explicitly
specify an arch.

This changes flatpak_dir_find_installed_refs() to always return
all the refs for all installed arches. This is generally what
we want anyway, except in the case of "flatpak run org.some.Platform" where
we don't want to prompt if there are multiple arches installed, so that
is manually changed.

This changes find_matching_ref() to look for refs in all arches, but
always prefer (without prompting) the default arch if that is installed.
This also matches what all current callers want.

Fixes #4264
2021-05-19 09:54:52 +02:00
Alexander Larsson
51ac8e1590 builtin-utils: Use shared helper
This uses the new flatpak_remote_state_ensure_subsummary_all_arches() helper
in ensure_remote_state_all_arches().
2021-05-19 09:49:30 +02:00
Alexander Larsson
540bcda3bd Transaction: Ensure we download the subsummary for the arch of added refs
By default we only download the main arch subsummary, so if you added
a ref for some other arch it failed to find the ref. This works with the
CLI, because it explicilty loads the subsummary when its trying to expand
the parial ref to the full ref. However apps using libflatpak don't do that
so they failed.
2021-05-19 09:49:30 +02:00
Alexander Larsson
ce9a1c4f6c Add FLATPAK_QUERY_FLAGS_ALL_ARCHES for list_remote_refs()
This allows flatpak_installation_list_remote_refs_sync_full() to list
refs for all arches on remotes that use the new subsummary format.

Fixes #4252
2021-05-19 09:49:25 +02:00
Simon McVittie
4c7d74ac57 doc: Add a release checklist for maintainers
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-17 10:02:51 +02:00
Philip Withnall
d5daaa537d tests: Fix test-summaries.sh when running tests as root
If the tests are run as root, the system helper is not used even when
commands are run with `--system`. This means a different cache path is
used (see `_flatpak_dir_ensure_repo()`). The tests did not accommodate
for that.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-17 10:00:33 +02:00
Philip Withnall
087dfe6630 Merge pull request #4269 from pwithnall/strcmp-crash
dir: Avoid a crash when looking up summary for a ref without an arch
2021-05-11 23:18:45 +01:00
Philip Withnall
a65e97c380 dir: Avoid a crash when looking up summary for a ref without an arch
If looking up the summary for a ref without an arch (for example,
`ostree-metadata`, which the Endless OS version of flatpak uses in some
backwards-compatibility code), avoid passing `NULL` to `strcmp()` and
hence crashing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-05-11 15:12:15 +01:00
Phaedrus Leeds
404d7c6941 Fix several memory leaks 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
4562627b04 utils: Add missing check for empty string collection id 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
66d00e1c47 list: Add a g_assert() for a coverity warning 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
a0188dee79 dir: Fix a GString leak 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
284510eabb remote-info: Fix memory leak of branch 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
75e60c5d8e remote-info: Fix printing of branch 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
756b9eae14 common: Fix several memory leaks 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
d191c2eb58 context: Fix leak of env var key/value pair 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
1120c7cb24 Fix memory errors w/ use of var_arrayofstring_to_strv() 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
879c9b9008 utils: Fix use-after-free and logic error
Without this change, validate_component() might free the "component"
variable, but then go on to keep using it. This change also makes the
code work as intended, to only have a flatpak-specific "bundle" in the
appstream xml (where here bundle does not mean "flatpak single-file
bundle").
2021-05-04 10:23:13 +02:00
Phaedrus Leeds
bc27dcb518 remote-list: Check for unlikely libostree error 2021-05-04 10:23:13 +02:00
Simon McVittie
bcdc073041 Update translation files for v1.11.1 release
Signed-off-by: Simon McVittie <smcv@collabora.com>
1.11.1
2021-04-26 12:47:36 +01:00
Simon McVittie
d7cf0736e0 Release v1.11.1
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-26 12:47:17 +01:00
Simon McVittie
f9e5ab264d NEWS: Summarize changes since 1.10.2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-26 12:42:03 +01:00
Simon McVittie
9a35bbc91c Merge tag '1.10.2', omitting changes in po/
Release 1.10.2

Git-EVTag-v0-SHA512: 849c1f828b993144d61353fc8f233d5f62ef773d4ded35e406797260b55a371cd7dc77cba1a4de912e05e9530f40adf9963789ac896ed3fe19ebce352031b85b
2021-04-26 12:21:28 +01:00
Alexander Larsson
283a3b93a5 tests: Add test for the flatpak prune implementation 2021-04-26 10:30:14 +02:00
Alexander Larsson
0cd4656ea1 Add (and use) custom, high-perfomance prune implementation
This is an optimized version of ostree_repo_prune() specialized for
archive mode repos. It is faster and uses less memory so that we can
prune larger repos (like flathub) in a realistic timeframe.

The primary reason it is faster is that it creates and uses a
`.commitmeta2` file for each commit, containing information about what
objects are reachable from that commit. This means incremental prunes
need only traverse over newly created commits.

Secondly, it uses the variant parser compiled accessors for the
various GVariants that are involved in the prune which is quite a bit
faster, especially if the repo is very large.

It also merges the scan-for-all-objects and prune-unreachable objects
phases, which means that we don't have to allocate a hashtable for
all the objects in the entire repo saving a lot of memory.

To save memory the hashtable of reachable objects, which can be quite
big on a big repo, points to a custom, very compact format for object
names.

Additionally it does the scanning for reachable objects twice, first
with a shared lock and then again (if anything changed) it with an
exclusive lock. This allows us to avoid using an exclusive lock during
the slowest part of the prune.

Unfortunately there are currently no public APIs for the ostree repo
locks. We really need to take an exclusive lock during the whole prune
or we parallel modifications (say a commit) might get their newly
written objects deleted. To work around this we have a minimal custom
implementation of an exclusive lock. Once the public API is available
we can start using that.

I created a repo with a lot of small commits to test this.  It has 9M,
and pruning with depth=10 deletes 2M of them.

The original performance looks like:

 Finding reachable objects: 287 seconds
 Pruning unreachable: 69 seconds

Just using the pregenerated reachable data:

 Finding reachable objects: 15 seconds
 Pruning unreachable: 69 seconds

The final optimized prune (using pregenerated data):

 Finding reachable objects: 12 seconds
 Pruning unreachable: 51 seconds

The above are with the page caches cleaned, on a second run the performance
increase is even more noticeable.

As a comparison to the above, finding the reachable objects in the
actual flathub repo took 22 hours, but with the pregenerated reachable data
only 39 minutes.
2021-04-26 10:30:14 +02:00
Alexander Larsson
07e1fd096d Compiled variants: Add some ostree types
This adds the ostree object name and the object info (returned from
ostree_repo_list_objects) to the set of variants we compile accessors
for.
2021-04-26 10:30:14 +02:00
Phaedrus Leeds
4485364825 README: Add related projects 2021-04-22 09:57:42 +02:00
Simon McVittie
686af7d3b8 test-instance: Add more assertions
scan-build points out that bytes isn't read after it is assigned. While
this is not actually true (scan-build doesn't understand
__attribute__((__cleanup__)), which frees bytes), it's true that we
should ideally have an assertion here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
12d7855493 enter: Make it clearer that rest_argv_start always gets initialized
scan-build complained that rest_argv_start could be used uninitialized,
because it can't see that rest_argc >= 2 implies that rest_argv_start
got initialized at the same time rest_argc was set. Make this easier
to understand.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
bd5c2762cf testcommon: Assert that parse_datetime succeeds
scan-build detected that ret was written but never read.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
3a85ceecfc testlibrary: Fix an assertion
scan-build detected that res was written but never read. Presumably
the use of ref here (carried over from the previous test) is a
copy/paste error.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
2a01318e15 ref-utils: Remove dead store
We always set match_len before using it, discarding the result of this
assignment. Detected by scan-build.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
3071d2ada9 quiet-transaction: Remove unnecessary finalize
This hasn't done anything useful since 0978826c: it just takes a
new ref to the installation, and then releases that ref without doing
anything with it. Detected by scan-build.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
c26a48a9aa Fix various unused variables detected by scan-build
scan-build has a lot of false positives for this codebase because it
doesn't understand __attribute__((__cleanup__)) or GLib's GError
convention, but it seems to have been right about these.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Yuri Chornoivan
54e783b8cd Update Ukrainian translation 2021-04-19 09:07:32 +02:00
Hubert Figuière
9e7c5fa545 flatpak_dir_find_local_related_for_metadata: Skip invalid branch
Fixes #4234
2021-04-19 09:07:10 +02:00
Piotr Drąg
f552d9a397 Update POTFILES.in 2021-04-16 18:09:51 +01:00
Simon McVittie
c2490aad12 app: Use autocleanup for FlatpakTablePrinter
Fixes: https://github.com/flatpak/flatpak/issues/4223
Fixes: https://github.com/flatpak/flatpak/issues/4224
2021-04-16 14:51:47 +02:00
Simon McVittie
282647c81f transaction: Avoid a possible use-after-free
scan-build detected that mark_op_resolved() can be called with
op->resolved_commit == commit, in which case we incorrectly freed the
string before allocating the new copy.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 14:51:12 +02:00
Simon McVittie
a0eaaf77ad revokefs: Use the right variable name in an error message
scan-build detected that response_size is uninitialized here, presumably
a typo for response_data_size.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 14:50:27 +02:00
Simon McVittie
1b930e955e oci-registry: Fix error reporting
The intention here seems to have been that failing to close the http
stream provokes a warning but does not make the function fail, but we
were setting the wrong error, resulting in a NULL dereference if closing
the http stream somehow fails.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 14:49:15 +02:00
Simon McVittie
4c676e4e3a portal: Reject negative handle numbers
In D-Bus, handles are defined to be unsigned, but in GVariant, for some
reason they're signed. Make sure they aren't negative, which could
result in a NULL dereference for fds.

A handle used in the conventional way will never legitimately be
negative (in GVariant's interpretation) or have its high bit set
(in D-Bus' interpretation), because file descriptors are signed 32-bit
integers, so an array of distinct file descriptors can never be long
enough for the distinction between signed and unsigned to matter.
In practice fds are limited by the kernel to several orders of
magnitude fewer than that anyway.

Fixes: 3ebf371f "run: Allow caller to replace /app and/or /usr"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 14:47:43 +02:00
Simon McVittie
38eac07293 run: Create a shared XDG_RUNTIME_DIR for each app-ID
Like $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this is shared between all
instances of the app, except for subsandboxed instances created by
flatpak-spawn --sandbox or equivalent. Unlike
$XDG_RUNTIME_DIR/app/$FLATPAK_ID, it does not exist at an equivalent
path on the host and in the sandboxed app.

Resolves: https://github.com/flatpak/flatpak/issues/4120
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 09:13:18 +02:00
Simon McVittie
40510e8ae8 run: Populate XDG_RUNTIME_DIR with symlinks into /run/flatpak
If XDG_RUNTIME_DIR is under app control, as it will be with #4120, we
don't want to be mounting pieces of filesystem directly into it, because
that will mean that the app could create a symlink that will cause us
to create a mount point for it at the target of the symlink, potentially
elsewhere in the host filesystem.

Instead, we mount them in /run/flatpak, which is a per-instance
directory entirely controlled by Flatpak; and then create (relative)
symlinks in XDG_RUNTIME_DIR, pointing into /run/flatpak.

In this commit, we still know that the XDG_RUNTIME_DIR is a
per-instance tmpfs, so we can safely create the symlinks using
the --symlink option. In a subsequent commit this will change to
creating them in a shared XDG_RUNTIME_DIR, if any.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 09:13:18 +02:00