create folder if not found

This commit is contained in:
Edward Shen 2021-07-16 20:03:59 -04:00
parent f8f4098fae
commit 93ff76aa89
Signed by: edward
GPG key ID: 19182661E818369F

6
src/cache/disk.rs vendored
View file

@ -16,7 +16,7 @@ use md5::{Digest, Md5};
use sodiumoxide::hex; use sodiumoxide::hex;
use sqlx::sqlite::SqliteConnectOptions; use sqlx::sqlite::SqliteConnectOptions;
use sqlx::{ConnectOptions, Sqlite, SqlitePool, Transaction}; use sqlx::{ConnectOptions, Sqlite, SqlitePool, Transaction};
use tokio::fs::{remove_file, rename, File}; use tokio::fs::{create_dir_all, remove_file, rename, File};
use tokio::join; use tokio::join;
use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
@ -43,6 +43,10 @@ impl DiskCache {
/// This internally spawns a task that will wait for filesystem /// This internally spawns a task that will wait for filesystem
/// notifications when a file has been written. /// notifications when a file has been written.
pub async fn new(disk_max_size: Bytes, disk_path: PathBuf) -> Arc<Self> { pub async fn new(disk_max_size: Bytes, disk_path: PathBuf) -> Arc<Self> {
if let Err(e) = create_dir_all(&disk_path).await {
error!("Failed to create cache folder: {}", e);
}
let cache_path = disk_path.to_string_lossy(); let cache_path = disk_path.to_string_lossy();
// Migrate old to new path // Migrate old to new path
if rename( if rename(