[fix] fix panic
This commit is contained in:
parent
a5473f6436
commit
bdf10a5176
@ -37,7 +37,6 @@ struct History {
|
||||
created: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Registry<'a> {
|
||||
pub async fn get_repositories(&self) -> Result<RepositoryList, Box<dyn std::error::Error>> {
|
||||
let registry_url = Url::parse(self.url).unwrap();
|
||||
@ -86,20 +85,25 @@ impl<'a> Registry<'a> {
|
||||
// .unwrap()
|
||||
// .to_string();
|
||||
|
||||
let digest = reqwest::Client::new()
|
||||
let mut digest = String::new();
|
||||
let rr = reqwest::Client::new()
|
||||
.get(api_url.clone())
|
||||
.header(
|
||||
reqwest::header::ACCEPT,
|
||||
"application/vnd.docker.distribution.manifest.v2+json",
|
||||
)
|
||||
.send()
|
||||
.await?
|
||||
.headers()
|
||||
.await?;
|
||||
|
||||
if rr.headers().get("Docker-Content-Digest").is_some() {
|
||||
digest.push_str(
|
||||
rr.headers()
|
||||
.get("Docker-Content-Digest")
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
.unwrap_or(""),
|
||||
);
|
||||
}
|
||||
|
||||
let mut data = resp.json::<RepositoryTagManifest>().await?;
|
||||
|
||||
|
31
src/main.rs
31
src/main.rs
@ -46,6 +46,7 @@ fn main() {
|
||||
// println!("proc images ::: {:?}", proc_images);
|
||||
|
||||
for img in proc_images.into_iter() {
|
||||
println!("ProcImage: {}", img);
|
||||
let _repo_tags = registry.get_repository_tags(img.as_str()).await.unwrap();
|
||||
|
||||
let mut tags: Vec<api::registry::RepositoryTagManifest> = Vec::new();
|
||||
@ -56,24 +57,36 @@ fn main() {
|
||||
if _parsed.exclude.contains(x) {
|
||||
continue;
|
||||
}
|
||||
let manifests = registry
|
||||
.get_repository_tag_manifest(img.as_str(), x)
|
||||
.await
|
||||
.unwrap();
|
||||
tags.push(manifests);
|
||||
let manifests = registry.get_repository_tag_manifest(img.as_str(), x).await;
|
||||
match manifests {
|
||||
Err(_) => continue,
|
||||
Ok(v) => tags.push(v),
|
||||
};
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
tags.sort_by(|a, b| b.ts.partial_cmp(&a.ts).unwrap());
|
||||
// println!("{:?}", tags);
|
||||
|
||||
tags.drain(0.._parsed.keep as usize);
|
||||
let del_count: usize = if tags.len() > _parsed.keep as usize {
|
||||
_parsed.keep as usize
|
||||
} else {
|
||||
tags.len()
|
||||
};
|
||||
|
||||
tags.drain(0..del_count);
|
||||
|
||||
println!("delete tag number : {}", tags.len());
|
||||
for x in tags.iter() {
|
||||
match registry.delete_repository_tag(img.as_str(), x.digest.as_str()).await {
|
||||
if x.digest.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
match registry
|
||||
.delete_repository_tag(img.as_str(), x.digest.as_str())
|
||||
.await
|
||||
{
|
||||
Ok(_) => println!("delete {} success", x.tag),
|
||||
Err(_) => println!("delete {} fail", x.tag),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user