Make get output look good again

This commit is contained in:
Josh Hansen 2023-09-26 20:14:39 -07:00
parent ce226e3565
commit 32266b6e13
3 changed files with 20 additions and 10 deletions

View file

@ -23,7 +23,7 @@ Initialized ./people/Darrel
Linked ./people:id/5 -> ./people/Darrel
Linked ./people/:state:id/MI/5 -> ./people/Darrel
+ cargo run --quiet -- get -a ./people
user.ghee.tableinfo {"key":"name","indices":{"id":"./people:id","name":"./people","state,id":"./people/:state:id"}}
user.ghee.tableinfo {"abs_path":"/home/josh/Projects/Ghee/example/people","key":"name","indices":{"id":"/home/josh/Projects/Ghee/example/people:id","name":".","state,id":"./:state:id"},"indices_abs":{"id":"/home/josh/Projects/Ghee/example/people:id","name":"/home/josh/Projects/Ghee/example/people","state,id":"/home/josh/Projects/Ghee/example/people/:state:id"},"indices_both":{"id":{"rel":"/home/josh/Projects/Ghee/example/people:id","abs":"/home/josh/Projects/Ghee/example/people:id"},"name":{"rel":".","abs":"/home/josh/Projects/Ghee/example/people"},"state,id":{"rel":"./:state:id","abs":"/home/josh/Projects/Ghee/example/people/:state:id"}}}
./people/Darrel user.id 5
./people/Darrel user.name Darrel
./people/Darrel user.state MI

View file

@ -47,17 +47,9 @@ pub fn get(
visit_empty,
&|record| {
let output_path = record
.original_path()
.original_path_abs()
.map(|p| p.relative_to_curdir_if_possible())
.unwrap_or_default();
// let output_path = record
// .original_path()
// .map(|p| {
// debug_assert!(p.is_absolute());
// let rel_path = p.relativize(&abs_path).unwrap();
// rel_path.resolve_curdir(path).unwrap()
// })
// .unwrap_or_default();
// Fields that will be output
let projected_fields: Vec<Xattr> = if fields.is_empty() {

View file

@ -62,6 +62,24 @@ impl<'a, 'b, 'c> PathVisit<'a, 'b, 'c> {
Ok(self.path.clone())
}
}
pub fn original_path_abs(&self) -> Result<PathBuf> {
if let Some(table_info) = self.table_info {
let original_table_key = table_info.key();
let subkey_values = original_table_key.value_for_record(self.xattr_values)?;
let mut path = table_info.index_path_abs(original_table_key).clone();
for sub in subkey_values {
path.push(sub.to_string());
}
Ok(path)
} else {
// If there are no indices, this path itself is the original path
Ok(self.path.clone())
}
}
}
/// Walk a path from Ghee's point of view, yielding only the DirEntry's, i.e. _not_