Skip to content

Commit

Permalink
use path instead of pathbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorCastelli committed Jan 5, 2024
1 parent e591dee commit 6b3ff29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/file_system.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::path::PathBuf;
use std::path::{PathBuf, Path};

use mockall::automock;

#[automock]
pub(crate) trait FileSystem {
fn dir_exists(&self, path: &PathBuf) -> bool;
fn create_dir(&self, path: &PathBuf) -> Result<PathBuf, FileSystemError>;
fn dir_exists(&self, path: &Path) -> bool;
fn create_dir(&self, path: &Path) -> Result<PathBuf, FileSystemError>;
}

#[derive(Debug)]
Expand Down
7 changes: 4 additions & 3 deletions src/file_system/real_file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ use std::fs::create_dir_all;

use std::fs::metadata;

use std::path::Path;
use std::path::PathBuf;

use super::FileSystem;

pub(crate) struct RealFileSystem;

impl FileSystem for RealFileSystem {
fn dir_exists(&self, path: &PathBuf) -> bool {
fn dir_exists(&self, path: &Path) -> bool {
metadata(path).map_or(false, |metadata| metadata.is_dir())
}

fn create_dir(&self, path: &PathBuf) -> Result<PathBuf, FileSystemError> {
fn create_dir(&self, path: &Path) -> Result<PathBuf, FileSystemError> {
match create_dir_all(path) {
Ok(_) => Ok(path.clone()),
Ok(_) => Ok(PathBuf::from(path)),
Err(_) => Err(FileSystemError::UnableToCreateDirectory),
}
}
Expand Down

0 comments on commit 6b3ff29

Please sign in to comment.