From c652461ae7a5d0b68118537ebbaa1522591e4869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 23 Aug 2023 16:15:09 +0200 Subject: [PATCH] xtask: Ignore non-text files in spec links check --- xtask/src/ci/spec_links.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xtask/src/ci/spec_links.rs b/xtask/src/ci/spec_links.rs index 7f9e724b..f6131158 100644 --- a/xtask/src/ci/spec_links.rs +++ b/xtask/src/ci/spec_links.rs @@ -3,7 +3,7 @@ use std::{ collections::HashMap, fs::{self, File}, - io::{BufRead, BufReader}, + io::{BufRead, BufReader, ErrorKind}, path::{Path, PathBuf}, }; @@ -85,7 +85,23 @@ fn collect_links(path: &Path) -> Result> { let mut content = BufReader::new(File::open(path)?); // We can assume a spec link will never overflow to another line. - while content.read_line(&mut buf)? > 0 { + loop { + match content.read_line(&mut buf) { + Ok(read) => { + if read == 0 { + break; + } + } + Err(err) => { + if err.kind() == ErrorKind::InvalidData { + // The content is not UTF-8 text, skip. + break; + } else { + return Err(err.into()); + } + } + }; + line += 1; // If for some reason a line has 2 spec links.