From 5c38b2c4eb67d74b33023227e4644b5f646703f1 Mon Sep 17 00:00:00 2001 From: Yip Rui Fung Date: Sat, 9 Jul 2022 08:53:00 +0800 Subject: [PATCH] Remove option and use unwrap_or_else to fall back to copy behavior. --- src/api/core/ciphers.rs | 10 ++++------ src/api/core/sends.rs | 9 ++++----- src/config.rs | 2 -- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 32c4d7a6..0da7a0c2 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -17,7 +17,7 @@ use crate::{ CONFIG, }; -use futures::{stream, stream::StreamExt}; +use futures::{stream, stream::StreamExt, TryFutureExt}; pub fn routes() -> Vec { // Note that many routes have an `admin` variant; this seems to be @@ -998,11 +998,9 @@ async fn save_attachment( attachment.save(&conn).await.expect("Error saving attachment"); } - if CONFIG.uploads_use_copy() { - data.data.move_copy_to(file_path).await?; - } else { - data.data.persist_to(file_path).await?; - } + data.data.persist_to(&file_path) + .unwrap_or_else(data.data.move_copy_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 index e8c5c3a6..90b75b55 100644 --- a/src/api/core/sends.rs +++ b/src/api/core/sends.rs @@ -1,6 +1,7 @@ use std::path::Path; use chrono::{DateTime, Duration, Utc}; +use futures::TryFutureExt; use rocket::form::Form; use rocket::fs::NamedFile; use rocket::fs::TempFile; @@ -226,11 +227,9 @@ async fn post_send_file(data: Form>, headers: Headers, conn: DbCo let file_path = folder_path.join(&file_id); tokio::fs::create_dir_all(&folder_path).await?; - if CONFIG.uploads_use_copy() { - data.move_copy_to(&file_path).await?; - } else { - data.persist_to(&file_path).await?; - } + data.persist_to(&file_path) + .unwrap_or_else(data.move_copy_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 index a52abd4a..09240c36 100644 --- a/src/config.rs +++ b/src/config.rs @@ -343,8 +343,6 @@ 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