Commit Graph

1146 Commits

Author SHA1 Message Date
Alexander Larsson
54e958d202 Transaction: Use flatpak_dir_resolve_p2p_refs to resolve p2p refs
This allows us to resolve as many operations as possible in parallel
which is much faster than doing the p2p queries for each potential
update.

Fixes #1592

Closes: #1796
Approved by: alexlarsson
2018-06-20 09:10:31 +00:00
Alexander Larsson
c647c315ef dir: Add flatpak_dir_resolve_p2p_refs()
This takes a list of refs + remotes and optional commit, all
which need to be p2p (i.e. have collection-id != NULL) refs, and
uses the p2p API to resolve the refs to the latest available commit
it and the matching metadata for that version.

It does this by doing a find_remotes() and then a pull_from_remotes
with PULL_FLAG_COMMIT_ONLY and then extracting the metadata
from the commit object.

We also do some checking before pulling so that if we have the latest
reported commit already available locally then we don't pull anything
for that ref (instead resolving to the locally available metadata).

We always pull to a child repo so that we have write-rights even as a
user (in the system case) and so we can properly clean up the temporary
results.

Note, this unconditionally uses the p2p APIs, and it relies on the latest
ostree master which has a fix that allows us to read the latest refs from
the transaction.

Closes: #1796
Approved by: alexlarsson
2018-06-20 09:10:31 +00:00
Alexander Larsson
d15fe7f5b2 dir: Break out flatpak_dir_create_child_repo
This is broken out of latpak_dir_create_system_child_repo and now
allows you to create user child repos too.

Closes: #1796
Approved by: alexlarsson
2018-06-20 09:10:31 +00:00
Alexander Larsson
9901ce875f dir: Never fsync child repos
There is no need to force a fsync after pulling into the child repo,
because we will anyway copy/verify it into the system repo. It is
never used for stable storage.

This makes system installation faster.

Closes: #1808
Approved by: alexlarsson
2018-06-20 08:40:28 +00:00
Matthew Leeds
71d4539d5d transaction: Fix wording in docs for "ready" signal
Closes: #1802
Approved by: alexlarsson
2018-06-20 08:27:19 +00:00
Matthew Leeds
1a240ac686 transaction: Fix g-ir-scanner warnings
Closes: #1801
Approved by: alexlarsson
2018-06-20 07:52:55 +00:00
Matthew Leeds
4e73b51a0b dir: Avoid unnecessary fetches of ostree-metadata
This commit removes fetches of ostree-metadata from
flatpak_dir_install() and flatpak_dir_update(), which both pull it into
the child repo when doing system-helper deployments. Both functions have
a FlatpakRemoteState object passed in and when that is initialized,
_flatpak_dir_fetch_remote_state_metadata_branch() pulls and deploys
ostree-metadata so it can be queried against for repo metadata and
served onto LAN and USB peers. So there's no need to pull it again here.

The issue of resolving a ref and its metadata atomically remains, but
that will be addressed by https://github.com/flatpak/flatpak/pull/1796.

Closes: #1806
Approved by: alexlarsson
2018-06-20 07:40:21 +00:00
Alexander Larsson
491d174879 Make p2p build non-optional
Closes: #1800
Approved by: alexlarsson
2018-06-19 18:10:56 +00:00
Alexander Larsson
065053775b run: Never inherit permissions from the runtime
We want inherit environment variables, but not actual permissions,
those need to be requested by the app only.

Closes: #1799
Approved by: alexlarsson
2018-06-19 14:54:22 +00:00
Alexander Larsson
23f1df8a5b Transaction: Add operation getters for metadata and old_metadata
Closes: #1799
Approved by: alexlarsson
2018-06-19 14:54:22 +00:00
Alexander Larsson
35615cbe54 Transaction: Track old metadata (for updates)
Closes: #1799
Approved by: alexlarsson
2018-06-19 14:54:22 +00:00
Alexander Larsson
db305f7287 Transaction: Keep metadata as GBytes
This makes it more easy to expose these without constantly
duplicating the memory.

Closes: #1799
Approved by: alexlarsson
2018-06-19 14:54:22 +00:00
Alexander Larsson
0515e49140 transaction: Add APIs to set dependency sources
Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
5e8b5e5319 Transaction: Use flatpakTransactionOperation in signals
This changes the signals to use a FlatpakTransactionOperation
argument instead of a bunch of arguments in the signal, making
this easier to extend in the future.

This is an API break, but nobody is using this API yet, and it
was only available in one unstable release.

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
462204462e Transaction: Add flatpak_transaction_operation_get_bundle_path
This is to match what you can get from the new_operation arguments.

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
f9ad4e3eee transaction: Add ready signal
This signal is emitted after all the added operations and their dependencies
are resolved and we have the full list of things that will be
done as part of the transaction. At this point you can call
flatpak_transaction_get_operations() and decide if you want to
continue with the operation.

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
4c8f788ecd transaction: Make FlatpakTransactionOperation a (public) GObject
Only the type itself is exposed atm, not members, etc.

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
16c097ce7a transaction: Rename FlatpakTransactionOp to FlatpakTransactionOperation
This is in preparation for exposing it a bit publically

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Alexander Larsson
79d43a3c1a transaction: Drop the internal FlatpakTransactionOpKind type
Instead use FlatpakTransactionOperationType internally too,
but extend it with a INSTALL_OR_UPDATE value which is not public.

Closes: #1797
Approved by: alexlarsson
2018-06-19 08:30:21 +00:00
Joonas Sarajärvi
59ecad0f29 Add ssh-auth socket support
SSH authentication sockets can be placed in a number of places, so it
is difficult for applications to just mount a fixed directory or
directories, hoping that SSH_AUTH_SOCK points somewhere inside the
mounted content.

Closes: #1764
Approved by: alexlarsson
2018-06-19 07:11:36 +00:00
Alexander Larsson
b6d63eaa9a Remove unused variable
Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:29 +00:00
Alexander Larsson
66eee3c2c7 Transaction: Change how dependencies are resolved
Instead of resolving dependencies when adding refs to the list we make
adding refs trivial, and then add a dependency-resolving and ordering
phase to the start of flatpak_transaction_run().

Instead of resolving dependencies for each ref by itself this means
that we have a long list of refs we can work on. For the moment this
isn't really used, but it will later allow us to be much more
efficient in the p2p codepath because we can hand over a lot of refs
in a single p2p operation.

There are some complexities, for instance, we don't know initially
which the final refs will be, because the dependency resolving will
add new ones, yet we must still start with some operation.

The way this works is by repeated stages:

 * Resolve the operatations for all the initially specified
   refs. Resolve means doing i/o to determine the latest available
   commit id, and the corresponding metadata for that commit.

 * Add dependencies for all resolved ops, this typically means looking
   at the apps and finding which runtime they need, and then finding a
   runtime to install or update.

 * Resolve all new refs, meaning we now load the metadata for the
   runtime dependencies we added before.

 * Add related refs for all resolved ops, i.e. extensions for apps
   and runtimes. These are marked for install/update as needed.

 * Resolve the final refs.

Now we have a full list of things that we need to install or update,
and for each the commit id and the corresponding metadata. We can at
this point:

 * Verify that the metadata is valid for this version of flatpak
 * Verify that the metadata permissions are not greater than the
   previous version on updates (confirm if so).
 * Guarantee that the above verification will be correct becase
   we resolved each operation to a particular commit it that we
   will pull.
 * Quickly decide which update operations to skip because they
   are no-ops (same as installed version).

There are also some complexities wrt operation ordering. Previously
we decided the ordering when emitting the dependencies, but now
we can't do that since the dependencies are added in non-ordered chunks.
Instead we add some dependency information during the dependency
gathering and do a topological sort at the end.

This is the first step towards a better transaction handling, but here
are still some things left to do:

 * resolve_ops() calls flatpak_dir_find_latest_rev() for each
   operation, which is fine in the normal case as it just looks
   at the summary cached in the RemoteState. However in the p2p
   case it is very inefficient. Now that we have a chunk of
   refs we could resolve in parallel we should instead do a
   single find_remotes() + pull_remotes(COMMITS_ONLY) operation which
   will be much faster.
 * In the p2p case we're still using the metadata from the ostree-metadata
   branch, which may not be the same as the version we will actually be
   pulling. The above COMMITS_ONLY pull operation will allow us to instead
   read the metadata from the real commit objects (which we're guaranteed
   to actually get due to us locking down the commit id when pulling).
 * Even in the non-p2p case we get the wrong metadata when doing an
   explicit downgrade (update --commit=...) because we're using the
   metadata from the summary which only applies to the latest commit.
   This needs to be changed to also pull the commit object.
 * After resolve, but before pulling the full ref we are not currently
   doing metadata permission verification (vs last installed version)
   to see if new permissions need to be requested. This needs to be
   added. We could also let the user pass in pre-acked permissions so
   that a UI can show permissions ahead of time and then avoid
   confirming them again.

Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:29 +00:00
Alexander Larsson
bdbd4d15e2 dir: Split flatpak_dir_find_local/remote_related()
These are split into two, one that loads the metadata and one
that works on the pre-loaded GKeyFile.

This changes no behaviour, but we will later use the split out
functions from FlatpakTransaction when we already have the
metadata loaded.

Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:29 +00:00
Alexander Larsson
641e416280 dir: Export flatpak_dir_find_latest_rev
Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:29 +00:00
Alexander Larsson
0a6f676161 dir: Split flatpak_dir_check_for_update
This splits out the part that extracts the current commit id
from the code that sees if given a particular commit id we need
to update.

Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:29 +00:00
Alexander Larsson
6459a13b2a transaction: Extract commit when adding bundle
This way we know ahead of time what we're going to be installing.

Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:28 +00:00
Alexander Larsson
6a73c26003 flatpak_dir_read_latest_commit: Also return commit id
Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:28 +00:00
Alexander Larsson
d4a476711f transaction: Avoid some duplicated code
This doesn't change any behaviour, but it avoids duplicating
shared code.

Closes: #1787
Approved by: alexlarsson
2018-06-18 08:11:28 +00:00
Alexander Larsson
854be2430e transaction: Use g_message, it g_warning for warnings
g_warning is fatal in the test-suite, breaking tests when p2p is
enabled.
2018-06-13 17:09:43 +02:00
Alexander Larsson
a59fa5c1af portals: By default, only allow portal calls, not broadcasts
No portal is currently using broadcasts, but we want to eventually use
them in dconf. But when doing that they can't be sent to all instances
but rather limited by the sender (dconfd). The exact way this will work
is still unclear, but to pave the way for this we start by defaulting
to not delivering any broadcasts.

Closes: #1689
Approved by: alexlarsson
2018-06-11 14:31:27 +00:00
Alexander Larsson
679248254a run: Add flatpak instance id directory
Each flatpak instance gets a (random uint32) identifier which is
unique during the runtime of the instance. Additionally there is a
directory created in $XDR_RUN_DIR/.flatpak/$id which is writable on
the host, but read-only bind-mounted into the sandbox. Services (like
dconf which this targets) can use this to pass file data to the
sandbox instance.

We use locks on a file in the instance directory to ensure that we
can clean up unused directories.

The container id is also put in the .flatpak-info file so that
portals can know where the instance directory is.

Closes: #1689
Approved by: alexlarsson
2018-06-11 14:31:27 +00:00
Alexander Larsson
ae58744b10 appstream: Allow multiple components per app
Some apps (like libreoffice) has multiple sup-apps, so we allow them to have multiple
appstream components (as well as e.g. multiple desktop files).

Fixes #1749

Closes: #1778
Approved by: alexlarsson
2018-06-11 10:00:17 +00:00
Alexander Larsson
f37396b2de uninstall --unused: Fix handling of autoprune-unless
We were doing autoprune-if instead, which is the opposite
of what we want.

Fixes #1766

Closes: #1777
Approved by: alexlarsson
2018-06-11 09:50:25 +00:00
Alexander Larsson
7311eff800 Fix regression with --own=name
We deleted the "filtered" policy, but forgot to delete it in one place.

This fixes https://github.com/flatpak/flatpak/issues/1761
2018-06-08 14:39:35 +02:00
Alexander Larsson
66b2ff40f7 run: Support accessing host trusted certificates
If p11-kit server is installed on the host, we spawn a copy of this, forwarding the access to the
p11-kit trust module in a read-only way.

We then (if the above worked) bind mount the socket as /run/user/$UID/p11-kit/pkcs11 in the sandbox,
which is the default socket path for the p11-kit-client module.

We also add a configuration file in /etc/pkcs11/modules/p11-kit-trust.module that makes the trust
module actually load the client module instead. This means applications automatically switch
to using the host certs for trust if possible, and use the runtime ca-certificates otherwise.

Additionally we add a config file that always disables pkcs user
config merging, because pkcs11 modules on the host are unlikely to work in a random runtime.

Closes: #1757
Approved by: alexlarsson
2018-06-07 12:25:21 +00:00
Alexander Larsson
b4bb890516 session-helper: Add new more generic helper start method
This does the same as RequestMonitor, but returns the status via a
a{sv} so that its more extensible.

Closes: #1757
Approved by: alexlarsson
2018-06-07 12:25:21 +00:00
Alexander Larsson
df3a0c444b deploy: Do required-version check on deploy too
We only checked this in transaction. This is now the recommended way to installation
via libflatpak too, but if you use the old API this check also ensures that
installation fails if the required version is too old.

Also, we add a specific error code for this so callers can check for it.

Fixes https://github.com/flatpak/flatpak/issues/881

Closes: #1755
Approved by: alexlarsson
2018-06-04 13:30:00 +00:00
Philip Withnall
ebb9baaeac common/installation: Fix indentation in a block
This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1736
Approved by: alexlarsson
2018-06-04 12:22:30 +00:00
Philip Withnall
441fe25255 all: Use GMainContextPopDefault when handling thread defaults
Simplify some of the return logic when handling pushing/popping the
thread default main context by using g_autoptr(GMainContextPopDefault).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1736
Approved by: alexlarsson
2018-06-04 12:22:30 +00:00
Alexander Larsson
a7ea6844d8 Add new extension key autoprune-unless and propagate it to related refs
The idea is for e.g. the gl extension to have
 download-if=active-gl-driver
 autoprune-unless=active-gl-driver

And then we can automatically find and uninstall unused gl drivers.

Closes: #1754
Approved by: alexlarsson
2018-06-04 12:08:59 +00:00
Alexander Larsson
e3559ddd41 flatpak_dir_find_local_related: Fix handling of subdir extensions
We were not correctly handling the partial refs that ostree_repo_list_refs()
returned, instead assuming they were full refs.

Closes: #1754
Approved by: alexlarsson
2018-06-04 12:08:59 +00:00
Alexander Larsson
3134512111 transaction: Reorder uninstalls so apps come before the runtimes they depend on
Otherwise we will fail if we uninstall "runtime app".

Closes: #1750
Approved by: alexlarsson
2018-06-01 15:45:08 +00:00
Alexander Larsson
de5a713336 uninstall: Don't allow uninstalling a runtime with apps that need it
Closes: #1750
Approved by: alexlarsson
2018-06-01 15:45:08 +00:00
Alexander Larsson
518da832ee Deploy: Store runtime dependencies in deploy data
For applications, we extract the name of the runtime it uses
so that we quickly can look up dependencies.

Closes: #1750
Approved by: alexlarsson
2018-06-01 15:45:08 +00:00
Alexander Larsson
3e47247425 Batch running triggers
This moves the triggers from out of flatpak_install/update/uninstall
and instead calls them manually at all the sites that call this.

This allows FlatpakTransaction to only run the triggers once for the
entire operation.

Closes: #1743
Approved by: alexlarsson
2018-06-01 11:41:56 +00:00
Alexander Larsson
715cc173ef Transactions: Add uninstall operation and handle no-pull correctly
In the no-pull case and when uninstalling, we never want to do any network
i/o for e.g. detecting depenedencies.

Closes: #1744
Approved by: alexlarsson
2018-06-01 10:59:14 +00:00
Alexander Larsson
f93886cb65 dir: Add flatpak_dir_get_remote_state_local_only
This does no network i/o and just keeps track of remote name
and collection id. This can be used for no-pull transactions.

Closes: #1744
Approved by: alexlarsson
2018-06-01 10:59:14 +00:00
Alexander Larsson
e7c9347b49 dir: Add flatpak_dir_read_latest_commit
This reads the current commit for a ref in the local repo.
This can be used e.g. to get at the metadata for an already pulled ref.

Closes: #1744
Approved by: alexlarsson
2018-06-01 10:59:14 +00:00
Alexander Larsson
f52d90635e dir: flatpak_dir_search_for_local_dependency
This is the same as flatpak_dir_search_for_dependency, but it looks only in the local
repo for already pulled dependencies. This is useful if you're in no-pull mode.

Closes: #1744
Approved by: alexlarsson
2018-06-01 10:59:14 +00:00
Alexander Larsson
ffe1b7e349 Make various operation work without a system installation
This makes info, list, remotes, and search work if there is no
system flatpak repo. Before it failed with EPERM.

Closes: #1742
Approved by: alexlarsson
2018-05-31 19:28:16 +00:00