Skip to content

Commit

Permalink
fix copy_metadata perms
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Mar 15, 2024
1 parent e9c35cb commit 3c8cd95
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions helix-view/src/faccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ mod imp {
}

pub fn copy_metadata(from: &Path, to: &Path) -> anyhow::Result<()> {
let meta = std::fs::File::open(from)?.metadata()?;
let uid = meta.gid();
let gid = meta.uid();
chown(to, Some(uid), Some(gid))?;

let mut perms = meta.permissions();
let new_perms = (perms.mode() & 0o0707) | (perms.mode() & 0o07) << 3;
perms.set_mode(new_perms);
let from_meta = std::fs::metadata(from)?;
let to_meta = std::fs::metadata(to)?;
let from_gid = from_meta.gid();
let to_gid = to_meta.gid();

let mut perms = from_meta.permissions();
if from_gid != to_gid && chown(to, None, Some(from_gid)).is_err() {
let new_perms = (perms.mode() & 0o0707) | ((perms.mode() & 0o07) << 3);
perms.set_mode(new_perms);
}

std::fs::set_permissions(to, perms)?;

Expand Down Expand Up @@ -401,7 +403,7 @@ mod imp {
let sd = SecurityDescriptor::for_path(from)?;
chown(to, sd)?;

let meta = std::fs::File::open(from)?.metadata()?;
let meta = std::fs::metadata(from)?;
let perms = meta.permissions();

std::fs::set_permissions(to, perms)?;
Expand Down Expand Up @@ -435,7 +437,7 @@ mod imp {
}

pub fn copy_metadata(from: &path, to: &Path) -> std::io::Result<()> {
let meta = std::fs::File::open(from)?.metadata()?;
let meta = std::fs::metadata(from)?;
let perms = meta.permissions();
std::fs::set_permissions(to, perms)?;

Expand Down

0 comments on commit 3c8cd95

Please sign in to comment.