diff options
Diffstat (limited to '')
-rw-r--r-- | yt/src/download/mod.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/yt/src/download/mod.rs b/yt/src/download/mod.rs index a056f80..5032b0f 100644 --- a/yt/src/download/mod.rs +++ b/yt/src/download/mod.rs @@ -8,7 +8,7 @@ // You should have received a copy of the License along with this program. // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration}; +use std::{collections::HashMap, io, str::FromStr, sync::Arc, time::Duration}; use crate::{ app::App, @@ -234,7 +234,38 @@ impl Downloader { .boxed() } - dir_size(fs::read_dir(&app.config.paths.download_dir).await?).await + let read_dir_result = match fs::read_dir(&app.config.paths.download_dir).await { + Ok(ok) => ok, + Err(err) => match err.kind() { + io::ErrorKind::NotFound => { + fs::create_dir_all(&app.config.paths.download_dir) + .await + .with_context(|| { + format!( + "Failed to create download dir at: '{}'", + &app.config.paths.download_dir.display() + ) + })?; + + info!( + "Created empty download dir at '{}'", + &app.config.paths.download_dir.display(), + ); + + // The new dir should not contain anything (otherwise we would not have had to + // create it) + return Ok(0); + } + err => Err(io::Error::from(err)).with_context(|| { + format!( + "Failed to get dir size of download dir at: '{}'", + &app.config.paths.download_dir.display() + ) + })?, + }, + }; + + dir_size(read_dir_result).await } async fn get_approx_video_size(&mut self, app: &App, video: &Video) -> Result<u64> { |