Skip to content

feat: Create CACHEDIR.TAG file #3353

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ pub async fn store_credentials_from_project(project: &Workspace) -> miette::Resu
Ok(())
}

/// Ensure that the `.pixi/` directory exists and contains a `.gitignore` file.
/// Ensure that the `.pixi/` directory exists and contains a `.gitignore` and a `CACHEDIR.TAG` file.
/// If the directory doesn't exist, create it.
/// If the `.gitignore` file doesn't exist, create it with a '*' pattern.
/// If the `CACHEDIR.TAG` file doesn't exist, create it with the appropriate content.
async fn ensure_pixi_directory_and_gitignore(pixi_dir: &Path) -> miette::Result<()> {
let gitignore_path = pixi_dir.join(".gitignore");
let cachedir_tag_path = pixi_dir.join("CACHEDIR.TAG");

// Create the `.pixi/` directory if it doesn't exist
if !pixi_dir.exists() {
Expand All @@ -348,6 +350,21 @@ async fn ensure_pixi_directory_and_gitignore(pixi_dir: &Path) -> miette::Result<
))?;
}

// Create or check the CACHEDIR.TAG file
let cachedir_tag_content = r#"Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag automatically created by pixi.
# For information about cache directory tags see https://bford.info/cachedir/
"#;
if !cachedir_tag_path.exists() {
tokio::fs::write(&cachedir_tag_path, cachedir_tag_content)
.await
.into_diagnostic()
.wrap_err(format!(
"Failed to create CACHEDIR.TAG file at {}",
cachedir_tag_path.display()
))?;
}

Ok(())
}

Expand Down
Loading