Commit Graph

1632 Commits

Author SHA1 Message Date
Bart Piotrowski
fcef62d77e Exclude EOL refs from fuzzy matching 2026-04-07 10:13:27 +02:00
fortime
c7824ae5f3 run: Add --no-scope to flatpak run
Don't run an app inside a transient systemd scope.

Closes: #6497
Fixes: #5870

Signed-off-by: fortime <palfortime@gmail.com>
2026-04-06 06:46:38 +05:30
Sebastian Wick
10470a82d3 tty-utils: Flush stdin before and after issuing Cursor Position command
If the user presses any key while we the CLI transaction UI is being
shown, it ends up in stdin. When we issue the Cursor Position command,
the result is appended to stdin and we fail to match on it because of
the proceeding bytes.

Similarily, if we fail to match the command output (bad data, too slow,
..), we leave behind data in stdin which will be echoed back to the
terminal when we restore the initial termios which icnludes ECHO in
c_lflag.

Let's use TCSAFLUSH to flush out stdin data before we issue the command,
which should help with matching the expected response.

Let's also use TCSAFLUSH when we restore the previous termios to make
sure the stdin is clean and we don't echo whatever remains in stdin.

Closes: #2712
2026-03-31 10:46:13 +00:00
Debarshi Ray
70ddf44b40 builtins-utils, dir: Be more strict about what is acceptable
The 'arch' parameter of flatpak_dir_remote_fetch_indexed_summary() is
used to construct the names of the caches, and can't be NULL.  This
function is used by flatpak_remote_state_ensure_subsummary(), which is
used by ensure_remote_state_arch().  So, the parameter can't be NULL in
those either.
2026-03-19 23:40:29 +00:00
Debarshi Ray
52d10816c7 completion: Avoid buffer overrun with strings having too many elements
Here are some strings representing valid refs:
  app/org.test.App/x86_64/stable - full ref
  org.test.App/x86_64/stable - full ref without prefix
  org.test.App - only app ID
  org.test.App/x86_64 - only app ID and arch
  org.test.App//stable - only app ID and branch

Therefore, if a ref's prefix (ie., 'app/' or 'runtime/) is skipped,
then there can only be a maximum of 3 other elements in it.

Right now, it's possible for find_current_element() to return a count
of 4, if the string being completed is invalid and has some extra
elements or slashes in it.  This count is later used to index the
cur_parts array which only has 4 elements in it.  This opens up the
possibility of a buffer overrun.

Invalid strings with extra elements or slashes can't be further
completed because none of the existing refs will match them.
Therefore, such strings should be outright skipped.

For the rest of the valid strings, the exact intended branch name is
never known, because the branch element doesn't have a trailing slash
and hence appears to be a prefix.  Therefore, it's not possible to use
the branch to find a list of existing refs that could possibly
complete the string.

Fallout from 7018717ce2
2026-03-19 23:40:29 +00:00
Debarshi Ray
48e7bf32ec builtins-utils: Remove unused function
Fallout from 0221f5a1fa
2026-03-12 19:20:55 +05:30
Debarshi Ray
d7f83c0db1 document-unexport: Fix a -Wanalyzer-null-dereference warning
OpenScanHub [1] triggered this and flagged it as CWE-476 [2]:
  app/flatpak-builtins-document-unexport.c:90:7:
      warning[-Wanalyzer-null-dereference]: dereference of NULL ‘doc_id’
  app/flatpak-builtins-document-unexport.c:48:1: enter_function: entry
      to ‘flatpak_builtin_document_unexport’
  app/flatpak-builtins-document-unexport.c:56:20: release_memory:
      ‘doc_id’ is NULL
  app/flatpak-builtins-document-unexport.c:61:6: branch_false: following
      ‘false’ branch...
  app/flatpak-builtins-document-unexport.c:66:7: branch_false: ...to
      here
  app/flatpak-builtins-document-unexport.c:66:6: branch_false: following
      ‘false’ branch...
  app/flatpak-builtins-document-unexport.c:69:6: branch_false: ...to
      here
  app/flatpak-builtins-document-unexport.c:69:6: branch_false: following
      ‘false’ branch...
  app/flatpak-builtins-document-unexport.c:72:3: branch_false: ...to
      here
  app/flatpak-builtins-document-unexport.c:75:6: branch_false: following
      ‘false’ branch...
  app/flatpak-builtins-document-unexport.c:78:15: branch_false: ...to
      here
  app/flatpak-builtins-document-unexport.c:82:6: branch_false: following
      ‘false’ branch...
  app/flatpak-builtins-document-unexport.c:85:7: branch_false: ...to
      here
  app/flatpak-builtins-document-unexport.c:85:6: branch_true: following
      ‘true’ branch...
  app/flatpak-builtins-document-unexport.c:86:14: call_function: inlined
      call to ‘g_strdup_inline’ from ‘flatpak_builtin_document_unexport’
  app/flatpak-builtins-document-unexport.c:90:7: release_memory:
      ‘doc_id’ is NULL
  app/flatpak-builtins-document-unexport.c:90:7: danger: dereference of
      NULL ‘doc_id’
  #   88|       return FALSE;
  #   89|
  #   90|->   if (strcmp (doc_id, "") == 0)
  #   91|       {
  #   92|         g_print (_("Not exported\n"));

Add an assertion to express that 'doc_id' can't be NULL unless there's a
programmer error.

Spotted by Siteshwar Vashisht.

[1] https://openscanhub.dev/

[2] https://cwe.mitre.org/data/definitions/476.html
2026-03-11 22:31:49 +00:00
bbhtt
50d9a2f735 builtins-update: Respect opt_noninteractive in update_appstream()
Use opt_noninteractive instead of hardcoded values so AppStream
refresh is quiet only when --noninteractive is specified. This allows
to show a better messsage instead of repeating and makes the errors
visible as well.

Related: #5716
2026-03-02 16:42:31 +00:00
matt
f256990331 builtins-update: Show a better message when there are no refs to update
Replace the "Nothing to do" message with "Nothing to update." when no
refs have updates available which is slightly clearer.

Fixes: #5716

Co-authored-by: Patrick <github.calorie764@passmail.net>
Co-authored-by: bbhtt <bbhtt.zn0i8@slmail.me>
2026-03-02 16:42:31 +00:00
Qiheng He
b37f739721 main: Default to text auth on WSL
Since this bug can be reproduced on Ubuntu, Debian, and Fedora, we should set `FLATPAK_FORCE_TEXT_AUTH=1` for all WSL users instead of ignoring its existence. After all, the so-called `graphical prompt` in the flatpak documentation seems to be something unique to GNOME. `WSL_DISTRO_NAME` and `WSL_INTEROP` are both located at https://github.com/microsoft/WSL/blob/master/src/linux/init/util.h .
2026-02-07 15:17:33 +05:30
Reilly Brogan
9380e0c66c fix: Build with glibc 2.43
Several glibc functions now return a const pointer if the input is a const pointer and a non-const pointer if the input is non-const, causing a build failure.

Fix this by declaring the output pointers as const if they are never modified and for the lone failure where the output is modified instead make the input non-const.
2026-02-02 18:54:08 +05:30
rezky_nightky
bb54916814 fix: cross typos, detail below
What I did
Repository rules / “don’t edit” areas
From CONTRIBUTING.md and subprojects/README.md, subprojects/ contains vendored/submodule/copylib code (bubblewrap, libglnx, dbus-proxy, variant-schema-compiler). I treated subprojects/ as third-party and excluded it from typo fixing.

You already skip po/ (translations) and node_modules/, and I kept those exclusions.

Typos fixed (project-owned files only)
I ran codespell with write mode and exclusions, and fixed the reported typos across:

NEWS
app/…
common/…
doc/…
tests/…
session-helper/…
portal/…
data/…
Then I handled the remaining items individually:

NEWS: thse -> these
common/flatpak-utils-private.h: Thse -> These
app/flatpak-polkit-agent-text-listener.c: identies -> identities
tests/test-auth.sh: Propertly -> Properly
tests/testlibrary.c: remore -> remote
common/flatpak-transaction.c: improved wording to avoid the xwindows typo (X11 window ID)
Added .codespellrc
Created .codespellrc:

skip: node_modules,po,subprojects
ignore-regex: .*(ratatui|Affinitized|affinitized).*
ignore-words-list: nd,ot,THUR,IST,fo,hel,bu
(these were confirmed as legitimate tokens/abbreviations/namespace prefix/test strings in this repo, so they should not be “fixed”)
Verification:

codespell --config .codespellrc . now exits clean.

Signed-off-by: rezky_nightky <with.rezky@gmail.com>
2026-01-21 17:58:19 +00:00
vgdaut
d38343194b install, uninstall: Fail if non-interactive and multiple refs, remotes or installations match 2026-01-15 17:45:39 +00:00
Christian Hergert
c896faae19 app: be selective about when to map font-dirs.xml
If the command calling `flatpak build` has already specified a
font-dirs.xml to map, then mapping in again may break (as exemplified in
Builder and Foundry).

This checks to see if an argument has already been mapped in before doing
so and resolves the issue with Builder/Foundry.

Follow-up to !6138

Fixes: GNOME/gnome-builder#2387
2026-01-13 16:34:55 +00:00
Sabri Ünal
fa4da960e1 typo: Fix URL usages
Url > URL
url > URL
2026-01-05 21:16:15 +05:30
Sabri Ünal
10cf402ea2 i18n: Update two strings
In the following usages, the "Install:" and "Download:" strings were used as a short form
of the "Download Size" and "Installed Size", which makes translation tricky.

Therefore, using the normal forms will be good from the translation side.
2026-01-05 13:51:30 +00:00
Sabri Ünal
5136ef48f8 i18n: Add comments for translators
The string "download" can be both a noun and a verb.

Here, "download" is used as a noun.
2026-01-02 14:37:29 +00:00
Sebastian Wick
6667e1d361 context: Use the new permission system for shares and features
This gives us conditionals for shares and features. So far we have no
use case for this, but the system already exists, it makes the code
simpler, and when we need this in the future, we don't have to wait for
it to roll out.
2025-12-08 19:33:09 +00:00
Owen W. Taylor
404aa33ce1 common: Check signatures when installing OCI images
Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-12-08 19:09:56 +00:00
Owen W. Taylor
841f33e451 app: Add a "signature lookaside" repository configuration
Allow specifying a lookside URL for downloading signatures for
an OCI remote. This can be specified:

 In a .repofile with the SignatureLookaside key
 As the --signature-lookaside option to remote-add/remote-modify
2025-12-08 19:09:56 +00:00
JakobDev
1e52cc62e8 build-bundle: Add the runtime repo to OCI image metadata
At the moment the --runtime-repo flags of flatpak build-bundle export is
ignored when building an OCI image. So an Flatpak OCI registry which
wants to supports a .flatpakref file has no information about the
runtime repo. With this PR the runtime repo gets added as the
org.flatpak.runtime-repo label to the OCI image.

This is currently only metadata to be used by repositories and not
used by flatpak during install.
2025-12-03 14:53:46 +00:00
Sebastian Wick
e4edecdef5 utils-http: Drop libsoup2 support in favor of libcurl
A few years ago there was a very painful attempt at porting from
libsoup2 to libsoup3. Flatpak libsoup3 support never landed and it seems
like a large amount of distros have switched over to libcurl instead.

This commit removes libsoup2 support completely instead of growing
libsoup3 support.

Closes #5915
Closes #4582
2025-11-20 17:40:57 +00:00
Owen W. Taylor
e6b584f85c flatpak-build-bundle: Add --oci-layer-compress=zstd
Add an option to build OCI bundles with zstd compressed layers.

gzip is kept as the default for maximum compatibility:

Ecosystem support:

 distribution/distribution: no explicit support, but works
 quay.io: sinc 2021
 Amazon ECR: supported
 pulp_container: since 2022
 flatpak: since first-OCI supporting version
 tardiff: since first version
2025-11-20 17:30:07 +00:00
Emir SARI
944c0908e1 cli-transaction: improve i18n
- Make percent values translatable

  Various languages use different ways to format the percentage
  values[1], making it translatable will allow a more coherent way to
  display the information.

- Make remaining time abbreviation translatable

  Making this value translatable will allow languages to display the
  seconds abbreviation in their language. This is particulary an issue
  for Turkish, in which hours and seconds start with the same letter, so
  it's not possible to distinguish which is which. We use a second
  letter (sa, sn) to figure it out.

[1] https://en.wikipedia.org/wiki/Percent_sign#Form_and_spacing

Signed-off-by: Emir SARI <emir_sari@icloud.com>
2025-11-20 15:20:59 +00:00
Sebastian Wick
947d4a6ce4 flatpak: Enable progress escape sequence by default
In 4febfb59 ("flatpak: Disable progress escape sequence by default") the
escape sequence has been disabled by default, but we want to enable it
again for 1.18.
2025-11-18 01:19:36 +00:00
Sebastian Wick
8354ee56cf kill: Do not kill pid 0 and embrace races
There are a number of races, and failure conditions which can lead to a
pid of 0 being returned from flatpak_instance_get_child_pid. This would
lead to a whole bunch of things getting killed.

We will skip the instance in those cases now, and retry a few times. We
also notice when the instance just goes away by itself now.

This should make killing more robust, and especially not SIGKILL pid 0.
2025-10-31 12:04:55 +00:00
Georgia Garcia
f61d931da8 common: Fix running_under_sudo check by checking euid
Sudo can be used in several ways other than calling a command with the
root user. For example, one can use -u to run the command as the
specified user, or -g to specify a primary group to run the command
as.

Flatpak adds a check when --user is used to prevent an installation in
the root's directory, for example, but it does it by only checking if
sudo was used. As stated previously, it does not necessarily imply
root, so this patch explicitly checks if the command is being run with
the root user.

Fixes: https://github.com/flatpak/flatpak/issues/5979
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-10-28 13:17:13 +00:00
Sebastian Wick
edac357aad builtins/install: Allow flatpak+https URIs in flatpak install --from
Those schemes are in use by flathub, usually to be handled by an app
store, but we can also handle it directly with `flatpak install`.

Base on an idea from user bbb651 in
https://github.com/flatpak/flatpak/pull/6259.
2025-10-28 12:55:59 +00:00
JakobDev
3544de6251 build-finish: Export AppStream external release metainfo
The appstream docs say:

  Release data may be present directly in a component metainfo file, but
  also optionally be split out into an external metadata file.

  The file must be installed as
  /usr/share/metainfo/releases/%{cid}.releases.xml, where cid is the
  component ID of the component the release information belongs to.

This change allows flatpak build-finish to export those external release
files.

Closes #6057
2025-10-28 10:22:45 +00:00
Sebastian Wick
3e9e68cc5d Support sideload repositories for OCI remotes
For OCI remotes, the existing sideload repository system doesn't
work: identity for OCI remotes is done by manifest digest (disguised
as a fake commit ID internally), instead of by ostree commit, so
we have no way of knowing whether a sideloaded image matches the
summary.

Allow specifying a new form of sideload repository with:

  --sideload-repo=oci:<path>

The desired use case for this is preinstalling Flatpaks during OS
install, and for this, binding the entire repository to a single
collection ID is both inconvenient and not useful, so OCI sideload
repostories don't have a defined collection ID - they just apply to
all OCI remotes. (And, because of this, they are restricted to
the command line.)
2025-10-24 16:27:33 +00:00
Sebastian Wick
f7671ebbc9 dir: Support sideloading from OCI repos/archives
This is implemented in a straightforward way by adding GFile
*sideload_path, FlatpakImageSource *image_source.
2025-10-24 16:27:33 +00:00
Sebastian Wick
0a3c2452c0 flatpak-build: Drop host permissions by default
For some reason, flatpak build always had host permissions set by
default. There really isn't a good reason for this. The build should be
isolated from the host as much as possible by default.
2025-10-13 19:24:50 +00:00
bbhtt
0bf531f44a dir: Add basic OS info to Flatpak-Os-Info header when pulling objects
Fixes https://github.com/flatpak/flatpak/issues/5549
2025-10-13 18:52:55 +00:00
Sebastian Wick
a92c5f686e context: Support condtional permissions for socket and devices
This uses the new FlatpakPermissions API to support the new
commandline options --socket-if= and --device-if=.
2025-10-13 18:31:33 +00:00
Adian Kozlica
4f8b935567 feat: json support for table printer 2025-10-13 13:53:15 +00:00
Sebastian Wick
f760f1b539 run: Add --clear-env option for clearing the outside environment 2025-10-09 18:02:50 +00:00
Kalev Lember
d10e11482d Add initial support for preinstalling flatpaks
This adds new FlatpakTransaction API, and a new top level CLI command to
preinstall flatpaks, that is to install flatpaks that are considered
part of the operating system.

A new drop-in directory /etc/flatpak/preinstall.d/ allows configuring
what apps should be preinstalled, and a new flatpak preinstall command
installs and removes apps based on the current configuration.

A drop-in loupe.preinstall file can look something like this:

[Flatpak Preinstall org.gnome.Loupe]
Branch=stable
IsRuntime=false

The corresponding API is flatpak_transaction_add_sync_preinstalled()
which can be implemented by GUI clients to drive the actual installs
on system startup.

Resolves: https://github.com/flatpak/flatpak/issues/5579
Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-08-26 11:51:07 +00:00
Owen W. Taylor
609f0ce0a1 common: Move delta_url into the FlatpakImageSource
Instead of passing the delta URL along with the image source, when
we create an image source for a remote registry, if we find a delta
URL in the metadata, set it on the FlatpakImageSource for later use.

Centralize duplicated code for creating an image source for a remote
repository based on a summary lookup into one place.
2025-08-25 15:56:20 +00:00
Owen W. Taylor
a460dd5069 image-source: Support oci-archive: image sources
Add support for `oci-archive:` image sources by temporarily
unpacking the archive using libarchive.

Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-08-25 15:56:20 +00:00
Owen W. Taylor
eee21d5a27 builtins/install: Allow direct installation from OCI images
Similar to bundle installs, add:

 flatpak install [--image] docker://registry.example.com/image:latest
 flatpak install [--image] oci:/path/to/image

These is useful for testing purposes and in certain cases when installing
Flatpaks on disconnected systems.
2025-08-25 15:56:20 +00:00
Sebastian Wick
ee9d25dfe2 builtins/install: Create install transaction in common function 2025-08-25 15:56:20 +00:00
Owen W. Taylor
5950438ca7 image-source: Replace flatpak_oci_parse_commit_labels with getters
Instead of having one function with a pile of out arguments in
arbitrary order, add getters to FlatpakImageSource.
2025-08-25 15:56:20 +00:00
Owen W. Taylor
59ad08e78c image-source: Refactor - add FlatpakImageSource type
To avoid passing around combinations of a FlaptakOciRegistry with
repository and digest, add a FlatpakImageSource type.

This also reduces duplicated code where every place that did
this independently retrieved the repository and image config.
2025-08-25 15:56:20 +00:00
Johannes Maibaum
054f4f4a7b flatpak-build: Add empty /run/host/font-dirs.xml
flatpak run writes /run/host/font-dirs.xml, but flatpak build so far
didn't.  This resulted in fontconfig writing:

Fontconfig error: Cannot load config file "/run/host/font-dirs.xml": No such file: /run/host/font-dirs.xml

to the stderr of all processes utilizing fontconfig and run during
flatpak build, as /run/host/font-dirs.xml is included via
/etc/fonts/50-flatpak.conf. This could cause issues for tests run during
building an application, for example.

Closes #6137
2025-08-20 18:24:33 +00:00
yu shuoqi
51452a7bf5 list, uninstall: Add simple output to two commands
Closes: https://github.com/flatpak/flatpak/issues/6197
2025-08-06 11:14:44 +00:00
Chris Williams
8f87b6ea08 permission-reset: Avoid setting unchanged table entries
This reduces the best case (no-op) execution time from ~900 ms to <100
ms on my system.

Closes #5772
2025-02-21 19:14:01 -06:00
Chris Williams
9a61ba7f7d uninstall: Skip in-use runtime check with --unused
confirm_runtime_removal() doesn't know about autoprune-unless
extensions, so it prompts unnecessarily when they're removed by
`flatpak uninstall --unused`. To avoid this, we can simply skip it and
trust flatpak_dir_list_unused_refs().

Closes #5712
Helps #2718
2025-02-21 19:12:46 -06:00
Bartłomiej Piotrowski
050f6e35fe prune: Skip calculating potential freed space in the dry run 2025-02-11 13:00:24 +01:00
Chris Williams
97c922f430 cli-transaction: Don't print fatal transaction error twice
Just clear the line and let the error be printed once in main().

Closes #3400
2025-02-10 14:12:20 -06:00
Chris Williams
402b13e32a search: Enable completion of command-specific options 2025-02-10 14:10:22 -06:00