mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 12:46:43 +00:00
fix: correct rename on unix platforms caused by pathdiff#8 (#1587)
* fix: correct rename on unix platforms caused by pathdiff#8 * fix: ensure all calls to pathdiff * fix: names * fix: file path on windows
This commit is contained in:
parent
c102ace9ab
commit
e4a4fc568f
19 changed files with 44 additions and 28 deletions
|
|
@ -1,6 +1,7 @@
|
|||
//! Path utilities.
|
||||
|
||||
use std::path::{Component, Path};
|
||||
use std::borrow::Cow;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
pub use path_clean::PathClean;
|
||||
|
||||
|
|
@ -48,6 +49,24 @@ pub fn unix_slash(root: &Path) -> String {
|
|||
/// Get the path cleaned as a platform-style string.
|
||||
pub use path_clean::clean;
|
||||
|
||||
/// Construct a relative path from a provided base directory path to the
|
||||
/// provided path.
|
||||
pub fn diff(fr: &Path, to: &Path) -> Option<PathBuf> {
|
||||
// Because of <https://github.com/Manishearth/pathdiff/issues/8>, we have to clean the path
|
||||
// before diff.
|
||||
fn clean_for_diff(p: &Path) -> Cow<'_, Path> {
|
||||
if p.components()
|
||||
.any(|c| matches!(c, Component::ParentDir | Component::CurDir))
|
||||
{
|
||||
Cow::Owned(p.clean())
|
||||
} else {
|
||||
Cow::Borrowed(p)
|
||||
}
|
||||
}
|
||||
|
||||
pathdiff::diff_paths(clean_for_diff(fr).as_ref(), clean_for_diff(to).as_ref())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::path::{Path, PathBuf};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue