Skip to content
Snippets Groups Projects
Commit c75b5ddb authored by Ryan Gonzalez's avatar Ryan Gonzalez Committed by Emanuele Aina
Browse files

Ignore missing files in snapshots

If a snapshot has any missing files, it would make the entire dashboard
collection fail, which isn't really the ideal behavior to have.

https://phabricator.apertis.org/T8593



Signed-off-by: default avatarRyan Gonzalez <ryan.gonzalez@collabora.com>
parent b40ccfbb
No related branches found
No related tags found
No related merge requests found
Pipeline #378869 failed
This commit is part of merge request !111. Comments created here will be created in the context of that merge request.
...@@ -88,22 +88,31 @@ async fn read_deb822_file< ...@@ -88,22 +88,31 @@ async fn read_deb822_file<
download: F, download: F,
client: &'client Client, client: &'client Client,
url: &'url str, url: &'url str,
) -> Result<T> { ) -> Result<Option<T>> {
let bytes = download(client, url) match lift_404(
.await download(client, url)
.with_context(|| format!("Failed to download {}", url))?; .await
.with_context(|| format!("Failed to download {}", url)),
let file = tokio::task::block_in_place(|| { )? {
rfc822_like::from_bytes(&bytes[..]) Some(bytes) => {
.with_context(|| format!("Failed to parse {}", url)) let file = tokio::task::block_in_place(|| {
})?; rfc822_like::from_bytes(&bytes[..])
.with_context(|| format!("Failed to parse {}", url))
})?;
debug!("Retrieved repo file");
Ok(Some(file))
}
debug!("Retrieved repo file"); None => Ok(None),
Ok(file) }
} }
impl Repository { impl Repository {
pub async fn read_release(&self, client: &Client) -> Result<RepositoryRelease> { pub async fn read_release(
&self,
client: &Client,
) -> Result<Option<RepositoryRelease>> {
read_deb822_file(Client::get, client, &format!("{}/Release", &self.url)).await read_deb822_file(Client::get, client, &format!("{}/Release", &self.url)).await
} }
...@@ -111,7 +120,7 @@ impl Repository { ...@@ -111,7 +120,7 @@ impl Repository {
&self, &self,
client: &Client, client: &Client,
component: &str, component: &str,
) -> Result<Vec<SourcePackage>> { ) -> Result<Option<Vec<SourcePackage>>> {
read_deb822_file( read_deb822_file(
get_maybe_compressed_file, get_maybe_compressed_file,
client, client,
...@@ -125,7 +134,7 @@ impl Repository { ...@@ -125,7 +134,7 @@ impl Repository {
client: &Client, client: &Client,
component: &str, component: &str,
arch: &str, arch: &str,
) -> Result<Vec<BinaryPackage>> { ) -> Result<Option<Vec<BinaryPackage>>> {
read_deb822_file( read_deb822_file(
get_maybe_compressed_file, get_maybe_compressed_file,
client, client,
......
...@@ -10,7 +10,7 @@ use anyhow::{Context, Result}; ...@@ -10,7 +10,7 @@ use anyhow::{Context, Result};
use futures::{future::try_join_all, stream, try_join, StreamExt, TryStreamExt}; use futures::{future::try_join_all, stream, try_join, StreamExt, TryStreamExt};
use serde_derive::Serialize; use serde_derive::Serialize;
use std::sync::Arc; use std::sync::Arc;
use tracing::{debug, info, instrument}; use tracing::{debug, info, instrument, warn};
async fn scan_source_packages( async fn scan_source_packages(
client: Client, client: Client,
...@@ -18,9 +18,23 @@ async fn scan_source_packages( ...@@ -18,9 +18,23 @@ async fn scan_source_packages(
component: String, component: String,
agg: Arc<StorageUsageAggregator>, agg: Arc<StorageUsageAggregator>,
) -> Result<()> { ) -> Result<()> {
for pkg in repo.read_sources(&client, &component).await? { match repo.read_sources(&client, &component).await? {
for file in pkg.files { Some(pkgs) => {
agg.add(&repo.id, format!("{}/{}", pkg.directory, file.filename), file.size); for pkg in pkgs {
for file in pkg.files {
agg.add(
&repo.id,
format!("{}/{}", pkg.directory, file.filename),
file.size,
);
}
}
}
None => {
warn!(
"Repository {}, component {} is missing its Sources file",
repo.id, component
);
} }
} }
...@@ -34,8 +48,18 @@ async fn scan_binary_packages( ...@@ -34,8 +48,18 @@ async fn scan_binary_packages(
arch: String, arch: String,
agg: Arc<StorageUsageAggregator>, agg: Arc<StorageUsageAggregator>,
) -> Result<()> { ) -> Result<()> {
for pkg in repo.read_packages(&client, &component, &arch).await? { match repo.read_packages(&client, &component, &arch).await? {
agg.add(&repo.id, pkg.filename, pkg.size); Some(pkgs) => {
for pkg in pkgs {
agg.add(&repo.id, pkg.filename, pkg.size);
}
}
None => {
warn!(
"Repository {}, component {}, arch {} is missing its Packages file",
repo.id, component, arch
);
}
} }
Ok(()) Ok(())
...@@ -50,7 +74,14 @@ async fn aggregate_basic_stats( ...@@ -50,7 +74,14 @@ async fn aggregate_basic_stats(
) -> Result<()> { ) -> Result<()> {
debug!("Scanning repo"); debug!("Scanning repo");
let release = repo.read_release(client).await?; let release = match repo.read_release(client).await? {
Some(release) => release,
None => {
warn!("Repository {} is missing its Release file", repo.id);
return Ok(());
}
};
let metadata_size: usize = release.files.iter().map(|entry| entry.size).sum(); let metadata_size: usize = release.files.iter().map(|entry| entry.size).sum();
agg.register_key(repo.id.to_owned(), metadata_size); agg.register_key(repo.id.to_owned(), metadata_size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment