Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file path separator decoded from manifest is not correct on Windows #3077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ url = "2.1"
wait-timeout = "0.2"
xz2 = "0.1.3"
zstd = "0.11"
path-slash = "0.2.1"

[dependencies.retry]
default-features = false
Expand Down
24 changes: 22 additions & 2 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::path::{Path, PathBuf};

use anyhow::{bail, Result};
use path_slash::PathBufExt;

use crate::dist::component::package::{INSTALLER_VERSION, VERSION_FILE};
use crate::dist::component::transaction::Transaction;
Expand Down Expand Up @@ -150,8 +151,12 @@ impl ComponentPart {
format!("{}:{}", &self.0, &self.1.to_string_lossy())
}
pub(crate) fn decode(line: &str) -> Option<Self> {
line.find(':')
.map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
line.find(':').map(|pos| {
Self(
line[0..pos].to_owned(),
PathBuf::from_slash(&line[(pos + 1)..]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've had a look at this. I think the change should be localised to the rename path, rather than the manifest: the change you've made will result in different manifests in the rustup dir depending on OS - that will interact badly with rustup dirs shared on NFS and the like.

I'm not entirely sure that the extra library is worth it - since we're only doing a relatively small number of these operations the overhead of a deconstruct to segments and reconstruct will be quite inivisble.

    42 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-cargo-x86_64-unknown-linux-gnu
     5 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-clippy-preview-x86_64-unknown-linux-gnu
    26 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rust-analysis-x86_64-unknown-linux-gnu
    25 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rustc-x86_64-unknown-linux-gnu
     1 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rust-docs-x86_64-unknown-linux-gnu
     5 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rustfmt-preview-x86_64-unknown-linux-gnu
  1466 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rust-src
    32 /home/robertc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/manifest-rust-std-x86_64-unknown-linux-gnu
  1602 total

Copy link
Member

@rami3l rami3l Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtcollins One of our tests is also plagued with this issue, so I doubt whether it's really reasonable to localize the change to the rename path. The snippet below has nothing to do with renaming I assume:

async fn bad_manifest() {
// issue #3851
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
// install some toolchain
cx.config.expect_ok(&["rustup", "update", "nightly"]).await;
#[cfg(not(target_os = "windows"))]
let path = format!(
"toolchains/nightly-{}/lib/rustlib/multirust-channel-manifest.toml",
this_host_triple(),
);
#[cfg(target_os = "windows")]
let path = format!(
r"toolchains\nightly-{}\lib/rustlib\multirust-channel-manifest.toml",
this_host_triple(),
);
assert!(cx.config.rustupdir.has(&path));
let path = cx.config.rustupdir.join(&path);
// corrupt the manifest file by inserting a NUL byte at some position
let old = fs::read_to_string(&path).unwrap();
let pattern = "[[pkg.rust.targ";
let (prefix, suffix) = old.split_once(pattern).unwrap();
let new = format!("{prefix}{pattern}\u{0}{suffix}");
fs::write(&path, new).unwrap();
// run some commands that try to load the manifest and
// check that the manifest parsing error includes the manifest file path
cx.config
.expect_err(
&["rustup", "check"],
&format!("error: could not parse manifest file: '{}'", path.display()),
)
.await;
}

... also, so far the only call site to .decode() is in DirectoryPackage::install().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different manifests in the rustup dir depending on OS

@rbtcollins I think that can be resolved by putting from_slash() in .decode() and to_slash() in .encode()... Performance-wise it won't make that much of a difference, right?

)
})
}
}

Expand Down Expand Up @@ -316,3 +321,18 @@ impl Component {
Ok(tx)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn decode_component_part() {
let part = ComponentPart::decode("dir:share/doc/rust/html").unwrap();
assert_eq!(part.0, "dir");
#[cfg(target_os = "windows")]
assert_eq!(part.1, Path::new(r"share\doc\rust\html"));
#[cfg(not(target_os = "windows"))]
assert_eq!(part.1, Path::new("share/doc/rust/html"));
}
}