This commit is contained in:
Niels Andriesse 2021-04-27 16:21:50 +10:00 committed by nielsandriesse
parent 7df4117c7d
commit cb67709ba5
3 changed files with 6 additions and 10 deletions

View File

@ -169,15 +169,11 @@ pub async fn store_file(
// Write to file
// room_id is guaranteed to be present at this point
let room_id = room_id.unwrap();
match std::fs::create_dir_all(format!("files/{}", &room_id)) {
match std::fs::create_dir_all(format!("files/{}_files", &room_id)) {
Ok(_) => (),
Err(e) => {
error!("Couldn't store file due to error: {}.", e);
return Err(warp::reject::custom(Error::DatabaseFailedInternally));
}
Err(_) => (),
};
let raw_path = format!("files/{}/{}", &room_id, &id);
println!("mmmyess");
let raw_path = format!("files/{}_files/{}", &room_id, &id);
let path = Path::new(&raw_path);
let mut file = match File::create(path).await {
Ok(file) => file,
@ -223,7 +219,7 @@ pub async fn get_file(
// Try to read the file
let mut bytes = vec![];
// room_id is guaranteed to be present at this point
let raw_path = format!("files/{}/{}", room_id.unwrap(), id);
let raw_path = format!("files/{}_files/{}", room_id.unwrap(), id);
let path = Path::new(&raw_path);
let mut file = match File::open(path).await {
Ok(file) => file,

View File

@ -267,7 +267,7 @@ pub async fn prune_files(file_expiration: i64) {
// Delete the files
let mut deleted_ids: Vec<String> = vec![];
for id in ids {
match fs::remove_file(format!("files/{}/{}", room, id)) {
match fs::remove_file(format!("files/{}_files/{}", room, id)) {
Ok(_) => deleted_ids.push(id),
Err(e) => error!("Couldn't delete file due to error: {}.", e),
}

View File

@ -107,7 +107,7 @@ async fn test_file_handling() {
// Will evaluate to now + 60
storage::prune_files(-60).await;
// It should be gone now
fs::read(format!("files/{}/{}", test_room_id, id)).unwrap_err();
fs::read(format!("files/{}_files/{}", test_room_id, id)).unwrap_err();
// Check that the file record is also gone
let conn = pool.get().unwrap();
let raw_query = format!("SELECT id FROM {}", storage::FILES_TABLE);