commit ebe9162af9fac09b7800e3b1b4a24534e4d2aad3
parent b64cf27038f04368af8f25aa80782d37471e6303
Author: Yip Rui Fung <rf@yrf.me>
Date: Sat, 9 Jul 2022 01:19:00 +0800
Add option to make file uploads use move_copy_to instead of persist_to
This is to support scenarios where the attachments and sends folder are to be stored on a separate device from the tmp_folder (i.e. fuse-mounted S3 storage), due to having the tmp_dir on the same device being undesirable.
Example being fuse-mounted S3 storage with the reasoning that because S3 basically requires a copy+delete operations to rename files, it's inefficient to rename files on device, if it's even allowed.
Diffstat:
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs
@@ -998,7 +998,11 @@ async fn save_attachment(
attachment.save(&conn).await.expect("Error saving attachment");
}
- data.data.persist_to(file_path).await?;
+ if CONFIG.uploads_use_copy() {
+ data.data.move_copy_to(file_path).await?;
+ } else {
+ data.data.persist_to(file_path).await?;
+ }
nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn).await).await;
diff --git a/src/api/core/sends.rs b/src/api/core/sends.rs
@@ -225,7 +225,12 @@ async fn post_send_file(data: Form<UploadData<'_>>, headers: Headers, conn: DbCo
let folder_path = tokio::fs::canonicalize(&CONFIG.sends_folder()).await?.join(&send.uuid);
let file_path = folder_path.join(&file_id);
tokio::fs::create_dir_all(&folder_path).await?;
- data.persist_to(&file_path).await?;
+
+ if CONFIG.uploads_use_copy() {
+ data.move_copy_to(&file_path).await?;
+ } else {
+ data.persist_to(&file_path).await?;
+ }
let mut data_value: Value = serde_json::from_str(&send.data)?;
if let Some(o) = data_value.as_object_mut() {
diff --git a/src/config.rs b/src/config.rs
@@ -343,6 +343,8 @@ make_config! {
rsa_key_filename: String, false, auto, |c| format!("{}/{}", c.data_folder, "rsa_key");
/// Web vault folder
web_vault_folder: String, false, def, "web-vault/".to_string();
+ /// Uploading files uses move_copy_to instead of persist_to to support cross-device scenarios where having tmp_folder on the same drive is undesirable. i.e. fuse-mounted S3.
+ uploads_use_copy: bool, false, def, false;
},
ws {
/// Enable websocket notifications