Use match to avoid ownership issues on the TempFile / file_path variables in closures.

This commit is contained in:
Yip Rui Fung
2022-07-09 10:33:27 +08:00
parent 5c38b2c4eb
commit 31595888ea
2 changed files with 22 additions and 19 deletions

View File

@@ -1,23 +1,24 @@
use std::collections::{HashMap, HashSet};
use chrono::{NaiveDateTime, Utc};
use rocket::fs::TempFile;
use rocket::serde::json::Json;
use futures::{stream, stream::StreamExt};
use rocket::{
form::{Form, FromForm},
Route,
};
use rocket::fs::TempFile;
use rocket::serde::json::Json;
use serde_json::Value;
use crate::{
api::{self, EmptyResult, JsonResult, JsonUpcase, Notify, PasswordData, UpdateType},
auth::Headers,
crypto,
db::{models::*, DbConn, DbPool},
CONFIG,
crypto,
db::{DbConn, DbPool, models::*},
};
use futures::{stream, stream::StreamExt, TryFutureExt};
use super::folders::FolderData;
pub fn routes() -> Vec<Route> {
// 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<String>,
Fields: Option<Value>,
@@ -230,7 +232,8 @@ pub struct CipherData {
// These are used during key rotation
#[serde(rename = "Attachments")]
_Attachments: Option<Value>, // Unused, contains map of {id: filename}
_Attachments: Option<Value>,
// Unused, contains map of {id: filename}
Attachments2: Option<HashMap<String, Attachments2Data>>,
// 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 {
@@ -804,7 +805,7 @@ async fn share_cipher_by_uuid(
nt,
UpdateType::CipherUpdate,
)
.await?;
.await?;
Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, None, conn).await))
}
@@ -998,9 +999,10 @@ async fn save_attachment(
attachment.save(&conn).await.expect("Error saving attachment");
}
data.data.persist_to(&file_path)
.unwrap_or_else(data.data.move_copy_to(&file_path))
.await?;
match data.data.persist_to(&file_path).await {
Ok(_result) => {}
Err(_error) => data.data.move_copy_to(&file_path).await?
}
nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn).await).await;