Properly parses the mode parsed from the config into a Rust integer with 'o'. Need to clean up the config logic and move code parsing into logical sections, but otherwise works… barely…
YKRSSHFQEP3O6HC7DOF22ATRMG6Y5SZZHKT6A34YGWFIXQDFGSIQC #type path mode user group age argumentd /run/user 0755 root root 10d -l /tmp/foobar - - - - /dev/null
#type path mode user group age argumentd /tmp/dtmp/testdir 0755 root root 10d -f /tmp/dtmp/testfile 0644 root root 3d -f+ /tmp/dtmp/testtfile 0644 root root 5d -l /tmp/dtmp/testlink - - - - /dev/null
let line: Vec<&str> = line.iter().map(|item| item.as_str()).collect();if line[0].chars().next().unwrap().to_string() == "#" {continue;
if line.len() >= 1 {let line: Vec<&str> = line.iter().map(|item| item.as_str()).collect();if line[0].chars().next().unwrap().to_string() == "#" {continue;}return_config.push(Config {file_type: String::from(line[0]),path: line[1].into(),mode: String::from(line[2]),user: String::from(line[3]),group: String::from(line[4]),age: String::from(line[5]),argument: String::from(line[6]),});
if let config_files = std::fs::read_dir("/usr/lib/tmpfiles.d").unwrap() {for file in config_files {match file {Ok(f) => match parser::parse(&f.path()) {Ok(config) => configs.push(config),
let config_files = std::fs::read_dir("/usr/lib/tmpfiles.d");match config_files {Ok(config_list) => {for file in config_list {match file {Ok(f) => match parser::parse(&f.path()) {Ok(config) => configs.push(config),Err(e) => return Err(e),},
// println!("{:#?}", config);if &line.file_type == "d" {// println!("{:#?}", line);match builder.recursive(true).mode(line.mode.parse::<u32>().unwrap()).create(&line.path.as_os_str()){Ok(k) => println!("Created path: {:#?}", &line.path.as_os_str()),Err(e) => {println!("Failed");return Err(e)},
let mut mode: u32;match line.mode.as_str() {"0755" => mode = 0o755,"755" => mode = 0o755,"1755" => mode = 1755,"0644" => mode = 0o644,"644" => mode = 0o644,"1644" => mode = 1644,_ => todo!(),}match line.file_type.as_str() {"f" => {match OpenOptions::new().create(true).mode(mode) // .mode(line.mode.parse::<u32>().unwrap()).open(&line.path.as_os_str()){Ok(k) => println!("Created file: {:#?}", &line.path.as_os_str()),Err(e) => {println!("Failed to create {:#?} with reason {}!",&line.path.as_os_str(),e);println!("Mode: {}", line.mode.parse::<u32>().unwrap());return Err(e);}}}"f+" => {match OpenOptions::new().create(true).truncate(true).mode(mode).open(&line.path.as_os_str()){Ok(k) => println!("Created file: {:#?} with truncation",&line.path.as_os_str()),Err(e) => {println!("Failed to create {:#?}!", &line.path.as_os_str());return Err(e);}}
"d" => match build_dir(&line.path, mode) {Ok(k) => println!("Created path {:#?} with mode {}",&line.path.as_os_str(),mode),Err(e) => {println!("Failed to create {:#?} with mode {} with error {}!",&line.path.as_os_str(),mode,e);return Err(e.into());}},_ => eprintln!("ERROR: File type \"{}\" is not implemented.",line.file_type),
nix = { version = "0.30.1", features = ["fs"], default-features = false }
name = "cfg-if"version = "1.0.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"[[package]]name = "cfg_aliases"version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"[[package]]
name = "libc"version = "0.2.174"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"[[package]]name = "nix"version = "0.30.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"dependencies = ["bitflags","cfg-if","cfg_aliases","libc",][[package]]