Skip to content

Commit 41d815e

Browse files
jyn514GuillaumeGomez
authored andcommitted
Don't forcibly fail linkchecking if there's a broken intra-doc link on Windows
1 parent dfedd33 commit 41d815e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/tools/linkchecker/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ impl Checker {
389389

390390
/// Load a file from disk, or from the cache if available.
391391
fn load_file(&mut self, file: &Path, report: &mut Report) -> (String, &FileEntry) {
392+
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
393+
#[cfg(windows)]
394+
const ERROR_INVALID_NAME: i32 = 123;
395+
392396
let pretty_path =
393397
file.strip_prefix(&self.root).unwrap_or(&file).to_str().unwrap().to_string();
394398

@@ -405,6 +409,14 @@ impl Checker {
405409
}
406410
Err(e) if e.kind() == ErrorKind::NotFound => FileEntry::Missing,
407411
Err(e) => {
412+
// If a broken intra-doc link contains `::`, on windows, it will cause `ERROR_INVALID_NAME` rather than `NotFound`.
413+
// Explicitly check for that so that the broken link can be allowed in `LINKCHECK_EXCEPTIONS`.
414+
#[cfg(windows)]
415+
if e.raw_os_error() == Some(ERROR_INVALID_NAME)
416+
&& file.as_os_str().to_str().map_or(false, |s| s.contains("::"))
417+
{
418+
return FileEntry::Missing;
419+
}
408420
panic!("unexpected read error for {}: {}", file.display(), e);
409421
}
410422
});

0 commit comments

Comments
 (0)