MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / read_file_bytes

Function read_file_bytes

src/sync.rs:55–72  ·  view source on GitHub ↗

Reads a file's bytes, absorbing transient Windows file locks. On Windows, antivirus scanners and the search indexer briefly open freshly written files with exclusive access; an unlucky open during that window fails with a sharing violation or "Access is denied" (os error 5) even though the file is readable milliseconds later. Callers treat read errors as "skip this file" or fail the whole sync, s

(path: &Path)

Source from the content-addressed store, hash-verified

53/// giving up. Other platforms read directly: `PermissionDenied` there is a
54/// real ACL problem that retrying cannot fix.
55fn read_file_bytes(path: &Path) -> std::io::Result<Vec<u8>> {
56 const RETRY_DELAYS_MS: [u64; 4] = [10, 20, 40, 80];
57 if !cfg!(windows) {
58 return std::fs::read(path);
59 }
60 let mut delays = RETRY_DELAYS_MS.iter();
61 loop {
62 match std::fs::read(path) {
63 Err(err) if is_transient_windows_file_lock(&err) => match delays.next() {
64 Some(&delay_ms) => {
65 std::thread::sleep(std::time::Duration::from_millis(delay_ms));
66 }
67 None => return Err(err),
68 },
69 result => return result,
70 }
71 }
72}
73
74/// True for Windows errors that indicate another process is briefly holding
75/// the file: `ERROR_SHARING_VIOLATION` (32) and `ERROR_LOCK_VIOLATION` (33)

Callers 1

read_source_fileFunction · 0.85

Calls 2

readFunction · 0.50

Tested by

no test coverage detected