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

Add a cache dir tag when creating a target directory. #836

Merged
merged 1 commit into from
Jun 22, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- #836 - write a `CACHEDIR.TAG` when creating the target directory, similar to `cargo`.
- #804 - allow usage of env `CARGO_BUILD_TARGET` as an alias for `CROSS_BUILD_TARGET`
- #792 - fixed container-in-container support when using podman.
- #781 - ensure `target.$(...)` config options override `build` ones.
Expand Down
20 changes: 19 additions & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Directories {
// otherwise `docker` will create them but they will be owned by `root`
fs::create_dir(&cargo).ok();
fs::create_dir(&xargo).ok();
fs::create_dir(&target).ok();
create_target_dir(target)?;

let cargo = mount_finder.find_mount_path(cargo);
let xargo = mount_finder.find_mount_path(xargo);
Expand Down Expand Up @@ -111,6 +111,24 @@ impl Directories {
}
}

const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cross.
# For information about cache directory tags see https://bford.info/cachedir/";

fn create_target_dir(path: &Path) -> Result<()> {
// cargo creates all paths to the target directory, and writes
// a cache dir tag only if the path doesn't previously exist.
if !path.exists() {
fs::create_dir_all(&path)?;
fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(&path.join("CACHEDIR.TAG"))?
.write_all(CACHEDIR_TAG.as_bytes())?;
}
Ok(())
}

pub fn command(engine: &Engine) -> Command {
Command::new(&engine.path)
}
Expand Down