diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index d70dd906..137242b0 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -1,6 +1,7 @@ use std::collections::{HashMap, HashSet}; use chrono::{NaiveDateTime, Utc}; +use futures::{stream, stream::StreamExt}; use rocket::fs::TempFile; use rocket::serde::json::Json; use rocket::{ @@ -17,7 +18,7 @@ use crate::{ CONFIG, }; -use futures::{stream, stream::StreamExt}; +use super::folders::FolderData; pub fn routes() -> Vec { // Note that many routes have an `admin` variant; this seems to be @@ -212,7 +213,8 @@ pub struct CipherData { Card = 3, Identity = 4 */ - pub Type: i32, // TODO: Change this to NumberOrString + pub Type: i32, + // TODO: Change this to NumberOrString pub Name: String, Notes: Option, Fields: Option, @@ -230,7 +232,8 @@ pub struct CipherData { // These are used during key rotation #[serde(rename = "Attachments")] - _Attachments: Option, // Unused, contains map of {id: filename} + _Attachments: Option, + // Unused, contains map of {id: filename} Attachments2: Option>, // The revision datetime (in ISO 8601 format) of the client's local copy @@ -470,8 +473,6 @@ pub async fn update_cipher_from_data( Ok(()) } -use super::folders::FolderData; - #[derive(Deserialize)] #[allow(non_snake_case)] struct ImportData { @@ -998,7 +999,9 @@ async fn save_attachment( attachment.save(&conn).await.expect("Error saving attachment"); } - data.data.persist_to(file_path).await?; + if let Err(_err) = data.data.persist_to(&file_path).await { + 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 9c53e936..4012fd82 100644 --- a/src/api/core/sends.rs +++ b/src/api/core/sends.rs @@ -225,7 +225,10 @@ async fn post_send_file(data: Form>, 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 let Err(_err) = data.persist_to(&file_path).await { + 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() {