feat: add xattr-rs
This commit is contained in:
56
xattr-rs/src/main.rs
Executable file
56
xattr-rs/src/main.rs
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env runrs
|
||||
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! rust_util = "0.6.47"
|
||||
//! xattr = "1.4.0"
|
||||
//! ```
|
||||
|
||||
use rust_util::{failure, failure_and_exit, information};
|
||||
|
||||
fn main() {
|
||||
let args = std::env::args().skip(1).collect::<Vec<_>>();
|
||||
if args.is_empty() {
|
||||
failure_and_exit!("No argument is assigned.");
|
||||
}
|
||||
|
||||
for filename in &args {
|
||||
match xattr::list(filename) {
|
||||
Err(e) => {
|
||||
failure!("Error read file: {filename}, error: {e}");
|
||||
}
|
||||
Ok(xattrs) => {
|
||||
for (_, xattr) in xattrs.enumerate() {
|
||||
let clone_xattr = xattr.clone();
|
||||
let xattr_name = match clone_xattr.to_str() {
|
||||
None => {
|
||||
continue;
|
||||
}
|
||||
Some(xattr_name) => xattr_name,
|
||||
};
|
||||
println!("{xattr_name}: ");
|
||||
match xattr::get(filename, xattr) {
|
||||
Err(e) => {
|
||||
println!(" - read xattr: {xattr_name}, failed: {e}");
|
||||
}
|
||||
Ok(Some(value)) => {
|
||||
println!(
|
||||
"> {}",
|
||||
String::from_utf8_lossy(value.as_ref())
|
||||
.to_string()
|
||||
.lines()
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n> \n")
|
||||
);
|
||||
}
|
||||
Ok(None) => {
|
||||
// DO NOTHING
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
information!("use xattr -c <filename> to remove xattrs");
|
||||
}
|
||||
Reference in New Issue
Block a user