This commit is contained in:
parent
b115b91ecb
commit
e4eb85f535
7 changed files with 75 additions and 38 deletions
|
@ -7,15 +7,15 @@ use regex::Regex;
|
|||
pub enum PackageIdentifierError {
|
||||
InvalidPackageLocator(String),
|
||||
InvalidURI(String),
|
||||
InvalidPath(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PackageIdentifierError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
PackageIdentifierError::InvalidPackageLocator(s) => {
|
||||
write!(f, "Invalid package locator: {}", s)
|
||||
}
|
||||
PackageIdentifierError::InvalidPackageLocator(s) => write!(f, "Invalid package locator: {}", s),
|
||||
PackageIdentifierError::InvalidURI(s) => write!(f, "Invalid URI: {}", s),
|
||||
PackageIdentifierError::InvalidPath(s) => write!(f, "Invalid path: {}", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,18 @@ impl FromStr for PackageIdentifier {
|
|||
return Err(PackageIdentifierError::InvalidURI(s.to_string()));
|
||||
}
|
||||
Ok(PackageIdentifier::URI(s.to_string()))
|
||||
} else if std::path::Path::new(s).exists() {
|
||||
} else if s.starts_with("/")
|
||||
|| s.starts_with("./")
|
||||
|| s.starts_with("../")
|
||||
|| s.starts_with("~/")
|
||||
{
|
||||
let path = std::path::Path::new(s);
|
||||
if s.ends_with("/")
|
||||
|| !path.exists()
|
||||
|| path.is_dir()
|
||||
{
|
||||
return Err(PackageIdentifierError::InvalidPath(s.to_string()));
|
||||
}
|
||||
return Ok(PackageIdentifier::Path(s.to_string()));
|
||||
} else {
|
||||
let pl = match PackageLocator::from_str(s) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue