Skip to content

Commit b5b95ee

Browse files
committed
tests: replace Unix sockets with pipes in special file test
A Nix CVE fix relocated builds from `/tmp` to `/nix/var/nix/builds`, which means these now exceed Darwin’s path length limit for Unix sockets. Unfortunately, `std::os::unix::fs::mkfifo` is unstable, so we have to add a `nix` dependency here (or else do more manual `unsafe` conversion). We already pull it in indirectly, though.
1 parent bc81ca5 commit b5b95ee

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interim = { version = "0.2.1", features = ["chrono_0_4"] }
6666
itertools = "0.14.0"
6767
libc = { version = "0.2.174" }
6868
maplit = "1.0.2"
69+
nix = "0.29.0"
6970
num_cpus = "1.17.0"
7071
once_cell = "1.21.3"
7172
os_pipe = "1.2.2"

lib/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ test-case = { workspace = true }
9393
testutils = { workspace = true }
9494
tokio = { workspace = true, features = ["full"] }
9595

96+
[target.'cfg(unix)'.dev-dependencies]
97+
# TODO: Remove once `std::os::unix::fs::mkfifo` is stable.
98+
nix = { workspace = true }
99+
96100
[features]
97101
default = ["git"]
98102
git = ["dep:gix"]

lib/tests/test_local_working_copy.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#[cfg(unix)]
1616
use std::os::unix::fs::PermissionsExt as _;
17-
#[cfg(unix)]
18-
use std::os::unix::net::UnixListener;
1917
use std::path::Path;
2018
use std::path::PathBuf;
2119
use std::sync::Arc;
@@ -1035,11 +1033,16 @@ fn test_snapshot_special_file() {
10351033
let file2_path = repo_path("file2");
10361034
let file2_disk_path = file2_path.to_fs_path_unchecked(&workspace_root);
10371035
std::fs::write(file2_disk_path, "contents".as_bytes()).unwrap();
1038-
let socket_disk_path = workspace_root.join("socket");
1039-
UnixListener::bind(&socket_disk_path).unwrap();
1036+
let fifo_disk_path = workspace_root.join("fifo");
1037+
// TODO: Use `std::os::unix::fs::mkfifo` once stable.
1038+
nix::unistd::mkfifo(
1039+
&fifo_disk_path,
1040+
nix::sys::stat::Mode::S_IRUSR | nix::sys::stat::Mode::S_IWUSR,
1041+
)
1042+
.unwrap();
10401043
// Test the setup
1041-
assert!(socket_disk_path.exists());
1042-
assert!(!socket_disk_path.is_file());
1044+
assert!(fifo_disk_path.exists());
1045+
assert!(!fifo_disk_path.is_file());
10431046

10441047
// Snapshot the working copy with the socket file
10451048
let mut locked_ws = ws.start_working_copy_mutation().unwrap();
@@ -1062,7 +1065,12 @@ fn test_snapshot_special_file() {
10621065

10631066
// Replace a regular file by a socket and snapshot the working copy again
10641067
std::fs::remove_file(&file1_disk_path).unwrap();
1065-
UnixListener::bind(&file1_disk_path).unwrap();
1068+
// TODO: Use `std::os::unix::fs::mkfifo` once stable.
1069+
nix::unistd::mkfifo(
1070+
&file1_disk_path,
1071+
nix::sys::stat::Mode::S_IRUSR | nix::sys::stat::Mode::S_IWUSR,
1072+
)
1073+
.unwrap();
10661074
let tree = test_workspace.snapshot().unwrap();
10671075
// Only the regular file should be in the tree
10681076
assert_eq!(

0 commit comments

Comments
 (0)