Skip to content

Commit

Permalink
Merge pull request #2744 from reubenmiller/refactor-use-unix-fs-metad…
Browse files Browse the repository at this point in the history
…ataext

refactor: use unix::fs::MetadataExt over linux variant to improve unix compatibility
  • Loading branch information
reubenmiller authored Mar 4, 2024
2 parents a75bbf5 + 00aaeb1 commit 52b388e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/common/tedge_utils/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nix::unistd::*;
use std::fs;
use std::io;
use std::io::Write;
use std::os::linux::fs::MetadataExt;
use std::os::unix::fs::MetadataExt;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -355,15 +355,15 @@ pub fn change_user_and_group(file: &Path, user: &str, group: &str) -> Result<(),
.map(|u| u.uid())
.ok_or_else(|| FileError::UserNotFound { user: user.into() })?;

let uid = get_metadata(Path::new(file))?.st_uid();
let uid = get_metadata(Path::new(file))?.uid();

let gd = get_group_by_name(group)
.map(|g| g.gid())
.ok_or_else(|| FileError::GroupNotFound {
group: group.into(),
})?;

let gid = get_metadata(Path::new(file))?.st_gid();
let gid = get_metadata(Path::new(file))?.gid();

// if user and group are same as existing, then do not change
if (ud != uid) && (gd != gid) {
Expand All @@ -383,7 +383,7 @@ fn change_user(file: &Path, user: &str) -> Result<(), FileError> {
.map(|u| u.uid())
.ok_or_else(|| FileError::UserNotFound { user: user.into() })?;

let uid = get_metadata(Path::new(file))?.st_uid();
let uid = get_metadata(Path::new(file))?.uid();

// if user is same as existing, then do not change
if ud != uid {
Expand All @@ -403,7 +403,7 @@ fn change_group(file: &Path, group: &str) -> Result<(), FileError> {
group: group.into(),
})?;

let gid = get_metadata(Path::new(file))?.st_gid();
let gid = get_metadata(Path::new(file))?.gid();

// if group is same as existing, then do not change
if gd != gid {
Expand Down

0 comments on commit 52b388e

Please sign in to comment.