Skip to content

Commit

Permalink
fix: assure possibly blocking non-files (like FIFOs) won't be picked …
Browse files Browse the repository at this point in the history
…up for publishing.

This would otherwise cause the publish to hang.
  • Loading branch information
Byron committed Dec 23, 2024
1 parent cfa27f2 commit db6ea4a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,11 @@ fn list_files_gix(
.filter(|res| {
// Don't include Cargo.lock if it is untracked. Packaging will
// generate a new one as needed.
// Also don't include untrackable directory entries, like FIFOs.
res.as_ref().map_or(true, |item| {
!(item.entry.status == Status::Untracked && item.entry.rela_path == "Cargo.lock")
item.entry.disk_kind != Some(gix::dir::entry::Kind::Untrackable)
&& !(item.entry.status == Status::Untracked
&& item.entry.rela_path == "Cargo.lock")
})
})
.map(|res| res.map(|item| (item.entry.rela_path, item.entry.disk_kind)))
Expand Down Expand Up @@ -751,7 +754,8 @@ fn list_files_walk(
for entry in walkdir {
match entry {
Ok(entry) => {
if !entry.file_type().is_dir() {
let file_type = entry.file_type();
if file_type.is_file() || file_type.is_symlink() {
ret.push(entry.into_path());
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4221,3 +4221,34 @@ src/lib.rs
"#]])
.run();
}

#[cargo_test]
#[cfg(unix)]
fn simple_with_fifo() {
let git_project = git::new("foo", |project| {
project
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
"#,
)
.file("src/main.rs", "fn main() {}")
});

std::process::Command::new("mkfifo")
.current_dir(git_project.root())
.arg(git_project.root().join("blocks-when-read"))
.status()
.expect("a FIFO can be created");

// Avoid actual blocking even in case of failure, assuming that what it lists here
// would also be read eventually.
git_project
.cargo("package -vl")
.with_stdout_does_not_contain("blocks-when-read")
.run();
}
29 changes: 29 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6873,3 +6873,32 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
"#]])
.run();
}

#[cargo_test]
#[cfg(unix)]
fn simple_with_fifo() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

std::process::Command::new("mkfifo")
.current_dir(p.root())
.arg(p.root().join("blocks-when-read"))
.status()
.expect("a FIFO can be created");

// Avoid actual blocking even in case of failure, assuming that what it lists here
// would also be read eventually.
p.cargo("package -vl")
.with_stdout_does_not_contain("blocks-when-read")
.run();
}

0 comments on commit db6ea4a

Please sign in to comment.