summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-11 13:40:27 +0100
committerdiogo464 <[email protected]>2025-08-11 13:40:27 +0100
commitf69ca010b80703389fffe75fc6dca907e53df74d (patch)
tree1cf081f49b3793aae3f298ed50753841fd306424 /src
parent4af66f418b6837b6441b4e8eaf2d8ede585238b9 (diff)
basic file upload
Diffstat (limited to 'src')
-rw-r--r--src/main.rs42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 00091e6..39785fc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -99,9 +99,20 @@ pub fn blob_import_file(
99 std::fs::create_dir_all(parent)?; 99 std::fs::create_dir_all(parent)?;
100 } 100 }
101 match mode { 101 match mode {
102 ImportMode::Move => { 102 ImportMode::Move => match std::fs::rename(&file_path, &blob_path) {
103 std::fs::rename(file_path, blob_path)?; 103 Ok(()) => {}
104 } 104 Err(err) if err.kind() == std::io::ErrorKind::CrossesDevices => {
105 let blob_tmp_path = {
106 let mut p = blob_path.clone();
107 p.set_file_name(format!("{blob_id}.tmp"));
108 p
109 };
110 std::fs::copy(&file_path, &blob_tmp_path)?;
111 std::fs::rename(&blob_tmp_path, blob_path)?;
112 std::fs::remove_file(&file_path)?;
113 }
114 Err(err) => return Err(err),
115 },
105 ImportMode::Copy => { 116 ImportMode::Copy => {
106 let blob_tmp_path = { 117 let blob_tmp_path = {
107 let mut p = blob_path.clone(); 118 let mut p = blob_path.clone();
@@ -759,8 +770,7 @@ struct RemoveArgs {
759 #[clap(long)] 770 #[clap(long)]
760 email: String, 771 email: String,
761 772
762 #[clap(long)] 773 path: Vec<DrivePath>,
763 path: DrivePath,
764} 774}
765 775
766#[derive(Debug, Args)] 776#[derive(Debug, Args)]
@@ -899,16 +909,18 @@ fn cmd_remove(args: RemoveArgs) {
899 let timestamp = args.timestamp.unwrap_or_else(get_timestamp); 909 let timestamp = args.timestamp.unwrap_or_else(get_timestamp);
900 let revision = get_next_revision(&ops); 910 let revision = get_next_revision(&ops);
901 911
902 let new_op = Operation { 912 for path in args.path {
903 header: OperationHeader { 913 let new_op = Operation {
904 timestamp, 914 header: OperationHeader {
905 revision, 915 timestamp,
906 email: args.email, 916 revision,
907 }, 917 email: args.email.clone(),
908 data: OperationData::Remove(OperationRemove { path: args.path }), 918 },
909 }; 919 data: OperationData::Remove(OperationRemove { path }),
910 apply(&mut fs, &new_op).unwrap(); 920 };
911 ops.push(new_op); 921 apply(&mut fs, &new_op).unwrap();
922 ops.push(new_op);
923 }
912 common_write_log_file(&args.common, &ops); 924 common_write_log_file(&args.common, &ops);
913} 925}
914 926