Skip to content

Commit 7a7d2aa

Browse files
committed
Auto merge of #6973 - exphp-forks:check-directory, r=ehuss
cargo package: detect new empty directories Detect the creation of directories in a build script, which is currently a very tempting workaround for the fact that a crate built from a package will be missing any empty directories. Maybe it would be better to only include directories in the map of hashes if they are completely empty. The removal of a directory that is initially empty cannot be tested because, as stated above, a crate built from a package will not *have* any empty directories. Closes #6931.
2 parents 5218d04 + aef2a9c commit 7a7d2aa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/cargo/ops/cargo_package.rs

+3
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ fn hash_all(path: &Path) -> CargoResult<HashMap<PathBuf, u64>> {
665665
} else if file_type.is_symlink() {
666666
let hash = util::hex::hash_u64(&fs::read_link(entry.path())?);
667667
result.insert(entry.path().to_path_buf(), hash);
668+
} else if file_type.is_dir() {
669+
let hash = util::hex::hash_u64(&());
670+
result.insert(entry.path().to_path_buf(), hash);
668671
}
669672
}
670673
Ok(result)

tests/testsuite/package.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ Caused by:
10051005
fn do_not_package_if_src_was_modified() {
10061006
let p = project()
10071007
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
1008-
.file("foo.txt", "")
1008+
.file("dir/foo.txt", "")
10091009
.file("bar.txt", "")
10101010
.file(
10111011
"build.rs",
@@ -1016,8 +1016,10 @@ fn do_not_package_if_src_was_modified() {
10161016
fs::write("src/generated.txt",
10171017
"Hello, world of generated files."
10181018
).expect("failed to create file");
1019-
fs::remove_file("foo.txt").expect("failed to remove");
1019+
fs::remove_file("dir/foo.txt").expect("failed to remove file");
1020+
fs::remove_dir("dir").expect("failed to remove dir");
10201021
fs::write("bar.txt", "updated content").expect("failed to update");
1022+
fs::create_dir("new-dir").expect("failed to create dir");
10211023
}
10221024
"#,
10231025
)
@@ -1033,8 +1035,10 @@ Caused by:
10331035
Source directory was modified by build.rs during cargo publish. \
10341036
Build scripts should not modify anything outside of OUT_DIR.
10351037
Changed: [CWD]/target/package/foo-0.0.1/bar.txt
1036-
Added: [CWD]/target/package/foo-0.0.1/src/generated.txt
1037-
Removed: [CWD]/target/package/foo-0.0.1/foo.txt
1038+
Added: [CWD]/target/package/foo-0.0.1/new-dir
1039+
<tab>[CWD]/target/package/foo-0.0.1/src/generated.txt
1040+
Removed: [CWD]/target/package/foo-0.0.1/dir
1041+
<tab>[CWD]/target/package/foo-0.0.1/dir/foo.txt
10381042
10391043
To proceed despite this, pass the `--no-verify` flag.",
10401044
)

0 commit comments

Comments
 (0)