diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 42 |
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 | ||
