summaryrefslogtreecommitdiffstats
path: root/crates/common/tedge_utils
diff options
context:
space:
mode:
authorRina Fujino <18257209+rina23q@users.noreply.github.com>2022-05-19 17:35:57 +0200
committerRina Fujino <18257209+rina23q@users.noreply.github.com>2022-05-19 17:35:57 +0200
commit840c42b2d7fc320ff7ce3366d805bae249979bd2 (patch)
tree17a7e07340aa29e8a8cc3c3f500076d98554ff37 /crates/common/tedge_utils
parent5733a4aed1f980089caf38a39d96f5d50ec9151b (diff)
--init creates an example c8y-configuration-plugin.toml
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Diffstat (limited to 'crates/common/tedge_utils')
-rw-r--r--crates/common/tedge_utils/src/file.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/common/tedge_utils/src/file.rs b/crates/common/tedge_utils/src/file.rs
index 663ecde1..6b714750 100644
--- a/crates/common/tedge_utils/src/file.rs
+++ b/crates/common/tedge_utils/src/file.rs
@@ -58,6 +58,12 @@ pub fn create_file_with_user_group(
Ok(())
}
+pub fn create_file_with_mode(file: &str, mode: u32) -> Result<(), FileError> {
+ let perm_entry = PermissionEntry::new(None, None, Some(mode));
+ let () = perm_entry.create_file(Path::new(file))?;
+ Ok(())
+}
+
#[derive(Debug, PartialEq, Eq, Default, Clone)]
pub struct PermissionEntry {
pub user: Option<String>,
@@ -91,7 +97,7 @@ impl PermissionEntry {
Ok(())
}
- pub fn create_directory(&self, dir: &Path) -> Result<(), FileError> {
+ fn create_directory(&self, dir: &Path) -> Result<(), FileError> {
match fs::create_dir(dir) {
Ok(_) => {
let () = self.apply(dir)?;
@@ -105,7 +111,7 @@ impl PermissionEntry {
}
}
- pub fn create_file(&self, file: &Path) -> Result<(), FileError> {
+ fn create_file(&self, file: &Path) -> Result<(), FileError> {
match File::create(file) {
Ok(_) => {
let () = self.apply(file)?;
@@ -141,11 +147,7 @@ fn change_user_and_group(file: &Path, user: &str, group: &str) -> Result<(), Fil
// if user and group are same as existing, then do not change
if (ud != uid) && (gd != gid) {
- chown(
- file,
- Some(Uid::from_raw(ud.into())),
- Some(Gid::from_raw(gd.into())),
- )?;
+ chown(file, Some(Uid::from_raw(ud)), Some(Gid::from_raw(gd)))?;
}
Ok(())