rust/passwd: minor cleanup, switch to copy_file_at

This updates file copying to use the newer `copy_file_at` from
openat-ext.
This commit is contained in:
Luca BRUNO 2021-01-26 10:11:28 +00:00 committed by OpenShift Merge Robot
parent 86ce9ea1f5
commit 867ba1eba8

View File

@ -102,9 +102,11 @@ fn prepare_pwgrp(rootfs: &openat::Dir, merge_passwd_dir: Option<PathBuf>) -> Res
// Copy the merge's passwd/group to usr/lib (breaking hardlinks).
if let Some(ref merge_dir) = merge_passwd_dir {
let merge_file = format!("{}/{}", merge_dir.display(), &filename);
let tmp_target = format!("/proc/self/fd/{}/{}", rootfs.as_raw_fd(), &usrlib_file_tmp);
std::fs::copy(merge_file, tmp_target)?;
{
let current_root = openat::Dir::open("/")?;
let merge_file = format!("{}/{}", merge_dir.display(), &filename);
current_root.copy_file_at(&merge_file, rootfs, &usrlib_file_tmp)?;
}
rootfs.local_rename(&usrlib_file_tmp, &usrlib_file)?;
}
}