From dd01bff07e029a12c98cf5aedfdce4d19f4f707c Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 2 Oct 2021 21:41:28 +0200 Subject: Re-add Ka repository directory creation to Create action. --- src/filesystem.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/filesystem.rs') diff --git a/src/filesystem.rs b/src/filesystem.rs index 74d7787..a19968b 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -14,7 +14,9 @@ pub trait Fs { fn open_readable_file(&self, path: &Path) -> Result; fn open_writable_file(&self, path: &Path) -> Result; + fn create_directory(&self, path: &Path) -> Result<()>; fn read_directory(&self, path: &Path) -> Result>; + fn delete_directory(&self, path: &Path) -> Result<()>; fn write_to_file(&self, file: &mut Self::File, buffer: Vec) -> Result<()>; fn read_from_file(&self, file: &mut Self::File) -> Result>; @@ -71,11 +73,21 @@ impl Fs for FsImpl { }) } + fn create_directory(&self, path: &Path) -> Result<()> { + fs::create_dir_all(path) + .with_context(|| format!("Failed creating directory '{}'.", path.display())) + } + fn read_directory(&self, path: &Path) -> Result> { let result: io::Result<_> = fs::read_dir(path)?.collect(); result.with_context(|| format!("Failed reading directory {}", path.display())) } + fn delete_directory(&self, path: &Path) -> Result<()> { + fs::remove_dir_all(path) + .with_context(|| format!("Failed deleting directory '{}'.", path.display())) + } + fn write_to_file(&self, file: &mut Self::File, buffer: Vec) -> Result<()> { file.rewind()?; file.set_len(0)?; @@ -197,6 +209,11 @@ pub mod mock { }) } + fn create_directory(&self, path: &Path) -> Result<()> { + self.add_call(path, ReceivedCallVariant::DirectoryCreated); + Ok(()) + } + fn read_directory(&self, path: &Path) -> Result> { self.add_call(path, ReceivedCallVariant::DirectoryRead); @@ -207,6 +224,11 @@ pub mod mock { } } + fn delete_directory(&self, path: &Path) -> Result<()> { + self.add_call(path, ReceivedCallVariant::DirectoryDeleted); + Ok(()) + } + fn write_to_file(&self, file: &mut Self::File, buffer: Vec) -> Result<()> { self.add_call( &file.path, @@ -274,7 +296,9 @@ pub mod mock { DeleteFile, OpenReadableFile, OpenWritableFile, + CreateDirectory, ReadDirectory { entries: Vec }, + DeleteDirectory, ReadFile { read_content: Vec }, WriteToFile, PathExists(bool), @@ -290,7 +314,9 @@ pub mod mock { FileDeleted, ReadableFileOpened, WritableFileOpened, + DirectoryCreated, DirectoryRead, + DirectoryDeleted, FileRead, FileWritten { written_content: Vec }, DoesPathExist, -- cgit 1.4.1