Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tempfile by default #12

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.