-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'eero/upgrade-diroid' into 'master'
feat: [NODE-1380] Switch IC-OS to newer FS build tools See merge request dfinity-lab/public/ic!19351
- Loading branch information
Showing
13 changed files
with
148 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
24bbf7e3a37a1de06f55b44b3419a92a929f919ba8e1dacb540255a17de36ad7 | ||
f3527253faea5555085c508e10e98ed276988b1b3cd6e63c249e03318cecb596 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,6 @@ libffi-dev | |
libgmp-dev | ||
|
||
# IC-OS | ||
android-sdk-ext4-utils | ||
cryptsetup-bin | ||
dosfstools | ||
fakeroot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,81 @@ | ||
use std::env; | ||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::io::{self, BufRead, Write}; | ||
use std::os::unix::fs::MetadataExt; | ||
use std::path::PathBuf; | ||
|
||
use walkdir::WalkDir; | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
use walkdir::{DirEntryExt, WalkDir}; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
/// Generate an e2fsdroid fs_config file for a given directory tree | ||
#[derive(Parser)] | ||
struct Args { | ||
/// Fakeroot statefile, to pull ownership from | ||
#[arg(long, required = true)] | ||
fakeroot: PathBuf, | ||
/// Base directory to scan | ||
#[arg(long, required = true)] | ||
input_dir: PathBuf, | ||
/// Output file | ||
#[arg(long, required = true)] | ||
output: PathBuf, | ||
} | ||
|
||
if args.len() != 2 { | ||
panic!("Incorrect arguments!"); | ||
} | ||
fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
|
||
let fakeroot_map = read_fakeroot_state(&args.fakeroot)?; | ||
let mut output = File::create(args.output)?; | ||
|
||
for entry in WalkDir::new(&args.input_dir) { | ||
let entry = entry?; | ||
|
||
for entry in WalkDir::new(&args[1]) { | ||
let entry = entry.unwrap(); | ||
let metadata = entry.metadata()?; | ||
|
||
let metadata = entry.metadata().unwrap(); | ||
println!( | ||
// fakeroot does not track /, so special case this ownership | ||
let (uid, gid) = if entry.path() == args.input_dir { | ||
&(0, 0) | ||
} else { | ||
fakeroot_map.get(&entry.ino()).context(format!( | ||
"fakeroot map does not contain inode: '{}'", | ||
entry.ino() | ||
))? | ||
}; | ||
|
||
writeln!( | ||
&mut output, | ||
"{} {} {} {:o}", | ||
entry.path().strip_prefix(&args[1]).unwrap().display(), | ||
metadata.uid(), | ||
metadata.gid(), | ||
entry.path().strip_prefix(&args.input_dir)?.display(), | ||
uid, | ||
gid, | ||
metadata.mode() | ||
); | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Parse a fakeroot statefile, building a map of inode to uid/gid | ||
fn read_fakeroot_state(path: &PathBuf) -> Result<HashMap<u64, (u32, u32)>> { | ||
let state = File::open(path)?; | ||
|
||
let mut fakeroot_map = HashMap::new(); | ||
for line in io::BufReader::new(state).lines() { | ||
let line = line?; | ||
|
||
let fields: Vec<_> = line.split(',').collect(); | ||
|
||
let ino = fields.iter().find_map(|v| v.strip_prefix("ino=")); | ||
let uid = fields.iter().find_map(|v| v.strip_prefix("uid=")); | ||
let gid = fields.iter().find_map(|v| v.strip_prefix("gid=")); | ||
|
||
let ino = ino.context("fakeroot map invalid, 'ino' not found")?; | ||
let uid = uid.context("fakeroot map invalid, 'uid' not found")?; | ||
let gid = gid.context("fakeroot map invalid, 'gid' not found")?; | ||
|
||
fakeroot_map.insert(ino.parse()?, (uid.parse()?, gid.parse()?)); | ||
} | ||
|
||
Ok(fakeroot_map) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.