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.
This commit is contained in:
Yip Rui Fung
2022-07-09 01:19:00 +08:00
parent b64cf27038
commit ebe9162af9
3 changed files with 13 additions and 2 deletions

View File

@ -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() {