refactor(db): use `parse` instead of `from_str`
parent
bf823bc1c8
commit
2150841ee6
|
@ -141,11 +141,11 @@ impl FsStore {
|
|||
|
||||
let upath = UHierPath(if let Some(dirname) = dirname {
|
||||
vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
UNode::from_str(&dirname.as_os_str().to_string_lossy()).unwrap(),
|
||||
]
|
||||
} else {
|
||||
vec![UNode::from_str("NATIVE").unwrap()]
|
||||
vec!["NATIVE".parse().unwrap()]
|
||||
});
|
||||
|
||||
upaths.insert(pb.clone(), upath);
|
||||
|
@ -166,7 +166,7 @@ impl FsStore {
|
|||
shallowest.insert(dirname.clone(), path.clone());
|
||||
}
|
||||
let shallowest_path = shallowest.get(&dirname).unwrap();
|
||||
let upath = iter::once(UNode::from_str("NATIVE").unwrap())
|
||||
let upath = iter::once("NATIVE".parse().unwrap())
|
||||
.chain(
|
||||
self.normalize_path(shallowest_path)
|
||||
.unwrap()
|
||||
|
@ -180,10 +180,7 @@ impl FsStore {
|
|||
.collect::<Vec<UNode>>();
|
||||
upaths.insert(path.clone(), UHierPath(upath));
|
||||
} else {
|
||||
upaths.insert(
|
||||
path.clone(),
|
||||
UHierPath(vec![UNode::from_str("NATIVE").unwrap()]),
|
||||
);
|
||||
upaths.insert(path.clone(), UHierPath(vec!["NATIVE".parse().unwrap()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +189,7 @@ impl FsStore {
|
|||
let normalized_path = self.normalize_path(&pb).unwrap();
|
||||
let path = normalized_path.parent().unwrap();
|
||||
|
||||
let upath = iter::once(UNode::from_str("NATIVE").unwrap())
|
||||
let upath = iter::once("NATIVE".parse().unwrap())
|
||||
.chain(path.iter().map(|component| {
|
||||
UNode::from_str(&component.to_string_lossy()).unwrap()
|
||||
}))
|
||||
|
@ -257,7 +254,6 @@ impl FsStore {
|
|||
let cleanup_results = existing_files.iter().filter(|f| f.valid).map(|file| {
|
||||
let trans_result = upconnection.transaction::<_, Error, _>(|| {
|
||||
self.file_set_valid(file.id, false)?;
|
||||
upconnection.remove_object(Address::from(file.clone()))?;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
|
@ -731,10 +727,7 @@ impl UpStore for FsStore {
|
|||
self.add_file(
|
||||
&connection,
|
||||
&final_path,
|
||||
UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("INCOMING").unwrap(),
|
||||
]),
|
||||
UHierPath(vec!["NATIVE".parse().unwrap(), "INCOMING".parse().unwrap()]),
|
||||
hash.clone(),
|
||||
name_hint,
|
||||
)
|
||||
|
@ -1035,18 +1028,18 @@ mod test {
|
|||
fn test_mirror_mode() {
|
||||
let connection = _prepare_hier_vault(VaultTreeMode::Mirror);
|
||||
|
||||
let native_path = UHierPath(vec![UNode::from_str("NATIVE").unwrap()]);
|
||||
let native_path = UHierPath(vec!["NATIVE".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &native_path, false).is_ok(),
|
||||
"Failed: NATIVE"
|
||||
);
|
||||
|
||||
let first_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("foo").unwrap(),
|
||||
UNode::from_str("bar").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("baz.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"foo".parse().unwrap(),
|
||||
"bar".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"baz.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &first_path, false).is_ok(),
|
||||
|
@ -1054,20 +1047,17 @@ mod test {
|
|||
);
|
||||
|
||||
let second_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("foo").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("qux.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"foo".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"qux.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &second_path, false).is_ok(),
|
||||
"Failed: `foo/baz/qux.txt`"
|
||||
);
|
||||
|
||||
let third_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("zot.txt").unwrap(),
|
||||
]);
|
||||
let third_path = UHierPath(vec!["NATIVE".parse().unwrap(), "zot.txt".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &third_path, false).is_ok(),
|
||||
"Failed: `zot.txt`"
|
||||
|
@ -1078,16 +1068,16 @@ mod test {
|
|||
fn test_flat_mode() {
|
||||
let connection = _prepare_hier_vault(VaultTreeMode::Flat);
|
||||
|
||||
let native_path = UHierPath(vec![UNode::from_str("NATIVE").unwrap()]);
|
||||
let native_path = UHierPath(vec!["NATIVE".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &native_path, false).is_ok(),
|
||||
"Failed: NATIVE"
|
||||
);
|
||||
|
||||
let first_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("baz.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"baz.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &first_path, false).is_ok(),
|
||||
|
@ -1095,19 +1085,16 @@ mod test {
|
|||
);
|
||||
|
||||
let second_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("qux.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"qux.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &second_path, false).is_ok(),
|
||||
"Failed: `baz/qux.txt`"
|
||||
);
|
||||
|
||||
let third_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("zot.txt").unwrap(),
|
||||
]);
|
||||
let third_path = UHierPath(vec!["NATIVE".parse().unwrap(), "zot.txt".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &third_path, false).is_ok(),
|
||||
"Failed: `zot.txt`"
|
||||
|
@ -1118,17 +1105,17 @@ mod test {
|
|||
fn test_depth_mode() {
|
||||
let connection = _prepare_hier_vault(VaultTreeMode::DepthFirst);
|
||||
|
||||
let native_path = UHierPath(vec![UNode::from_str("NATIVE").unwrap()]);
|
||||
let native_path = UHierPath(vec!["NATIVE".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &native_path, false).is_ok(),
|
||||
"Failed: NATIVE"
|
||||
);
|
||||
|
||||
let first_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("foo").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("baz.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"foo".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"baz.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &first_path, false).is_ok(),
|
||||
|
@ -1136,20 +1123,17 @@ mod test {
|
|||
);
|
||||
|
||||
let second_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("foo").unwrap(),
|
||||
UNode::from_str("baz").unwrap(),
|
||||
UNode::from_str("qux.txt").unwrap(),
|
||||
"NATIVE".parse().unwrap(),
|
||||
"foo".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
"qux.txt".parse().unwrap(),
|
||||
]);
|
||||
assert!(
|
||||
resolve_path(&connection, &second_path, false).is_ok(),
|
||||
"Failed: `foo/baz/qux.txt`"
|
||||
);
|
||||
|
||||
let third_path = UHierPath(vec![
|
||||
UNode::from_str("NATIVE").unwrap(),
|
||||
UNode::from_str("zot.txt").unwrap(),
|
||||
]);
|
||||
let third_path = UHierPath(vec!["NATIVE".parse().unwrap(), "zot.txt".parse().unwrap()]);
|
||||
assert!(
|
||||
resolve_path(&connection, &third_path, false).is_ok(),
|
||||
"Failed: `zot.txt`"
|
||||
|
|
Loading…
Reference in New Issue