patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 039841651bbe6ae0547d2338a90fcac1203e55df 1525 bytes (raw)
name: tools/mount-flatpak/metadata.rs 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2025 Alyssa Ross <hi@alyssa.is>

mod keyfile;

use std::env::args_os;
use std::ffi::OsString;
use std::fs::File;
use std::io::{read_to_string, stderr, Write};
use std::os::fd::OwnedFd;
use std::os::unix::prelude::*;
use std::process::exit;

use keyfile::parse;

fn extract_runtime(mut metadata: File) -> Result<String, String> {
    let metadata = read_to_string(&mut metadata).map_err(|e| e.to_string())?;
    let group = parse(&metadata).map_err(|e| e.to_string())?;
    let application = group
        .get("Application")
        .ok_or_else(|| "Application group missing".to_string())?;
    Ok(application
        .get("runtime")
        .ok_or_else(|| "runtime property missing".to_string())?
        .clone())
}

// SAFETY: we do not expect "extract_runtime" to collide with another symbol.
#[unsafe(export_name = "extract_runtime")]
pub extern "C" fn extract_runtime_c(metadata: OwnedFd, out: &mut [u8; 256]) {
    let error = match extract_runtime(metadata.into()) {
        Err(e) => e,
        Ok(runtime) if runtime.len() >= out.len() => "runtime name too long".to_string(),
        Ok(runtime) => {
            out[..runtime.len()].copy_from_slice(runtime.as_bytes());
            out[runtime.len()] = 0;
            return;
        }
    };

    let prog_name = args_os()
        .next()
        .unwrap_or_else(|| OsString::from("mount-flatpak"));
    stderr().write_all(prog_name.as_bytes()).unwrap();
    eprintln!(": {error}");
    exit(1);
}

debug log:

solving 0398416 ...
found 0398416 in https://inbox.spectrum-os.org/spectrum-devel/20251113120452.65711-1-hi@alyssa.is/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20251113120452.65711-1-hi@alyssa.is/
diff --git a/tools/mount-flatpak/metadata.rs b/tools/mount-flatpak/metadata.rs
new file mode 100644
index 0000000..0398416

Checking patch tools/mount-flatpak/metadata.rs...
Applied patch tools/mount-flatpak/metadata.rs cleanly.

index at:
100644 039841651bbe6ae0547d2338a90fcac1203e55df	tools/mount-flatpak/metadata.rs

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).