From 47b25c05a6be51b93c909d38a19440d1c04ba2f8 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 16:23:29 +1300 Subject: Large collection of changes --- src/operations.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/operations.rs') diff --git a/src/operations.rs b/src/operations.rs index 54ce8c7..dd0a132 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -1,30 +1,25 @@ use crate::*; -use std::path::Path; - -mod ls; -pub use ls::*; mod cp; -pub use cp::*; - +mod ls; +mod mkdir; mod rm; -pub use rm::*; -mod mkdir; +pub use cp::*; +pub use ls::*; pub use mkdir::*; +pub use rm::*; -pub fn append_to_file

(_path: P, _content: &str) -> Result<(), EntryWriteError> -where - P: AsRef, -{ +/// Append bytes to the end of a file. +#[must_use] +pub fn append_to_file(_path: impl AsRef, _content: &str) -> WriteResult<()> { unimplemented!() } -pub fn write_to_file

(path: P, content: &str) -> Result<(), EntryWriteError> -where - P: AsRef, -{ +/// Write a slice of bytes to a file, overwriting the existing file if it already exists. +#[must_use] +pub fn write_to_file(path: impl AsRef, content: impl AsRef<[u8]>) -> WriteResult<()> { make_parent_directory(&path)?; - std::fs::write(&path, content)?; - Ok(()) + let write_result = std::fs::write(&path, content); + Ok(io_result_to_write_result(write_result, path.as_ref())?) } -- cgit v1.2.3-70-g09d2