aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bin/geniza-drive.rs53
-rw-r--r--src/drive.rs8
2 files changed, 45 insertions, 16 deletions
diff --git a/src/bin/geniza-drive.rs b/src/bin/geniza-drive.rs
index 79ba480..62bfc90 100644
--- a/src/bin/geniza-drive.rs
+++ b/src/bin/geniza-drive.rs
@@ -7,7 +7,6 @@ extern crate env_logger;
extern crate error_chain;
extern crate geniza;
-// TODO: more careful import
use geniza::*;
use std::path::Path;
use clap::{App, Arg, SubCommand};
@@ -17,13 +16,12 @@ fn run() -> Result<()> {
let matches = App::new("geniza-drive")
.version(env!("CARGO_PKG_VERSION"))
- // TODO: dat-dir for all commands up here, and have a default vaule ('./dat')
.arg(Arg::with_name("dat-dir")
.short("d")
.long("dat-dir")
.value_name("PATH")
.help("dat drive directory")
- .default_value(".dat") // TODO: needs to be default_value_os?
+ .default_value(".dat")
.takes_value(true))
.subcommand(
SubCommand::with_name("init")
@@ -62,6 +60,22 @@ fn run() -> Result<()> {
SubCommand::with_name("dump-entries")
.about("Dump all entries in a debug-friendly format")
)
+ .subcommand(
+ SubCommand::with_name("copy")
+ .about("Internally copies a file in a dat archive")
+ .arg_from_usage("<FROM> 'path to copy from'")
+ .arg_from_usage("<TO> 'path to copy from'")
+ )
+ .subcommand(
+ SubCommand::with_name("remove")
+ .about("Deletes a file path from dat archive")
+ .arg_from_usage("<FILE> 'file to delete'")
+ )
+ .subcommand(
+ SubCommand::with_name("remove-dir-all")
+ .about("Recursively deletes a directory from the dat archive")
+ .arg_from_usage("<PATH> 'directory to delete'")
+ )
.get_matches();
let dir = Path::new(matches.value_of("dat-dir").unwrap());
@@ -78,6 +92,14 @@ fn run() -> Result<()> {
println!("{}", entry.path.display());
}
}
+ ("cat", Some(subm)) => {
+ let path = Path::new(subm.value_of("FILE").unwrap());
+ let mut drive = DatDrive::open(dir, true)?;
+ let data = drive.read_file_bytes(&path)?;
+ // TODO: just write to stdout
+ let s = String::from_utf8(data).unwrap();
+ println!("{}", s);
+ }
("import-file", Some(subm)) => {
let path = Path::new(subm.value_of("FILE").unwrap());
let mut drive = DatDrive::open(dir, true)?;
@@ -97,15 +119,6 @@ fn run() -> Result<()> {
};
drive.export_file(&path, &fpath)?;
}
- ("cat", Some(subm)) => {
- let path = Path::new(subm.value_of("FILE").unwrap());
- let mut drive = DatDrive::open(dir, true)?;
- let data = drive.read_file_bytes(&path)?;
- // TODO: just write to stdout
- let s = String::from_utf8(data).unwrap();
- println!("{}", s);
-
- }
("log", Some(_subm)) => {
let mut drive = DatDrive::open(dir, false)?;
for entry in drive.history(0) {
@@ -143,6 +156,22 @@ fn run() -> Result<()> {
}
}
}
+ ("copy", Some(subm)) => {
+ let from_path= Path::new(subm.value_of("FROM").unwrap());
+ let to_path= Path::new(subm.value_of("FROM").unwrap());
+ let mut drive = DatDrive::open(dir, true)?;
+ drive.copy_file(&from_path, &to_path)?;
+ }
+ ("remove", Some(subm)) => {
+ let path = Path::new(subm.value_of("FILE").unwrap());
+ let mut drive = DatDrive::open(dir, true)?;
+ drive.remove_file(&path)?;
+ }
+ ("remove-dir-all", Some(subm)) => {
+ let path = Path::new(subm.value_of("FILE").unwrap());
+ let mut drive = DatDrive::open(dir, true)?;
+ drive.remove_dir_all(&path)?;
+ }
_ => {
println!("Missing or unimplemented command!");
println!("{}", matches.usage());
diff --git a/src/drive.rs b/src/drive.rs
index b064a25..a4e6cf9 100644
--- a/src/drive.rs
+++ b/src/drive.rs
@@ -516,7 +516,7 @@ impl<'a> DatDrive {
}
/// Returns version number of completed action on success.
- pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(&mut self, from: P, to: Q) -> Result<u64> {
+ pub fn copy_file<P: AsRef<Path>, Q: AsRef<Path>>(&mut self, from: P, to: Q) -> Result<u64> {
let from = from.as_ref();
let to = to.as_ref();
if from == to {
@@ -541,7 +541,7 @@ impl<'a> DatDrive {
// Crude implementation:
// 1. copy file
let from = from.as_ref();
- self.copy(from, to)?;
+ self.copy_file(from, to)?;
// 2. delete the original
self.remove_file(from)
@@ -741,14 +741,14 @@ fn test_dd_remove_dir_all() {
}
#[test]
-fn test_dd_copy() {
+fn test_dd_copy_file() {
use tempdir::TempDir;
let tmp_dir = TempDir::new("geniza-test").unwrap();
let mut dd = DatDrive::create(tmp_dir.path()).unwrap();
dd.import_file("test-data/dat/alphabet/a", "/a").unwrap();
- dd.copy("/a", "/c").unwrap();
+ dd.copy_file("/a", "/c").unwrap();
assert_eq!(dd.history(0).count(), 2);
assert!(&dd.read_file_bytes("/a").is_ok());
assert!(&dd.read_file_bytes("/c").is_ok());