Skip to content

Support installing files from file sources#711

Draft
bbhtt wants to merge 1 commit intomainfrom
bbhtt/file-install
Draft

Support installing files from file sources#711
bbhtt wants to merge 1 commit intomainfrom
bbhtt/file-install

Conversation

@bbhtt
Copy link
Contributor

@bbhtt bbhtt commented Mar 8, 2026

This adds a new install stage to BuilderSourceFile that copies files to
a specified directory within the appdir after post-install for
sources that have opted into using it (currently only the file source
and no-op for everyone else).

Additionally, the file source now has a install-dir and install-mode
property. The install-dir property assumes the install location
is relative to FLATPAK_DEST. If the destination file already exists, the
install is skipped with a warning. If install-mode is specified as a
valid octal permission string, the permissions are applied on the file
otherwise the file retains its original permissions.

Fixes: #54

@bbhtt bbhtt force-pushed the bbhtt/file-install branch 2 times, most recently from 31d9506 to 3fb254a Compare March 8, 2026 12:12
This adds a new install stage to BuilderSourceFile that copies files to
a specified directory within the appdir after post-install for
sources that have opted into using it (currently only the file source
and no-op for everyone else).

Additionally, the file source now has a install-dir and install-mode
property. The install-dir property assumes the install location
is relative to FLATPAK_DEST. If the destination file already exists, the
install is skipped with a warning. If install-mode is specified as a
valid octal permission string, the permissions are applied on the file
otherwise the file retains its original permissions.

Fixes: #54
@bbhtt bbhtt force-pushed the bbhtt/file-install branch from 3fb254a to 1b22657 Compare March 8, 2026 12:20
@bbhtt bbhtt added this to the 1.5.0 milestone Mar 9, 2026
g_printerr ("Warning: %s already exists, skipping install\n", dst_path);
else
{
if (!g_file_copy (src, dst, G_FILE_COPY_NOFOLLOW_SYMLINKS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU this is executed in the host context and dst can point to arbitrary locations on the filesystem. You really have to make sure that dst points somewhere inside dest_dir. This is harder than it sounds because even if you ensure there are no ".." in self->install_dir, there might be symlinks anywhere in the build-controlled path (and they do get followed even if you use G_FILE_COPY_NOFOLLOW_SYMLINKS; they only care about the last element in the path).

I think we have a very similar problem with the LICENSE file code (i.e. you can copy certain files from the host system to the build output).

The solution is the use something like openat2/chase (https://gitlab.gnome.org/GNOME/libglnx/-/merge_requests/64).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is indeed executed in host context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh, builder_migrate_locale_dirs also got this wrong already. I'm wondering if people assume that flatpak-builder is secure to run on untrusted content, because it certainly doesn't look like it is.

@bbhtt bbhtt marked this pull request as draft March 10, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a more packager-friendly way of installing appdata files

2 participants