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