From cdca9f5debfe987447ed98b874342c99424c7b38 Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:09:04 +0100 Subject: [PATCH 1/3] =?UTF-8?q?shell:=20writable's=20probe=20held=20by=20a?= =?UTF-8?q?=20test=20=E2=80=94=20the=20next=20one=20never=20waits=20on=20t?= =?UTF-8?q?he=20last=20one's=20deletion=20(#760,=20red)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `probe` taken out of `writable`, as it was. Its name kept taken after removal — a folder in its place, as Windows keeps a name whose deletion is pending (#705) —, the second probe must still be made, under another name. Red: one name per process. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/shell/src/sessions.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/shell/src/sessions.rs b/modules/shell/src/sessions.rs index d854320b..6e30ccfa 100644 --- a/modules/shell/src/sessions.rs +++ b/modules/shell/src/sessions.rs @@ -307,7 +307,32 @@ pub fn settle(current: &Path, previous: &Path, written: bool, dispose: impl FnOn /// will do first —, leaving nothing: a folder that refuses is said before any recorder starts. pub fn writable(folder: &Path) -> std::io::Result<()> { std::fs::create_dir_all(folder)?; + std::fs::remove_file(probe(folder)?) +} + +/// A file written in `folder` for `writable`: its path. +fn probe(folder: &Path) -> std::io::Result { let probe = folder.join(format!(".kitokey-writable-{}", std::process::id())); std::fs::write(&probe, b"")?; - std::fs::remove_file(&probe) + Ok(probe) +} + +#[cfg(test)] +mod tests { + use super::*; + + /// On Windows a removed file's name can stay taken a while, its deletion pending — « Access is + /// denied » to whoever makes it again (#705, #760): the next probe never depends on the last + /// one's going. Its name kept taken here by a folder, which refuses a file as Windows does. + #[test] + fn a_second_probe_does_not_wait_on_the_first_ones_deletion() { + let folder = tempfile::tempdir().unwrap(); + let first = probe(folder.path()).unwrap(); + fs::remove_file(&first).unwrap(); + fs::create_dir(&first).unwrap(); + let second = probe(folder.path()).unwrap(); + assert_ne!(first, second); + fs::remove_file(second).unwrap(); + assert!(writable(folder.path()).is_ok()); + } } From b772341f3912fc83ef0ea909be439f649fca11fd Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:10:21 +0100 Subject: [PATCH 2/3] shell: writable's probe is never named twice in a process (#760) As the trial's file beside the day (#759): a count for the process in its name, the file made new, one left under the same number passed over. On Windows a name whose deletion is pending refuses to be made again (#705); a second probe no longer meets the first one's name. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/shell/src/sessions.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/shell/src/sessions.rs b/modules/shell/src/sessions.rs index 6e30ccfa..2ca687cf 100644 --- a/modules/shell/src/sessions.rs +++ b/modules/shell/src/sessions.rs @@ -3,6 +3,7 @@ //! and the files beside it; nothing here writes, moves or opens a file for writing. use std::io::ErrorKind; +use std::sync::atomic::{AtomicU64, Ordering}; use std::{ fs, path::{Path, PathBuf}, @@ -310,11 +311,24 @@ pub fn writable(folder: &Path) -> std::io::Result<()> { std::fs::remove_file(probe(folder)?) } -/// A file written in `folder` for `writable`: its path. +/// The count of the next probe's name, one for the process (`probe`). +static PROBES: AtomicU64 = AtomicU64::new(0); + +/// A file made new in `folder` for `writable`: its path. Its name is never given twice in a +/// process, as the trial's beside the day (#759): on Windows, a name just removed can stay taken a +/// while, its deletion pending, and making it again answers « Access is denied » (#705, #760). fn probe(folder: &Path) -> std::io::Result { - let probe = folder.join(format!(".kitokey-writable-{}", std::process::id())); - std::fs::write(&probe, b"")?; - Ok(probe) + for _ in 0..1000 { + let count = PROBES.fetch_add(1, Ordering::Relaxed); + let probe = folder.join(format!(".kitokey-writable-{}-{count}", std::process::id())); + match fs::OpenOptions::new().write(true).create_new(true).open(&probe) { + Ok(_) => return Ok(probe), + // One an earlier Kitokey left under the same number: passed over. + Err(error) if error.kind() == ErrorKind::AlreadyExists => continue, + Err(error) => return Err(error), + } + } + Err(std::io::Error::other("no name free for a probe of the folder")) } #[cfg(test)] From 467e94fe26cb28e1fae1c6cfe4877c651cf98913 Mon Sep 17 00:00:00 2001 From: "kitokey-marc[bot]" <356215105+kitokey-marc[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:12:47 +0100 Subject: [PATCH 3/3] shell: a probe an earlier Kitokey left is passed over, held by a test (#760) As #759's for its file beside the day: fifty names under this process's number taken, the probe made under another. Without the AlreadyExists branch, it fails. Agent-Session: 14f73956-90b9-46a3-9fcc-52dc45c43948 Co-Authored-By: Claude Opus 5.5 --- modules/shell/src/sessions.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/shell/src/sessions.rs b/modules/shell/src/sessions.rs index 2ca687cf..9e2a7495 100644 --- a/modules/shell/src/sessions.rs +++ b/modules/shell/src/sessions.rs @@ -349,4 +349,19 @@ mod tests { fs::remove_file(second).unwrap(); assert!(writable(folder.path()).is_ok()); } + + /// A probe an earlier Kitokey left under this process's number is passed over, never an error. + #[test] + fn a_probe_left_in_the_folder_is_passed_over() { + let folder = tempfile::tempdir().unwrap(); + let next = PROBES.load(Ordering::Relaxed); + let left: Vec<_> = (next..next + 50) + .map(|count| folder.path().join(format!(".kitokey-writable-{}-{count}", std::process::id()))) + .collect(); + for path in &left { + fs::write(path, "").unwrap(); + } + let made = probe(folder.path()).unwrap(); + assert!(!left.contains(&made), "{made:?}"); + } }