patches and low-level development discussion
 help / color / mirror / code / Atom feed
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 2/4] tools/mount-flatpak: Create utility function to open a subdirectory
Date: Fri, 05 Dec 2025 11:22:02 -0500	[thread overview]
Message-ID: <20251205-better-mount-flatpak-v1-2-229a81366091@gmail.com> (raw)
In-Reply-To: <20251205-better-mount-flatpak-v1-0-229a81366091@gmail.com>

This rejects non-directories where a directory is expected.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
 tools/mount-flatpak/src/main.rs | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/mount-flatpak/src/main.rs b/tools/mount-flatpak/src/main.rs
index dca42e5007e52b24c9a4b6940d5667f770a64bd0..68a1f6ea308387a9471682c927d3a71439ab69e4 100644
--- a/tools/mount-flatpak/src/main.rs
+++ b/tools/mount-flatpak/src/main.rs
@@ -49,8 +49,8 @@ use std::os::unix::prelude::*;
 use std::path::{Path, PathBuf};
 use std::process::exit;
 
-use pathrs::Root;
 use pathrs::flags::{OpenFlags, ResolverFlags};
+use pathrs::{Root, error::Error};
 use rustix::fs::{CWD, FileType, fstat};
 use rustix::mount::{MoveMountFlags, OpenTreeFlags, move_mount, open_tree};
 
@@ -61,6 +61,11 @@ fn ex_usage() -> ! {
     exit(1);
 }
 
+fn open_subdir(root: &Root, path: &Path) -> Result<Root, Error> {
+    root.open_subpath(path, OpenFlags::O_PATH | OpenFlags::O_DIRECTORY)
+        .map(|f| Root::from_fd(f).with_resolver_flags(ResolverFlags::NO_SYMLINKS))
+}
+
 fn mount_commit(
     source_commit: &dyn AsFd,
     target_installation: &Root,
@@ -106,11 +111,8 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
         .map_err(|e| format!("opening user data partition: {e}"))?
         .with_resolver_flags(ResolverFlags::NO_SYMLINKS);
 
-    let source_installation_dir = user_data
-        .open_subpath(&installation_path, OpenFlags::O_PATH)
-        .map(Root::from_fd)
-        .map_err(|e| format!("opening source flatpak installation: {e}"))?
-        .with_resolver_flags(ResolverFlags::NO_SYMLINKS);
+    let source_installation_dir = open_subdir(&user_data, &installation_path)
+        .map_err(|e| format!("opening source flatpak installation: {e}"))?;
 
     std::fs::create_dir("flatpak")
         .map_err(|e| format!("creating target flatpak installation: {e}"))?;
@@ -150,12 +152,11 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
 
     full_app_path.pop();
     full_app_path.push(&commit);
-    let source_app_dir = source_installation_dir
-        .resolve(&full_app_path)
+    let source_app_dir = open_subdir(&source_installation_dir, &full_app_path)
         .map_err(|e| format!("opening source app directory: {e}"))?;
 
     let metadata = source_installation_dir
-        .resolve(full_app_path.join("metadata"))
+        .resolve(&full_app_path.join("metadata"))
         .map_err(|e| format!("resolving app metadata: {e}"))?;
 
     let metadata_stat =
@@ -182,8 +183,7 @@ fn run(mut args: ArgsOs) -> Result<(), String> {
 
     full_runtime_path.pop();
     full_runtime_path.push(&runtime_commit);
-    let source_runtime_dir = source_installation_dir
-        .resolve(&full_runtime_path)
+    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)?;

-- 
2.52.0


  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 ` Demi Marie Obenour [this message]
2025-12-22 14:31   ` [PATCH 2/4] tools/mount-flatpak: Create utility function to open a subdirectory Alyssa Ross
2025-12-22 18:31     ` Demi Marie Obenour
2025-12-05 16:22 ` [PATCH 3/4] tools/mount-flatpak: Move more code to mount_commit() Demi Marie Obenour
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-2-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).