mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-25 06:40:03 +00:00
feat: Support install directly from git repo (#1162)
Fixed #3 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
dd35fba232
commit
ca00cbaccc
22 changed files with 1810 additions and 28 deletions
|
@ -29,6 +29,11 @@ pub trait NormalizePath {
|
|||
/// However, this does not resolve links.
|
||||
fn normalize(&self) -> PathBuf;
|
||||
|
||||
/// Same as [`NormalizePath::normalize`] except that if
|
||||
/// `Component::Prefix`/`Component::RootDir` is encountered,
|
||||
/// or if the path points outside of current dir, returns `None`.
|
||||
fn try_normalize(&self) -> Option<PathBuf>;
|
||||
|
||||
/// Return `true` if the path is normalized.
|
||||
///
|
||||
/// # Quirk
|
||||
|
@ -68,6 +73,27 @@ impl NormalizePath for Path {
|
|||
ret
|
||||
}
|
||||
|
||||
fn try_normalize(&self) -> Option<PathBuf> {
|
||||
let mut ret = PathBuf::new();
|
||||
|
||||
for component in self.components() {
|
||||
match component {
|
||||
Component::Prefix(..) | Component::RootDir => return None,
|
||||
Component::CurDir => {}
|
||||
Component::ParentDir => {
|
||||
if !ret.pop() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Component::Normal(c) => {
|
||||
ret.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(ret)
|
||||
}
|
||||
|
||||
fn is_normalized(&self) -> bool {
|
||||
for component in self.components() {
|
||||
match component {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue