Skip to content

Commit

Permalink
chore: create missing directory for downloads in DownloadsBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Kremilly committed Jun 5, 2024
1 parent 2bb7a88 commit cfc17c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/syntax/downloads_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use crate::{
args_cli::Flags,
utils::file::FileMisc,
system::providers::Providers,
ui::macros_alerts::MacrosAlerts,

Expand Down Expand Up @@ -42,6 +43,8 @@ impl DownloadsBlock {

if let (Some(start_index), Some(end_index)) = (start_index, end_index) {
let mut refs = Vec::new();

FileMisc::create_path(&path);
let downloads_content = &contents[start_index + "downloads ".len()..end_index];

for line in downloads_content.lines() {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ impl FileMisc {
Path::new(&path).exists()
}

pub fn create_path(path: &str) {
if !Self::check_path_exists(path) {
fs::create_dir_all(path).expect(
&"Error creating directory".to_string()
);
}
}

pub fn write_file(path: &str, contents: String) {
fs::write(path, contents).expect(
&"Error saving file".to_string()
Expand Down

0 comments on commit cfc17c0

Please sign in to comment.