aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-05-31 16:29:40 -0700
committerBryan Newbold <bnewbold@archive.org>2020-05-31 16:30:13 -0700
commit31f1d3d18566d1ae97daaedbd17132a11a7ab5aa (patch)
treeef0183f9888ce3d51cd4d3ef0fb74261afdd4cf8 /src/bin
parent661da10e73b9ec95a0411d1e54b999f6696c3152 (diff)
downloadaft-31f1d3d18566d1ae97daaedbd17132a11a7ab5aa.tar.gz
aft-31f1d3d18566d1ae97daaedbd17132a11a7ab5aa.zip
start aft-ls
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/aft-ls.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bin/aft-ls.rs b/src/bin/aft-ls.rs
new file mode 100644
index 0000000..3118c08
--- /dev/null
+++ b/src/bin/aft-ls.rs
@@ -0,0 +1,36 @@
+
+use std::{fs,env,path};
+use std::error::Error;
+use std::os::unix::fs::MetadataExt;
+
+fn main() -> Result<(), Box<dyn Error>> {
+
+ let args: Vec<String> = env::args().collect();
+ let dir = match args.len() {
+ 0 | 1 => path::Path::new("."),
+ _other => path::Path::new(&args[2]),
+ };
+
+ // header is basically a constant
+ print!("\x01");
+ println!("{}\x1D", ["file_name", "size", "mtime"].join("\x1E"));
+ println!("{}\x1D", ["string", "integer+bytes", "datetime"].join("\x1E"));
+ print!("\x02");
+
+ for entry in fs::read_dir(dir)? {
+ let entry = entry?;
+ let metadata = entry.metadata()?;
+ let filename: String = entry.file_name()
+ .into_string()
+ .or_else(|_| Err(format!("Invalid entry")))?;
+ let mtime = chrono::DateTime::<chrono::Utc>::from_utc(
+ chrono::NaiveDateTime::from_timestamp(metadata.mtime(), 0), chrono::Utc);
+ println!("{}\x1D",
+ [
+ filename,
+ metadata.size().to_string(),
+ mtime.to_rfc3339_opts(chrono::SecondsFormat::AutoSi, true),
+ ].join("\x1E"));
+ }
+ Ok(())
+}