copy & remove instead of persist/rename

feat/vaults
Tomáš Mládek 2022-01-18 22:43:55 +01:00
parent d46f449e4b
commit 7def06e153
1 changed files with 8 additions and 3 deletions

View File

@ -18,13 +18,13 @@ use futures_util::TryStreamExt;
use log::{debug, info, trace};
use serde::Deserialize;
use serde_json::json;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::time::UNIX_EPOCH;
use std::{collections::HashMap, io};
use tempfile::NamedTempFile;
#[cfg(feature = "desktop")]
@ -227,8 +227,13 @@ pub async fn put_object(
let final_path = state.upend.vault_path.join(&final_name);
file.persist(&final_path)
.map_err(ErrorInternalServerError)?;
let (_, tmp_path) = file.keep().map_err(ErrorInternalServerError)?;
let final_path = web::block::<_, _, io::Error>(move || {
fs::copy(&tmp_path, &final_path)?;
fs::remove_file(tmp_path)?;
Ok(final_path)
})
.await?;
let metadata = fs::metadata(&final_path)?;
let size = metadata.len() as i64;