From 6bfc7ee06dc1a598014dd5bec659b14a3aa87bbd Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 22 Aug 2024 14:22:13 +0200 Subject: feat(download): Support limiting the downloader by maximal cache size --- src/constants.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/constants.rs') diff --git a/src/constants.rs b/src/constants.rs index f4eef3d..00919ce 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -8,9 +8,9 @@ // You should have received a copy of the License along with this program. // If not, see . -use std::{env::temp_dir, path::PathBuf}; +use std::{env::temp_dir, fs, path::PathBuf}; -use anyhow::Context; +use anyhow::{Context, Result}; pub const HELP_STR: &str = include_str!("./select/selection_file/help.str"); pub const LOCAL_COMMENTS_LENGTH: usize = 1000; @@ -21,9 +21,15 @@ pub const DEFAULT_SUBTITLE_LANGS: &str = "en"; pub const CONCURRENT_DOWNLOADS: u32 = 5; // We download to the temp dir to avoid taxing the disk -pub fn download_dir() -> PathBuf { +pub fn download_dir(create: bool) -> Result { const DOWNLOAD_DIR: &str = "/tmp/yt"; - PathBuf::from(DOWNLOAD_DIR) + let dir = PathBuf::from(DOWNLOAD_DIR); + + if !dir.exists() && create { + fs::create_dir_all(&dir).context("Failed to create the download directory")? + } + + Ok(dir) } const PREFIX: &str = "yt"; -- cgit 1.4.1