Skip to content

Commit

Permalink
Merge pull request #5533 from habitat-sh/chroot_so_crazy
Browse files Browse the repository at this point in the history
do not root linux symlink target in fs_root to please chroot
  • Loading branch information
mwrock authored Aug 31, 2018
2 parents f4a1d78 + 156044d commit f2dd4ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
41 changes: 23 additions & 18 deletions components/hab/src/command/pkg/binlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ pub fn start(
dst_path.display()
))?;
let pkg_install = PackageInstall::load(&ident, Some(fs_root_path))?;
let src = match hfs::find_command_in_pkg(binary, &pkg_install, fs_root_path)? {
Some(c) => fs_root_path.join(c.strip_prefix("/")?),
let mut src = match hfs::find_command_in_pkg(binary, &pkg_install, fs_root_path)? {
Some(c) => c,
None => {
return Err(Error::CommandNotFoundInPkg((
pkg_install.ident().to_string(),
binary.to_string(),
)))
}
};
if cfg!(target_os = "windows") {
src = fs_root_path.join(src.strip_prefix("/")?);
}
if !dst_path.is_dir() {
ui.status(
Status::Creating,
Expand Down Expand Up @@ -271,12 +274,12 @@ mod test {
let ident = fake_bin_pkg_install("acme/cooltools", tools, rootfs.path());
let dst_path = Path::new("/opt/bin");

let rootfs_src_dir = rootfs.path().join(
hcore::fs::pkg_install_path(&ident, None::<&Path>)
.join("bin")
.strip_prefix("/")
.unwrap(),
);
let mut rootfs_src_dir = hcore::fs::pkg_install_path(&ident, None::<&Path>).join("bin");
if cfg!(target_os = "windows") {
rootfs_src_dir = rootfs
.path()
.join(rootfs_src_dir.strip_prefix("/").unwrap());
}
let rootfs_bin_dir = rootfs.path().join("opt/bin");
let force = true;

Expand Down Expand Up @@ -331,11 +334,12 @@ mod test {
let ident = fake_bin_pkg_install("acme/securetools", tools, rootfs.path());
let dst_path = Path::new("/opt/bin");

let rootfs_src_dir = rootfs.path().join(
hcore::fs::pkg_install_path(&ident, None::<&Path>)
.strip_prefix("/")
.unwrap(),
);
let mut rootfs_src_dir = hcore::fs::pkg_install_path(&ident, None::<&Path>);
if cfg!(target_os = "windows") {
rootfs_src_dir = rootfs
.path()
.join(rootfs_src_dir.strip_prefix("/").unwrap());
}
let rootfs_bin_dir = rootfs.path().join("opt/bin");
let force = true;

Expand Down Expand Up @@ -413,11 +417,12 @@ mod test {
let ident = fake_bin_pkg_install("acme/securetools", tools, rootfs.path());
let dst_path = Path::new("/opt/bin");

let rootfs_src_dir = rootfs.path().join(
hcore::fs::pkg_install_path(&ident, None::<&Path>)
.strip_prefix("/")
.unwrap(),
);
let mut rootfs_src_dir = hcore::fs::pkg_install_path(&ident, None::<&Path>);
if cfg!(target_os = "windows") {
rootfs_src_dir = rootfs
.path()
.join(rootfs_src_dir.strip_prefix("/").unwrap());
}
let rootfs_bin_dir = rootfs.path().join("opt/bin");
let force = true;

Expand Down
23 changes: 5 additions & 18 deletions components/pkg-export-docker/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,32 +905,19 @@ mod test {
.unwrap();

assert_eq!(
rootfs.path().join(
hcore::fs::pkg_install_path(base_pkgs.busybox.as_ref().unwrap(), None::<&Path>)
.join("bin/busybox")
.strip_prefix("/")
.unwrap()
),
hcore::fs::pkg_install_path(base_pkgs.busybox.as_ref().unwrap(), None::<&Path>)
.join("bin/busybox"),
rootfs.path().join("bin/busybox").read_link().unwrap(),
"busybox program is symlinked into /bin"
);
assert_eq!(
rootfs.path().join(
hcore::fs::pkg_install_path(&base_pkgs.busybox.unwrap(), None::<&Path>)
.join("bin/sh")
.strip_prefix("/")
.unwrap()
),
hcore::fs::pkg_install_path(&base_pkgs.busybox.unwrap(), None::<&Path>)
.join("bin/sh"),
rootfs.path().join("bin/sh").read_link().unwrap(),
"busybox's sh program is symlinked into /bin"
);
assert_eq!(
rootfs.path().join(
hcore::fs::pkg_install_path(&base_pkgs.hab, None::<&Path>)
.join("bin/hab")
.strip_prefix("/")
.unwrap()
),
hcore::fs::pkg_install_path(&base_pkgs.hab, None::<&Path>).join("bin/hab"),
rootfs.path().join("bin/hab").read_link().unwrap(),
"hab program is symlinked into /bin"
);
Expand Down

0 comments on commit f2dd4ee

Please sign in to comment.