From 366648b027af851ec69087cc6e74d88ad66effdd Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 19 Nov 2026 13:28:50 +0000 Subject: [PATCH] state: write root-relative paths with / on windows paths of tracked files come from walking .pc and from joining path components, which uses \ on windows, so refresh wrote headers like a/chrome\app\main.cc into every patch. convert those paths to /, which windows accepts as well, so patches match the ones written elsewhere. --- src/state.rs | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/state.rs b/src/state.rs index f991af1..7a2c8d7 100644 --- a/src/state.rs +++ b/src/state.rs @@ -66,7 +66,7 @@ impl State { .map(|_| { let mut prefix: PathBuf = subdir.components().map(|_| "..").collect(); prefix.push(&patches_name); - format!("{}/", prefix.display()) + format!("{}/", with_slashes(prefix).display()) }); Ok(Self { @@ -318,12 +318,14 @@ impl State { } else { self.subdir.join(path) }; - rel.components() - .filter_map(|component| match component { - Component::CurDir => None, - other => Some(other.as_os_str().to_owned()), - }) - .collect() + with_slashes( + rel.components() + .filter_map(|component| match component { + Component::CurDir => None, + other => Some(other.as_os_str().to_owned()), + }) + .collect(), + ) } pub fn tracked_files(&self, patch: &str) -> Result> { @@ -354,7 +356,7 @@ impl State { } }; if entry.file_type().is_file() && entry.file_name() != ".timestamp" { - files.push(entry.path().strip_prefix(&dir)?.to_path_buf()); + files.push(with_slashes(entry.path().strip_prefix(&dir)?.to_path_buf())); } } sort_tracked(&mut files); @@ -362,6 +364,22 @@ impl State { } } +/// A path relative to the quilt root as quilt writes it in patches and +/// listings, with `/` even on Windows, where `Path` joins components with `\` +/// but accepts `/` as well. +#[cfg(windows)] +pub(crate) fn with_slashes(path: PathBuf) -> PathBuf { + match path.to_str() { + Some(text) if !path.is_absolute() => PathBuf::from(text.replace('\\', "/")), + _ => path, + } +} + +#[cfg(not(windows))] +pub(crate) fn with_slashes(path: PathBuf) -> PathBuf { + path +} + /// quilt's order for a patch's files: shallower paths first, then by name. pub(crate) fn sort_tracked(files: &mut [PathBuf]) { files.sort_by(|a, b| { @@ -417,6 +435,10 @@ fn write_if_missing(path: PathBuf, value: &str) -> Result<()> { #[cfg(test)] mod tests { use super::parse_series_line; + #[cfg(windows)] + use super::with_slashes; + #[cfg(windows)] + use std::path::PathBuf; #[test] fn parses_series_lines_with_options_and_comments() { @@ -430,4 +452,13 @@ mod tests { assert!(parse_series_line("# patch.diff").is_none()); assert!(parse_series_line(" ").is_none()); } + + #[cfg(windows)] + #[test] + fn writes_relative_paths_with_slashes() { + let path = with_slashes(PathBuf::from(r"chrome\app\main.cc")); + assert_eq!(path.to_str(), Some("chrome/app/main.cc")); + let absolute = with_slashes(PathBuf::from(r"C:\src\main.cc")); + assert_eq!(absolute.to_str(), Some(r"C:\src\main.cc")); + } }