mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
Fixup Dir regex
This commit is contained in:
parent
16069b8792
commit
e0138ad759
3 changed files with 46 additions and 33 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libips"
|
name = "libips"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Till Wegmueller <toasterson@gmail.com>"]
|
authors = ["Till Wegmueller <till.wegmueller@openflowlabs.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
||||||
|
|
@ -174,18 +174,29 @@ fn determine_action_kind(line: &str) -> ActionKind {
|
||||||
|
|
||||||
fn parse_dir_action(line: String, line_nr: usize) -> Result<Dir, Error> {
|
fn parse_dir_action(line: String, line_nr: usize) -> Result<Dir, Error> {
|
||||||
let mut act = Dir::default();
|
let mut act = Dir::default();
|
||||||
let regex = Regex::new(r#"(([^ ]+)=([^"][^ ]+[^"])|([^ ]+)=([^"][^ ]+[^"]))"#)?;
|
let regex_set = RegexSet::new(&[
|
||||||
|
r#"([^ ]+)=([^"][^ ]+[^"])"#,
|
||||||
|
r#"([^ ]+)="(.+)"#
|
||||||
|
])?;
|
||||||
|
|
||||||
|
for pat in regex_set.matches(line.trim_start()).into_iter().map(|match_idx| ®ex_set.patterns()[match_idx]) {
|
||||||
|
let regex = Regex::new(&pat)?;
|
||||||
|
|
||||||
for cap in regex.captures_iter(line.trim_start()) {
|
for cap in regex.captures_iter(line.trim_start()) {
|
||||||
match &cap[1] {
|
let full_cap_idx = 0;
|
||||||
"path" => act.path = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
let key_cap_idx = 1;
|
||||||
"owner" => act.owner = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
let val_cap_idx = 2;
|
||||||
"group" => act.group = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
|
||||||
"mode" => act.mode = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
|
||||||
"revert-tag" => act.revert_tag = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
match &cap[key_cap_idx] {
|
||||||
"salvage-from" => act.salvage_from = String::from(&cap[2]).replace(&['"', '\\'][..], ""),
|
"path" => act.path = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
|
"owner" => act.owner = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
|
"group" => act.group = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
|
"mode" => act.mode = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
|
"revert-tag" => act.revert_tag = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
|
"salvage-from" => act.salvage_from = String::from(&cap[val_cap_idx]).trim_end().replace(&['"', '\\'][..], ""),
|
||||||
_ => {
|
_ => {
|
||||||
let key_val_string = String::from(&cap[1]).replace(&['"', '\\'][..], "");
|
let key_val_string = String::from(&cap[full_cap_idx]).trim_end().replace(&['"', '\\'][..], "");
|
||||||
if key_val_string.contains("facet.") {
|
if key_val_string.contains("facet.") {
|
||||||
let key = match key_val_string.find(".") {
|
let key = match key_val_string.find(".") {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
|
|
@ -201,13 +212,15 @@ fn parse_dir_action(line: String, line_nr: usize) -> Result<Dir, Error> {
|
||||||
None => return Err(ManifestError::InvalidAction{action: line, line: line_nr, message: String::from("no value present for facet")})?
|
None => return Err(ManifestError::InvalidAction{action: line, line: line_nr, message: String::from("no value present for facet")})?
|
||||||
};
|
};
|
||||||
|
|
||||||
if !act.facets.insert(Facet{name: key, value: value}) {
|
if !act.facets.insert(Facet{name: key, value }) {
|
||||||
return Err(ManifestError::InvalidAction{action: line, line: line_nr, message: String::from("double declaration of facet")})?
|
return Err(ManifestError::InvalidAction{action: line, line: line_nr, message: String::from("double declaration of facet")})?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +252,7 @@ fn parse_attr_action(line: String) -> Result<Attr, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
val = val.replace(&['"', '\\'][..], "");
|
val = val.replace(&['"', '\\'][..], "");
|
||||||
//TODO knock out single quotes somehow
|
//TODO knock out single quotes somehow without
|
||||||
|
|
||||||
if !fast_path_fail{
|
if !fast_path_fail{
|
||||||
return Ok(Attr{
|
return Ok(Attr{
|
||||||
|
|
|
||||||
10
src/lib.rs
10
src/lib.rs
|
|
@ -151,8 +151,8 @@ mod tests {
|
||||||
let manifest_string = String::from("dir group=bin mode=0755 owner=root path=etc/nginx
|
let manifest_string = String::from("dir group=bin mode=0755 owner=root path=etc/nginx
|
||||||
dir group=bin mode=0755 owner=root path=usr/share/nginx
|
dir group=bin mode=0755 owner=root path=usr/share/nginx
|
||||||
dir group=bin mode=0755 owner=root path=usr/share/nginx/html
|
dir group=bin mode=0755 owner=root path=usr/share/nginx/html
|
||||||
dir group=bin mode=0755 owner=root path=\"var/nginx\"
|
dir group=bin mode=0755 owner=webservd path=var/nginx/logs
|
||||||
dir group=bin mode=0755 owner=webservd path=var/nginx/logs");
|
dir group=bin mode=0755 owner=root path=\"var/nginx\"");
|
||||||
|
|
||||||
let test_results = vec![
|
let test_results = vec![
|
||||||
Dir{
|
Dir{
|
||||||
|
|
@ -176,14 +176,14 @@ mod tests {
|
||||||
},Dir{
|
},Dir{
|
||||||
group: String::from("bin"),
|
group: String::from("bin"),
|
||||||
mode: String::from("0755"),
|
mode: String::from("0755"),
|
||||||
owner: String::from("root"),
|
owner: String::from("webservd"),
|
||||||
path: String::from("\"var/nginx\""),
|
path: String::from("var/nginx/logs"),
|
||||||
..Dir::default()
|
..Dir::default()
|
||||||
},Dir{
|
},Dir{
|
||||||
group: String::from("bin"),
|
group: String::from("bin"),
|
||||||
mode: String::from("0755"),
|
mode: String::from("0755"),
|
||||||
owner: String::from("root"),
|
owner: String::from("root"),
|
||||||
path: String::from("var/nginx/logs"),
|
path: String::from("var/nginx"),
|
||||||
..Dir::default()
|
..Dir::default()
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue