-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(package): exclude target/package from backups #16272
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
base: master
Are you sure you want to change the base?
Conversation
|
Should we have automated tests for this? Note that our contrib guide normally recommends creating a passing test in a commit before the fix, showing the old behavior. Then the commit with the fix updates the test so it still passes, showing the new behavior. Then the diff will show how the behavior changed. |
4d928f4 to
5bb82db
Compare
|
Looks like this needs |
Add a test that documents the current behavior where `cargo package` creates the target/package directory without excluding it from backups. The CACHEDIR.TAG file does not currently exist in the target directory, causing backup tools to include these temporary build artifacts. This test currently passes by asserting the buggy behavior (CACHEDIR.TAG does not exist). The next commit will fix the issue and update the test to verify correct behavior.
Ensure that the target directory is excluded from backups when running `cargo package` by creating a CACHEDIR.TAG file. According to the CACHEDIR.TAG specification, a tag file in a parent directory excludes all subdirectories, so tagging the target directory protects the entire tree including the package/ subdirectory and all build artifacts. This prevents temporary packaging artifacts from being included in Time Machine and other backup systems that respect CACHEDIR.TAG. The fix applies to both build_dir (which typically equals target_dir) during package creation, and to target_dir when uplifting artifacts in workspaces where they differ. Updates the test from the previous commit to verify that target/CACHEDIR.TAG now exists after running `cargo package`. Fixes rust-lang#16238
5bb82db to
d77851d
Compare
Thanks for all your help! I have did the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to update test snapshots accordingly (with env SNAPSHOTS=overwrite): https://github.com/rust-lang/cargo/actions/runs/19452875528/job/55661053577?pr=16272#step:15:4779
| // This test documents the current behavior where target directory is NOT excluded from backups. | ||
| // After the fix, this test will be updated to verify that CACHEDIR.TAG exists. | ||
| let p = project() | ||
| .file("src/main.rs", r#"fn main() { println!("hello"); }"#) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for faster test execution (avoid to binary linking)
| .file("src/main.rs", r#"fn main() { println!("hello"); }"#) | |
| .file("src/lib.rs", "") |
What does this PR try to resolve?
The target directory is not excluded from backups when created with
cargo packageorcargo publish. This causes thetarget/packagedirectory to be included in Time Machine backups on macOS and other
backup systems that respect CACHEDIR.TAG files.
The issue occurs because when
Filesystem::open()creates parentdirectories in
src/cargo/util/flock.rs:336, it usespaths::create_dir_all()instead of the backup-excluding version,bypassing the normal target directory creation logic.
This commit adds a new
create_dir_with_backup_exclusion()method toFilesystemand uses it to ensure thetarget/packagedirectory isproperly excluded from backups before creating files in it.
Fixes #16238
How to test and review this PR?
Run the following:
cargo new foo
cd foo
cargo package --allow-dirty
ls -al target/package/
Verify that
CACHEDIR.TAGnow exists intarget/package/.All existing package tests pass.