Skip to content

Commit

Permalink
Add support for local source file url scheme (#177)
Browse files Browse the repository at this point in the history
Fix #176
  • Loading branch information
beenje authored Sep 5, 2023
1 parent 39edb0c commit 34c8e0d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub enum SourceError {
#[error("Download could not be validated with checksum!")]
ValidationFailed,

#[error("File not found!")]
FileNotFound,

#[error("Failed to apply patch: {0}")]
PatchFailed(String),

Expand Down
19 changes: 19 additions & 0 deletions src/source/url_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ pub(crate) async fn url_src(
cache_dir: &Path,
checksum: &Checksum,
) -> Result<PathBuf, SourceError> {
if source.url.scheme() == "file" {
let local_path = source.url.to_file_path().map_err(|_| {
SourceError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
"Invalid local file path",
))
})?;
if !local_path.is_file() {
return Err(SourceError::FileNotFound);
}
if validate_checksum(&local_path, checksum) {
tracing::info!("Using local source file.");
return Ok(local_path);
} else {
tracing::error!("Checksum validation failed!");
return Err(SourceError::ValidationFailed);
}
}

let cache_name = PathBuf::from(cache_name_from_url(&source.url, checksum));
let cache_name = cache_dir.join(cache_name);

Expand Down

0 comments on commit 34c8e0d

Please sign in to comment.