From 929486d078811faae4b052e00a98987817a903ed Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:21:51 +0200 Subject: [PATCH] initfs: Replace metadata field on Entry with executable field on EntryKind::File --- initfs/tools/src/lib.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/initfs/tools/src/lib.rs b/initfs/tools/src/lib.rs index 8d01587783..29e3679635 100644 --- a/initfs/tools/src/lib.rs +++ b/initfs/tools/src/lib.rs @@ -1,5 +1,5 @@ use std::convert::{TryFrom, TryInto}; -use std::fs::{DirEntry, File, Metadata, OpenOptions}; +use std::fs::{DirEntry, File, OpenOptions}; use std::io::{prelude::*, SeekFrom}; use std::path::{Path, PathBuf}; @@ -23,7 +23,7 @@ pub const DEFAULT_MAX_SIZE: u64 = 64 * MEBIBYTE; const PAGE_SIZE: u16 = 4096; enum EntryKind { - File(File), + File { file: File, executable: bool }, Dir(Dir), Link(PathBuf), } @@ -31,7 +31,6 @@ enum EntryKind { struct Entry { name: Vec, kind: EntryKind, - metadata: Metadata, } struct Dir { entries: Vec, @@ -101,9 +100,13 @@ fn read_directory(path: &Path, root_path: &Path) -> Result { } else if file_type.is_char_device() { return unsupported_type("character device", &entry); } else if file_type.is_file() { - EntryKind::File(File::open(entry.path()).with_context(|| { - anyhow!("failed to open file `{}`", entry.path().to_string_lossy(),) - })?) + let executable = metadata.permissions().mode() & 0o100 != 0; + EntryKind::File { + file: File::open(entry.path()).with_context(|| { + anyhow!("failed to open file `{}`", entry.path().to_string_lossy(),) + })?, + executable, + } } else if file_type.is_dir() { EntryKind::Dir(read_directory(&entry.path(), root_path)?) } else if file_type.is_symlink() { @@ -139,7 +142,6 @@ fn read_directory(path: &Path, root_path: &Path) -> Result { Ok(Entry { kind: entry_kind, - metadata, name, }) }) @@ -256,11 +258,14 @@ fn allocate_and_write_dir(state: &mut State, dir: &Dir) -> Result { (write_result, initfs::InodeType::Dir) } - EntryKind::File(ref file) => { + EntryKind::File { + ref file, + executable, + } => { let write_result = allocate_and_write_file(state, file) .context("failed to copy file into image")?; - let type_ = if entry.metadata.permissions().mode() & 0o100 != 0 { + let type_ = if executable { initfs::InodeType::ExecutableFile } else { initfs::InodeType::RegularFile