feat: Support install directly from git repo (#1162)

Fixed #3

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-06-24 11:01:31 +10:00 committed by GitHub
parent dd35fba232
commit ca00cbaccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1810 additions and 28 deletions

View file

@ -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 {