Tweak fs extractor
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
use pile_config::Label;
|
use pile_config::Label;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
path::Component,
|
path::{Component, PathBuf},
|
||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,22 +27,20 @@ impl FsExtractor {
|
|||||||
return Ok(x);
|
return Ok(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Item::File { path, .. } = &self.item else {
|
let path = PathBuf::from(self.item.key().as_str());
|
||||||
return Ok(self.output.get_or_init(HashMap::new));
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut root = false;
|
let mut root = false;
|
||||||
let components = path
|
let components = path
|
||||||
.components()
|
.components()
|
||||||
.map(|x| match x {
|
.filter_map(|x| match x {
|
||||||
Component::CurDir => None,
|
Component::CurDir => None,
|
||||||
Component::Normal(x) => x.to_str().map(|x| x.to_owned()),
|
Component::Normal(x) => Some(x.to_str().map(|x| x.to_owned())),
|
||||||
Component::ParentDir => Some("..".to_owned()),
|
Component::ParentDir => Some(Some("..".to_owned())),
|
||||||
Component::RootDir => {
|
Component::RootDir => {
|
||||||
root = true;
|
root = true;
|
||||||
None
|
Some(None)
|
||||||
}
|
}
|
||||||
Component::Prefix(x) => x.as_os_str().to_str().map(|x| x.to_owned()),
|
Component::Prefix(x) => Some(x.as_os_str().to_str().map(|x| x.to_owned())),
|
||||||
})
|
})
|
||||||
.collect::<Option<Vec<_>>>();
|
.collect::<Option<Vec<_>>>();
|
||||||
|
|
||||||
@@ -69,6 +67,7 @@ impl FsExtractor {
|
|||||||
(
|
(
|
||||||
Label::new("segments").unwrap(),
|
Label::new("segments").unwrap(),
|
||||||
components
|
components
|
||||||
|
.clone()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
PileValue::Array(Arc::new(
|
PileValue::Array(Arc::new(
|
||||||
x.iter()
|
x.iter()
|
||||||
@@ -78,6 +77,12 @@ impl FsExtractor {
|
|||||||
})
|
})
|
||||||
.unwrap_or(PileValue::Null),
|
.unwrap_or(PileValue::Null),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
Label::new("name").unwrap(),
|
||||||
|
components
|
||||||
|
.and_then(|x| x.last().map(|x| PileValue::String(Arc::new(x.into()))))
|
||||||
|
.unwrap_or(PileValue::Null),
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return Ok(self.output.get_or_init(|| output));
|
return Ok(self.output.get_or_init(|| output));
|
||||||
|
|||||||
Reference in New Issue
Block a user