Skip to content

Commit f34b086

Browse files
committed
Exclude whole target/ from backups
This is following the discussion on GitHub. The doc tests are no longer necessary because Layout::new() creates CACHEDIR.TAG directly in target root, no doc-specific code is necessary anymore.
1 parent 1b5f749 commit f34b086

File tree

5 files changed

+10
-70
lines changed

5 files changed

+10
-70
lines changed

src/cargo/core/compiler/layout.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ impl Layout {
151151
// here. Use this opportunity to exclude it from backups as well if the
152152
// system supports it since this is a freshly created folder.
153153
//
154-
paths::create_dir_all_excluded_from_backups_atomic(dest.as_path_unlocked())?;
154+
paths::create_dir_all_excluded_from_backups_atomic(root.as_path_unlocked())?;
155+
// Now that the excluded from backups target root is created we can create the
156+
// actual destination (sub)subdirectory.
157+
paths::create_dir_all(dest.as_path_unlocked())?;
155158

156159
// For now we don't do any more finer-grained locking on the artifact
157160
// directory, so just lock the entire thing for the duration of this

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
557557
// Create the documentation directory ahead of time as rustdoc currently has
558558
// a bug where concurrent invocations will race to create this directory if
559559
// it doesn't already exist.
560-
paths::create_dir_all_excluded_from_backups_atomic(&doc_dir)?;
560+
paths::create_dir_all(&doc_dir)?;
561561

562562
rustdoc.arg("-o").arg(doc_dir);
563563

tests/testsuite/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,7 +4998,7 @@ fn target_directory_is_excluded_from_backups() {
49984998
.build();
49994999

50005000
p.cargo("build").run();
5001-
let cachedir_tag = p.target_debug_dir().join("CACHEDIR.TAG");
5001+
let cachedir_tag = p.build_dir().join("CACHEDIR.TAG");
50025002
assert!(cachedir_tag.is_file());
50035003
assert!(fs::read_to_string(&cachedir_tag)
50045004
.unwrap()
@@ -5012,7 +5012,7 @@ fn target_directory_is_not_excluded_from_backups_if_it_already_exists() {
50125012
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
50135013
.build();
50145014

5015-
let cachedir_tag = p.target_debug_dir().join("CACHEDIR.TAG");
5015+
let cachedir_tag = p.build_dir().join("CACHEDIR.TAG");
50165016
p.cargo("build").run();
50175017
fs::remove_file(&cachedir_tag).unwrap();
50185018
p.cargo("build").run();

tests/testsuite/clean.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ fn clean_verbose() {
293293
[REMOVING] [..]
294294
[REMOVING] [..]
295295
[REMOVING] [..]
296-
[REMOVING] [..]
297296
",
298297
)
299298
.run();
@@ -433,7 +432,9 @@ fn assert_all_clean(build_dir: &Path) {
433432
}) {
434433
let entry = entry.unwrap();
435434
let path = entry.path();
436-
if let ".rustc_info.json" | ".cargo-lock" = path.file_name().unwrap().to_str().unwrap() {
435+
if let ".rustc_info.json" | ".cargo-lock" | "CACHEDIR.TAG" =
436+
path.file_name().unwrap().to_str().unwrap()
437+
{
437438
continue;
438439
}
439440
if path.is_symlink() || path.is_file() {

tests/testsuite/doc.rs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,67 +1551,3 @@ fn crate_versions_flag_is_overridden() {
15511551
.run();
15521552
asserts(output_documentation());
15531553
}
1554-
1555-
#[cargo_test]
1556-
fn target_directory_is_excluded_from_backups() {
1557-
let p = project()
1558-
.file(
1559-
"Cargo.toml",
1560-
r#"
1561-
[package]
1562-
name = "foo"
1563-
version = "0.0.1"
1564-
authors = []
1565-
build = "build.rs"
1566-
"#,
1567-
)
1568-
.file("build.rs", "fn main() {}")
1569-
.file("src/lib.rs", "pub fn foo() {}")
1570-
.build();
1571-
1572-
p.cargo("doc")
1573-
.with_stderr(
1574-
"\
1575-
[..] foo v0.0.1 ([CWD])
1576-
[..] foo v0.0.1 ([CWD])
1577-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1578-
",
1579-
)
1580-
.run();
1581-
let cachedir_tag = p.root().join("target/doc/CACHEDIR.TAG");
1582-
assert!(cachedir_tag.is_file());
1583-
assert!(fs::read_to_string(&cachedir_tag)
1584-
.unwrap()
1585-
.starts_with("Signature: 8a477f597d28d172789f06886806bc55"));
1586-
}
1587-
1588-
#[cargo_test]
1589-
fn target_directory_is_not_excluded_from_backups_if_it_already_exists() {
1590-
let p = project()
1591-
.file(
1592-
"Cargo.toml",
1593-
r#"
1594-
[package]
1595-
name = "foo"
1596-
version = "0.0.1"
1597-
authors = []
1598-
build = "build.rs"
1599-
"#,
1600-
)
1601-
.file("build.rs", "fn main() {}")
1602-
.file("src/lib.rs", "pub fn foo() {}")
1603-
.build();
1604-
fs::create_dir_all(p.root().join("target/doc")).unwrap();
1605-
1606-
p.cargo("doc")
1607-
.with_stderr(
1608-
"\
1609-
[..] foo v0.0.1 ([CWD])
1610-
[..] foo v0.0.1 ([CWD])
1611-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1612-
",
1613-
)
1614-
.run();
1615-
let cachedir_tag = p.root().join("target/doc/CACHEDIR.TAG");
1616-
assert!(!&cachedir_tag.is_file());
1617-
}

0 commit comments

Comments
 (0)