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