mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-18 04:10:57 +00:00
Non-existing directories are fine for URI base for files
This commit is contained in:
parent
d51a49db46
commit
d924c25669
1 changed files with 2 additions and 21 deletions
|
|
@ -8,7 +8,7 @@ use crate::ErrorKind;
|
|||
/// the base determines where this resource can be found.
|
||||
/// Both, local and remote targets are supported.
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
|
||||
#[allow(variant_size_differences)]
|
||||
pub enum Base {
|
||||
/// Local file path pointing to root directory
|
||||
Local(PathBuf),
|
||||
|
|
@ -47,21 +47,7 @@ impl TryFrom<&str> for Base {
|
|||
}
|
||||
return Ok(Self::Remote(url));
|
||||
}
|
||||
// Only accept existing directories as path
|
||||
let path = PathBuf::from(&value);
|
||||
if !path.is_dir() {
|
||||
return Err(ErrorKind::InvalidBase(
|
||||
value.to_string(),
|
||||
"The given base path is not a directory".to_string(),
|
||||
));
|
||||
}
|
||||
if !path.exists() {
|
||||
return Err(ErrorKind::InvalidBase(
|
||||
value.to_string(),
|
||||
"The given base directory does not exist".to_string(),
|
||||
));
|
||||
}
|
||||
Ok(Self::Local(path))
|
||||
Ok(Self::Local(PathBuf::from(value)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +78,4 @@ mod test_base {
|
|||
Base::try_from(dir.as_ref().to_str().unwrap())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_local() {
|
||||
assert!(Base::try_from("/asdfasdd20asdfljvvvzzcv/j2ofasd").is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue