Skip to content

Commit

Permalink
fix clippy and add package name in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 21, 2023
1 parent 601e999 commit d392345
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ async fn upload_from_args(args: UploadOpts) -> miette::Result<()> {
}

for package_file in &args.package_files {
if ArchiveType::try_from(&package_file).is_none() {
if ArchiveType::try_from(package_file).is_none() {
return Err(miette::miette!(
"The file {} does not appear to be a conda package.",
package_file.to_string_lossy()
Expand Down
26 changes: 16 additions & 10 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ pub async fn upload_package_to_quetz(
))
.into_diagnostic()?;

let hash = sha256_sum(&package_file).into_diagnostic()?;
let hash = sha256_sum(package_file).into_diagnostic()?;

let prepared_request = client
.request(Method::POST, upload_url)
.query(&[("force", "false"), ("sha256", &hash)])
.header("X-API-Key", token.clone());

send_request(prepared_request, &package_file).await?;
send_request(prepared_request, package_file).await?;
}

info!("Packages successfully uploaded to Quetz server");
Expand Down Expand Up @@ -136,13 +136,13 @@ pub async fn upload_package_to_artifactory(
.into_diagnostic()
.wrap_err("Creating temporary directory failed")?;

rattler_package_streaming::fs::extract(&package_file, package_dir.path())
rattler_package_streaming::fs::extract(package_file, package_dir.path())
.into_diagnostic()?;

let index_json = IndexJson::from_package_directory(package_dir.path()).into_diagnostic()?;
let subdir = index_json
.subdir
.ok_or_else(|| miette::miette!("index.json of the package has no subdirectory. Cannot determine which directory to upload to"))?;
.ok_or_else(|| miette::miette!("index.json of package {} has no subdirectory. Cannot determine which directory to upload to", package_file.display()))?;

let client = get_client().into_diagnostic()?;

Expand All @@ -159,7 +159,7 @@ pub async fn upload_package_to_artifactory(
.request(Method::PUT, upload_url)
.basic_auth(username.clone(), Some(password.clone()));

send_request(prepared_request, &package_file).await?;
send_request(prepared_request, package_file).await?;
}

info!("Packages successfully uploaded to Artifactory server");
Expand Down Expand Up @@ -198,7 +198,7 @@ pub async fn upload_package_to_prefix(
for package_file in package_files {
let filename = package_file
.file_name()
.unwrap()
.expect("no filename found")
.to_string_lossy()
.to_string();

Expand All @@ -210,7 +210,7 @@ pub async fn upload_package_to_prefix(

let client = get_client().into_diagnostic()?;

let hash = sha256_sum(&package_file).into_diagnostic()?;
let hash = sha256_sum(package_file).into_diagnostic()?;

let prepared_request = client
.post(url.clone())
Expand All @@ -220,7 +220,7 @@ pub async fn upload_package_to_prefix(
.header("Content-Type", "application/octet-stream")
.bearer_auth(token.clone());

send_request(prepared_request, &package_file).await?;
send_request(prepared_request, package_file).await?;
}

info!("Packages successfully uploaded to prefix.dev server");
Expand All @@ -239,7 +239,10 @@ async fn send_request(
let file_size = file.metadata().await.into_diagnostic()?.len();
info!(
"Uploading package file: {} ({})\n",
package_file.file_name().unwrap().to_string_lossy(),
package_file
.file_name()
.expect("no filename found")
.to_string_lossy(),
HumanBytes(file_size)
);
let progress_bar = indicatif::ProgressBar::new(file_size)
Expand Down Expand Up @@ -273,7 +276,10 @@ async fn send_request(
progress_bar.finish();
info!(
"\nUpload complete for package file: {}",
package_file.file_name().unwrap().to_string_lossy()
package_file
.file_name()
.expect("no filename found")
.to_string_lossy()
);

Ok(response)
Expand Down

0 comments on commit d392345

Please sign in to comment.