Skip to content

Commit

Permalink
Use tempfile by default
Browse files Browse the repository at this point in the history
Per discussion this crate is widely used and there's
no reason to carry even a small reimplementation.
  • Loading branch information
cgwalters committed Oct 19, 2024
1 parent 668b386 commit ce86ecc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ rand = "0.8.5"
rustix = { version = "0.38.37", features = ["fs", "mount", "process"] }
sha2 = "0.10.8"
tar = "0.4.42"
tempfile = "3.13.0"
zstd = "0.13.2"

[dev-dependencies]
tempfile = "3.13.0"

[profile.dev.package.sha2]
# this is *really* slow otherwise
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ pub mod mount;
pub mod oci;
pub mod repository;
pub mod splitstream;
pub mod tmpdir;
15 changes: 6 additions & 9 deletions src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use rustix::mount::{
unmount,
};

use crate::{
fsverity,
tmpdir,
};
use crate::fsverity;

struct FsHandle {
pub fd: OwnedFd,
Expand Down Expand Up @@ -58,21 +55,21 @@ impl Drop for FsHandle {
}

struct TmpMount {
pub dir: tmpdir::TempDir,
pub dir: tempfile::TempDir,
}

impl TmpMount {
pub fn mount(fs: BorrowedFd) -> Result<TmpMount> {
let tmp = tmpdir::TempDir::new()?;
let tmp = tempfile::TempDir::new()?;
let mnt = fsmount(fs, FsMountFlags::FSMOUNT_CLOEXEC, MountAttrFlags::empty())?;
move_mount(mnt.as_fd(), "", rustix::fs::CWD, &tmp.path, MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH)?;
move_mount(mnt.as_fd(), "", rustix::fs::CWD, tmp.path(), MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH)?;
Ok(TmpMount { dir: tmp })
}
}

impl Drop for TmpMount {
fn drop(&mut self) {
unmount(&self.dir.path, UnmountFlags::DETACH)
unmount(self.dir.path(), UnmountFlags::DETACH)
.expect("umount(MNT_DETACH) failed");
}
}
Expand All @@ -92,7 +89,7 @@ pub fn mount_fd<F: AsFd>(image: F, basedir: &Path, mountpoint: &str) -> Result<(

// unfortunately we can't do this via the fd: we need a tmpdir mountpoint
let tmp = TmpMount::mount(erofs.as_fd())?; // NB: must live until the "create" operation
fsconfig_set_string(overlayfs.as_fd(), "lowerdir+", &tmp.dir.path)?;
fsconfig_set_string(overlayfs.as_fd(), "lowerdir+", tmp.dir.path())?;
fsconfig_set_string(overlayfs.as_fd(), "datadir+", basedir)?;
fsconfig_create(overlayfs.as_fd())?;

Expand Down
35 changes: 0 additions & 35 deletions src/tmpdir.rs

This file was deleted.

0 comments on commit ce86ecc

Please sign in to comment.