From 2c9c7397321975295efb19a76c19b375ac603bcc Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 24 Oct 2026 16:42:41 +0300 Subject: [PATCH] Make an_unwritable_path_fails_at_once hold for root The test started a recording at /nonexistent-root-dir/x/clip.webm and expected an error. Recorder::start creates the missing parent directories, which a regular user cannot do below / but root can: under the runner image (Gitea run 1091, docker.gitea.com/runner-images:ubuntu-24.04, root) the call succeeded, created /nonexistent-root-dir and left a file behind. The test now builds its unwritable paths in a temporary directory from things that fail for every user: a path below a regular file (ENOTDIR, so create_dir_all fails) and a path that names an existing directory (EISDIR, so File::create fails). The unknown-container name is checked in the same place and also asserts that no file was created. Reproduced in the runner image as root with the old test failing and the new one passing. Co-Authored-By: Claude Sonnet 5.5 --- .../voelin-media/src/studio/output/record.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/voelin-media/src/studio/output/record.rs b/crates/voelin-media/src/studio/output/record.rs index 29c5cb1..0c78cd3 100644 --- a/crates/voelin-media/src/studio/output/record.rs +++ b/crates/voelin-media/src/studio/output/record.rs @@ -350,7 +350,22 @@ mod tests { #[test] fn an_unwritable_path_fails_at_once() { - assert!(Recorder::start("/nonexistent-root-dir/x/clip.webm", 0, 2).is_err()); - assert!(Recorder::start("clip.mp4", 0, 2).is_err()); + let dir = dir("unwritable"); + // A path below a regular file fails for every user, root included + // (ENOTDIR). A directory that is merely missing would be created, and + // a read-only one is written to by root. + let file = dir.join("not-a-directory"); + std::fs::write(&file, b"x").unwrap(); + assert!(Recorder::start(file.join("x").join("clip.webm"), 0, 2).is_err()); + // The directory is there and the file cannot be created because the + // path names a directory (EISDIR, again for every user). + let named_like_a_file = dir.join("clip.webm"); + std::fs::create_dir(&named_like_a_file).unwrap(); + assert!(Recorder::start(&named_like_a_file, 0, 2).is_err()); + // A name that asks for no known container is refused before any file + // is created. + assert!(Recorder::start(dir.join("clip.mp4"), 0, 2).is_err()); + assert!(!dir.join("clip.mp4").exists()); + std::fs::remove_dir_all(&dir).ok(); } }