Skip to content

Commit

Permalink
: don't panic in relative_path (#36)
Browse files Browse the repository at this point in the history
Summary:

if in `relative_path` we find `to` and `from` are in different file systems, don't panic but instead just return `to` unmodified. testing indicates that `reindeer buckify` continues to work as normal with that choice in this case (and so we can avoid needing `CARGO_HOME` workarounds).

Differential Revision: D52989646
  • Loading branch information
Shayne Fletcher committed Jan 23, 2024
1 parent 09c3167 commit d1daf8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: echo CARGO_HOME=$GITHUB_WORKSPACE/.cargo >> $GITHUB_ENV
shell: bash
- run: cargo build --locked
- run: cargo test
- run: |-
Expand Down
18 changes: 17 additions & 1 deletion src/buckify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,23 @@ pub fn relative_path(mut base: &Path, to: &Path) -> PathBuf {
res.display()
);
res.push("..");
base = base.parent().expect("root dir not prefix of other?");
match base.parent() {
Some(parent) => base = parent,
None => {
// Here, `to` and `base` do not share a common
// ancestor.

// Example:
// - `to` = 'C:\Users\runneradmin\.cargo\...001f\anyhow-1.0.79\build.rs'
// - `base` = 'D:\a\reindeer\reindeer\shim\third-party\rust'

// In this case return `to` "as-is" (i.e. without any
// modification)`. `reindeer buckify` seems to work
// with this choice.

return to.to_path_buf();
}
}
}

res.join(
Expand Down

0 comments on commit d1daf8d

Please sign in to comment.