Re-use xattr values already loaded
This commit is contained in:
parent
74504c90d3
commit
e985456c29
1 changed files with 6 additions and 15 deletions
|
@ -9,9 +9,9 @@ use crate::{
|
|||
use std::{collections::HashMap, io::Write, path::PathBuf};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct FileXattrs<'a> {
|
||||
struct FileXattrs<'a, 'b> {
|
||||
path: String,
|
||||
xattrs: HashMap<&'a Xattr, Value>,
|
||||
xattrs: HashMap<&'a Xattr, &'b Value>,
|
||||
}
|
||||
|
||||
pub fn get(
|
||||
|
@ -44,22 +44,13 @@ pub fn get(
|
|||
fields.clone()
|
||||
};
|
||||
if *json {
|
||||
let mut xattrs: HashMap<&Xattr, Value> = HashMap::with_capacity(projected_fields.len());
|
||||
let mut xattrs: HashMap<&Xattr, &Value> =
|
||||
HashMap::with_capacity(projected_fields.len());
|
||||
|
||||
for field in projected_fields.iter() {
|
||||
let field_osstring = field.to_osstring();
|
||||
if let Some(value) = xattr::get(&path, field_osstring).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Could not get xattr {} from {}: {}",
|
||||
field,
|
||||
path.display(),
|
||||
e
|
||||
);
|
||||
}) {
|
||||
let value = Value::from(value.as_slice());
|
||||
let value = &all_field_values[field];
|
||||
|
||||
xattrs.insert(field, value);
|
||||
}
|
||||
xattrs.insert(field, value);
|
||||
}
|
||||
|
||||
if !xattrs.is_empty() {
|
||||
|
|
Loading…
Reference in a new issue