Skip to content

Commit 8721d52

Browse files
authored
fix: assure possibly blocking non-files (like FIFOs) won't be picked up for publishing. (#14977)
Follow-up of #14975, related to GitoxideLabs/gitoxide#1629. This would otherwise cause the publish to hang if it tries to read from a fifo.
2 parents 0c157e0 + af92c44 commit 8721d52

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

src/cargo/sources/path.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,11 @@ fn list_files_gix(
626626
.filter(|res| {
627627
// Don't include Cargo.lock if it is untracked. Packaging will
628628
// generate a new one as needed.
629+
// Also don't include untrackable directory entries, like FIFOs.
629630
res.as_ref().map_or(true, |item| {
630-
!(item.entry.status == Status::Untracked && item.entry.rela_path == "Cargo.lock")
631+
item.entry.disk_kind != Some(gix::dir::entry::Kind::Untrackable)
632+
&& !(item.entry.status == Status::Untracked
633+
&& item.entry.rela_path == "Cargo.lock")
631634
})
632635
})
633636
.map(|res| res.map(|item| (item.entry.rela_path, item.entry.disk_kind)))
@@ -751,7 +754,8 @@ fn list_files_walk(
751754
for entry in walkdir {
752755
match entry {
753756
Ok(entry) => {
754-
if !entry.file_type().is_dir() {
757+
let file_type = entry.file_type();
758+
if file_type.is_file() || file_type.is_symlink() {
755759
ret.push(entry.into_path());
756760
}
757761
}

tests/testsuite/git.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,3 +4221,41 @@ src/lib.rs
42214221
"#]])
42224222
.run();
42234223
}
4224+
4225+
#[cargo_test]
4226+
#[cfg(unix)]
4227+
fn simple_with_fifo() {
4228+
let git_project = git::new("foo", |project| {
4229+
project
4230+
.file(
4231+
"Cargo.toml",
4232+
r#"
4233+
[package]
4234+
name = "foo"
4235+
version = "0.1.0"
4236+
edition = "2015"
4237+
"#,
4238+
)
4239+
.file("src/main.rs", "fn main() {}")
4240+
});
4241+
4242+
std::process::Command::new("mkfifo")
4243+
.current_dir(git_project.root())
4244+
.arg(git_project.root().join("blocks-when-read"))
4245+
.status()
4246+
.expect("a FIFO can be created");
4247+
4248+
// Avoid actual blocking even in case of failure, assuming that what it lists here
4249+
// would also be read eventually.
4250+
git_project
4251+
.cargo("package -l")
4252+
.with_stdout_data(str![[r#"
4253+
.cargo_vcs_info.json
4254+
Cargo.lock
4255+
Cargo.toml
4256+
Cargo.toml.orig
4257+
src/main.rs
4258+
4259+
"#]])
4260+
.run();
4261+
}

tests/testsuite/package.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6873,3 +6873,38 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
68736873
"#]])
68746874
.run();
68756875
}
6876+
6877+
#[cargo_test]
6878+
#[cfg(unix)]
6879+
fn simple_with_fifo() {
6880+
let p = project()
6881+
.file(
6882+
"Cargo.toml",
6883+
r#"
6884+
[package]
6885+
name = "foo"
6886+
version = "0.1.0"
6887+
edition = "2015"
6888+
"#,
6889+
)
6890+
.file("src/main.rs", "fn main() {}")
6891+
.build();
6892+
6893+
std::process::Command::new("mkfifo")
6894+
.current_dir(p.root())
6895+
.arg(p.root().join("blocks-when-read"))
6896+
.status()
6897+
.expect("a FIFO can be created");
6898+
6899+
// Avoid actual blocking even in case of failure, assuming that what it lists here
6900+
// would also be read eventually.
6901+
p.cargo("package -l")
6902+
.with_stdout_data(str![[r#"
6903+
Cargo.lock
6904+
Cargo.toml
6905+
Cargo.toml.orig
6906+
src/main.rs
6907+
6908+
"#]])
6909+
.run();
6910+
}

0 commit comments

Comments
 (0)