From aef2a9cbc47479d0607bc56eb1e506f734c03058 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Mon, 20 May 2019 21:11:34 -0400 Subject: [PATCH] cargo package: detect new empty directories --- src/cargo/ops/cargo_package.rs | 3 +++ tests/testsuite/package.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 609f9bd69de..cb60567b324 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -665,6 +665,9 @@ fn hash_all(path: &Path) -> CargoResult> { } else if file_type.is_symlink() { let hash = util::hex::hash_u64(&fs::read_link(entry.path())?); result.insert(entry.path().to_path_buf(), hash); + } else if file_type.is_dir() { + let hash = util::hex::hash_u64(&()); + result.insert(entry.path().to_path_buf(), hash); } } Ok(result) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index ad1287d1e13..0fe80f31ee7 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1005,7 +1005,7 @@ Caused by: fn do_not_package_if_src_was_modified() { let p = project() .file("src/main.rs", r#"fn main() { println!("hello"); }"#) - .file("foo.txt", "") + .file("dir/foo.txt", "") .file("bar.txt", "") .file( "build.rs", @@ -1016,8 +1016,10 @@ fn do_not_package_if_src_was_modified() { fs::write("src/generated.txt", "Hello, world of generated files." ).expect("failed to create file"); - fs::remove_file("foo.txt").expect("failed to remove"); + fs::remove_file("dir/foo.txt").expect("failed to remove file"); + fs::remove_dir("dir").expect("failed to remove dir"); fs::write("bar.txt", "updated content").expect("failed to update"); + fs::create_dir("new-dir").expect("failed to create dir"); } "#, ) @@ -1033,8 +1035,10 @@ Caused by: Source directory was modified by build.rs during cargo publish. \ Build scripts should not modify anything outside of OUT_DIR. Changed: [CWD]/target/package/foo-0.0.1/bar.txt -Added: [CWD]/target/package/foo-0.0.1/src/generated.txt -Removed: [CWD]/target/package/foo-0.0.1/foo.txt +Added: [CWD]/target/package/foo-0.0.1/new-dir +[CWD]/target/package/foo-0.0.1/src/generated.txt +Removed: [CWD]/target/package/foo-0.0.1/dir +[CWD]/target/package/foo-0.0.1/dir/foo.txt To proceed despite this, pass the `--no-verify` flag.", )