From: Demi Marie Obenour <demiobenour@gmail.com>
To: Spectrum OS Development <devel@spectrum-os.org>
Cc: Demi Marie Obenour <demiobenour@gmail.com>, Alyssa Ross <hi@alyssa.is>
Subject: [PATCH 3/4] tools/mount-flatpak: Move more code to mount_commit()
Date: Fri, 05 Dec 2025 11:22:03 -0500 [thread overview]
Message-ID: <20251205-better-mount-flatpak-v1-3-229a81366091@gmail.com> (raw)
In-Reply-To: <20251205-better-mount-flatpak-v1-0-229a81366091@gmail.com>
Make mount_commit() responsible for not only mounting the commit tree,
but also for opening the source subdirectory and creating the
destination subdirectory.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
tools/mount-flatpak/src/main.rs | 82 ++++++++++++++++++++---------------------
1 file changed, 39 insertions(+), 43 deletions(-)
diff --git a/tools/mount-flatpak/src/main.rs b/tools/mount-flatpak/src/main.rs
index 68a1f6ea308387a9471682c927d3a71439ab69e4..b40402b1b15729bdd2228025850efe8d87a48e3b 100644
--- a/tools/mount-flatpak/src/main.rs
+++ b/tools/mount-flatpak/src/main.rs
@@ -43,7 +43,7 @@ mod metadata;
use std::borrow::Cow;
use std::env::{ArgsOs, args_os};
-use std::ffi::OsStr;
+use std::ffi::{OsStr, OsString};
use std::io;
use std::os::unix::prelude::*;
use std::path::{Path, PathBuf};
@@ -67,12 +67,21 @@ fn open_subdir(root: &Root, path: &Path) -> Result<Root, Error> {
}
fn mount_commit(
- source_commit: &dyn AsFd,
+ source_installation: &Root,
+ source_path: &Path,
target_installation: &Root,
- path: &Path,
-) -> Result<(), String> {
+ target_path: &Path,
+ kind: &str,
+) -> Result<(Root, OsString), String> {
+ let source_commit_parent_dir = open_subdir(source_installation, source_path)
+ .map_err(|e| format!("opening source {kind} commit parent: {e}"))?;
+ let commit = source_commit_parent_dir
+ .readlink("active")
+ .map_err(|e| format!("reading active {kind} commit: {e}"))?;
+ let source_root = open_subdir(&source_commit_parent_dir, &commit)
+ .map_err(|e| format!("opening source {kind} commit: {e}"))?;
let source_commit_tree = open_tree(
- source_commit,
+ &source_root,
"",
OpenTreeFlags::AT_EMPTY_PATH
| OpenTreeFlags::OPEN_TREE_CLONE
@@ -81,7 +90,7 @@ fn mount_commit(
)
.map_err(|e| format!("cloning source commit tree: {e}"))?;
let target_commit_dir = target_installation
- .mkdir_all(path, &PermissionsExt::from_mode(0o700))
+ .mkdir_all(target_path, &PermissionsExt::from_mode(0o700))
.map_err(|e| format!("creating target commit directory: {e}"))?;
move_mount(
source_commit_tree,
@@ -90,7 +99,8 @@ fn mount_commit(
"",
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH | MoveMountFlags::MOVE_MOUNT_T_EMPTY_PATH,
)
- .map_err(|e| format!("mounting commit: {e}"))
+ .map_err(|e| format!("mounting commit: {e}"))?;
+ Ok((source_root, commit.as_os_str().to_owned()))
}
fn run(mut args: ArgsOs) -> Result<(), String> {
@@ -129,11 +139,13 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
let target_installation_dir =
Root::from_fd(target_installation_dir).with_resolver_flags(ResolverFlags::NO_SYMLINKS);
- let mut full_app_path = installation_path.join("app");
- full_app_path.push(&app);
- full_app_path.push("current");
- let arch_and_branch = source_installation_dir
- .readlink(&full_app_path)
+ let mut app_path = PathBuf::new();
+ app_path.push("app");
+ app_path.push(&app);
+ let source_app_dir = open_subdir(&source_installation_dir, &app_path)
+ .map_err(|e| format!("opening source flatpak app: {e}"))?;
+ let arch_and_branch = source_app_dir
+ .readlink("current")
.map_err(|e| format!("reading current app arch and branch: {e}"))?;
let mut components = arch_and_branch.components();
let arch = components.next().unwrap().as_os_str();
@@ -142,21 +154,16 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
return Err("can't infer branch from \"current\" link".to_string());
}
- full_app_path.pop();
- full_app_path.push(&arch_and_branch);
- full_app_path.push("active");
- let commit = source_installation_dir
- .readlink(&full_app_path)
- .map_err(|e| format!("reading active app commit: {e}"))?
- .into_os_string();
-
- full_app_path.pop();
- full_app_path.push(&commit);
- let source_app_dir = open_subdir(&source_installation_dir, &full_app_path)
- .map_err(|e| format!("opening source app directory: {e}"))?;
+ let (source_commit_dir, commit) = mount_commit(
+ &source_app_dir,
+ &app_path.join(&arch_and_branch),
+ &target_installation_dir,
+ &arch_and_branch,
+ "app",
+ )?;
- let metadata = source_installation_dir
- .resolve(&full_app_path.join("metadata"))
+ let metadata = source_commit_dir
+ .resolve("metadata")
.map_err(|e| format!("resolving app metadata: {e}"))?;
let metadata_stat =
@@ -172,25 +179,14 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
let runtime =
extract_runtime(metadata).map_err(|e| format!("reading runtime from metadata: {e}"))?;
+ let runtime_path = Path::new("runtime").join(runtime);
- let mut full_runtime_path = installation_path.join("runtime");
- full_runtime_path.push(runtime);
- full_runtime_path.push("active");
- let runtime_commit = source_installation_dir
- .readlink(&full_runtime_path)
- .map_err(|e| format!("reading active runtime commit: {e}"))?
- .into_os_string();
-
- full_runtime_path.pop();
- full_runtime_path.push(&runtime_commit);
- let source_runtime_dir = open_subdir(&source_installation_dir, &full_runtime_path)
- .map_err(|e| format!("opening source runtime directory: {e}"))?;
-
- mount_commit(&source_app_dir, &target_installation_dir, &full_app_path)?;
- mount_commit(
- &source_runtime_dir,
+ let (_, runtime_commit) = mount_commit(
+ &source_installation_dir,
+ &runtime_path,
&target_installation_dir,
- &full_runtime_path,
+ &runtime_path,
+ "runtime",
)?;
target_installation_dir
--
2.52.0
next prev parent reply other threads:[~2025-12-05 16:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 16:22 [PATCH 0/4] Improve mount-flatpak Demi Marie Obenour
2025-12-05 16:22 ` [PATCH 1/4] tools: Use with_resolver_flags instead of mutation Demi Marie Obenour
2026-01-07 13:07 ` Alyssa Ross
2025-12-05 16:22 ` [PATCH 2/4] tools/mount-flatpak: Create utility function to open a subdirectory Demi Marie Obenour
2025-12-22 14:31 ` Alyssa Ross
2025-12-22 18:31 ` Demi Marie Obenour
2025-12-05 16:22 ` Demi Marie Obenour [this message]
2025-12-05 16:22 ` [PATCH 4/4] tools/mount-flatpak: Reasonableness checks on application IDs and paths Demi Marie Obenour
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251205-better-mount-flatpak-v1-3-229a81366091@gmail.com \
--to=demiobenour@gmail.com \
--cc=devel@spectrum-os.org \
--cc=hi@alyssa.is \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).