diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-06-21 07:57:15 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-08-06 09:47:01 +0200 |
commit | a9e04b8ba2bd25eb0102ba42cf8c8d05e7d24250 (patch) | |
tree | 2ed9e35f526560b20fcac3226778117fdb5a432e /crates/common/tedge_utils/src/file.rs | |
parent | d337c33adf8fecc4a49845a9b6a47c9f57aa05d2 (diff) |
Relax interface of file helper functions
This patch relaxes the interface of the file helper functions by
allowing `impl AsRef<Path>` for creating file/directory pathes.
This results in a less narrow interface, as now the functions can be
used with Path, String, &str...
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/common/tedge_utils/src/file.rs')
-rw-r--r-- | crates/common/tedge_utils/src/file.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/common/tedge_utils/src/file.rs b/crates/common/tedge_utils/src/file.rs index 1ca804f9..7fc1c1ab 100644 --- a/crates/common/tedge_utils/src/file.rs +++ b/crates/common/tedge_utils/src/file.rs @@ -34,29 +34,29 @@ pub enum FileError { } pub fn create_directory_with_user_group( - dir: &str, + dir: impl AsRef<Path>, user: &str, group: &str, mode: u32, ) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(Some(user.into()), Some(group.into()), Some(mode)); - perm_entry.create_directory(Path::new(dir)) + perm_entry.create_directory(dir.as_ref()) } -pub fn create_directory_with_mode(dir: &str, mode: u32) -> Result<(), FileError> { +pub fn create_directory_with_mode(dir: impl AsRef<Path>, mode: u32) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(None, None, Some(mode)); - perm_entry.create_directory(Path::new(dir)) + perm_entry.create_directory(dir.as_ref()) } pub fn create_file_with_user_group( - file: &str, + file: impl AsRef<Path>, user: &str, group: &str, mode: u32, default_content: Option<&str>, ) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(Some(user.into()), Some(group.into()), Some(mode)); - perm_entry.create_file(Path::new(file), default_content) + perm_entry.create_file(file.as_ref(), default_content) } #[derive(Debug, PartialEq, Eq, Default, Clone)] |