-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Exclude the target directory from backups using CACHEDIR.TAG #8378
Conversation
This patch follows the lead of rust-lang#4386 (which excludes target directories from Time Machine backups) and is motived by the same reasons listen in rust-lang#3884. CACHEDIR.TAG is an OS-independent mechanism supported by Borg, restic, GNU Tar and other backup/archiving solutions. See https://bford.info/cachedir/ for more information about the specification. This has been discussed in Rust Internals earlier this year[1] and it seems like it's an uncontroversial improvement so I went ahead with the patch. [1] https://internals.rust-lang.org/t/pre-rfc-put-cachedir-tag-into-target/12262/11
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Josh you were active on the internals thread: |
Ah yeah, I forgot to mention Josh explicitly, thanks for that. Also I'll rerun the test suite locally and address the build failures. |
I'm unable to reproduce the |
I also have the following concern: I imagine it's possible for cargo to be interrupted right after creating the target directory (whether we consider if !dest.as_path_unlocked().exists() {
dest.create_dir()?;
exclude_from_backups(dest.as_path_unlocked());
} would not trigger on the re-run and the directory would be included in backups until next working directory cleanup/target directory recreation. However small the chance of that is I'm wondering if maybe the |
I can see a straightforward way to fix that. When creating a new target directory:
|
Yeah I decided against it before but you convinced me to give it a shot – I pushed a commit that does just what you suggest. |
FWIW I had a quick look around and the only other open source backup solution I found (I only looked at open source ones) that supports this out of the box is attic, others (like rsync and bacula) support this in a exclude-directory-if-a-file-named-like-this-exists-in-it way – so while my initial commit message may be technically correct I wanted the above to be known, I don't want to oversell this solution on false premises. |
@jstasiak duplicity similarly has an |
Could you please add a test that confirms this creates |
Sure, done. I wasn't sure if `testsuite/build.rs`` was the right place for them but I didn't find a better one, let me know if it's ok. |
This commit changed things a bit: 6263d72.
I'm still wondering whether this shouldn't maybe cover the whole
|
@jstasiak I think it would be appropriate to add a If we were doing this from day 1, I would suggest covering all of |
Ok, fair. I added a patch to add this to If this is accepted I'll create a patch for RLS to match this. |
I think it is reasonable to consider marking the entire I'm pretty certain we do not want to include the Also, I'd prefer to avoid adding additional tests for each command. I think it's fine to just have a single test that runs multiple commands as needed. (Each additional test has a cost, so it helps to avoid adding too many unless necessary.) (I'm amused to see Josh has experience with this from 9 years ago.) |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
📌 Commit 5f2ba2b has been approved by |
☀️ Test successful - checks-azure |
Thank you all for the comments and patience, I'm really glad this managed to land. :) I'm still slightly unsure if maybe errors on writing to Thanks again! |
Update cargo, rls ## cargo 14 commits in c26576f9adddd254b3dd63aecba176434290a9f6..fede83ccf973457de319ba6fa0e36ead454d2e20 2020-06-23 16:21:21 +0000 to 2020-07-02 21:51:34 +0000 - Fix overflow error on 32-bit. (rust-lang/cargo#8446) - Exclude the target directory from backups using CACHEDIR.TAG (rust-lang/cargo#8378) - CONTRIBUTING.md: Link to Zulip rather than Discord (rust-lang/cargo#8436) - Update built-in help for features (rust-lang/cargo#8433) - Update core-foundation requirement from 0.7.0 to 0.9.0 (rust-lang/cargo#8432) - Parse `# env-dep` directives in dep-info files (rust-lang/cargo#8421) - Move string interning to util (rust-lang/cargo#8419) - Expose built cdylib artifacts in the Compilation structure (rust-lang/cargo#8418) - Remove unused serde_derive dependency from the crates.io crate (rust-lang/cargo#8416) - Remove unused remove_dir_all dependency (rust-lang/cargo#8412) - Improve git error messages a bit (rust-lang/cargo#8409) - Improve the description of Config.home_path (rust-lang/cargo#8408) - Improve support for non-`master` main branches (rust-lang/cargo#8364) - Document that OUT_DIR in JSON messages is an absolute path (rust-lang/cargo#8403) ## rls 2020-06-19 15:36:00 +0200 to 2020-06-30 23:34:52 +0200 - Update cargo (rust-lang/rls#1686)
Cargo excludes newly created target/ from backups[1]. This is an attempt to make rls interact nicely with it and prevent build directories like target/debug/ and target/release/ from polluting backups. The cargo dependency is updated to the latest cargo in order for the paths::create_dir_all_excluded_from_backups_atomic() function to become available to rls. [1] rust-lang/cargo#8378
"target" is Cargo's (Rust's) build directory. Cargo recently learned to put CACHEDIR.TAG in those directories[1], so I no longer need to exclude them manually. 1. rust-lang/cargo#8378
This follows rust-langGH-8378 which applies this technique to target directories inside projects. With the patch two large-ish throwaway directories are also excluded from backups. I decided against excluding $CARGO_HOME/bin or $CARGO_HOME as a whole, because there may be important binaries needed by a user to run their system and there are credentials in the credentials file – I'm happy to simplify this and exclude whole $CARGO_HOME though.
This patch follows the lead of #4386 (which excludes target directories
from Time Machine backups) and is motived by the same reasons listen
in #3884. CACHEDIR.TAG is an OS-independent mechanism supported by Borg,
restic, GNU Tar and other backup/archiving solutions.
See https://bford.info/cachedir/ for more information about the
specification. This has been discussed in Rust Internals earlier this
year[1] and it seems like it's an uncontroversial improvement so I went
ahead with the patch.
One thing I'm wondering is whether this should maybe cover the whole main target directory (right now it applies to
target/debug
,target/release
etc. but not to target root).[1] https://internals.rust-lang.org/t/pre-rfc-put-cachedir-tag-into-target/12262/11