Skip to content

Commit 8e64249

Browse files
committed
fix: lint
1 parent fbd5dde commit 8e64249

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

src/server.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn strip_leading_slash(s: &str) -> &str {
2121
s.strip_prefix('/').unwrap_or(s)
2222
}
2323

24-
2524
type SharedStorage = Arc<dyn Storage>;
2625

2726
#[derive(Clone)]
@@ -47,7 +46,7 @@ pub struct RegistryServer {
4746
impl RegistryServer {
4847
pub async fn new(config: RegistryConfig) -> Result<Self> {
4948
let storage = create_storage(&config.storage).await?;
50-
49+
5150
let state = AppState { storage };
5251

5352
let app = Router::new()
@@ -63,7 +62,7 @@ impl RegistryServer {
6362
.layer(
6463
tower::ServiceBuilder::new()
6564
.layer(axum::extract::DefaultBodyLimit::max(512 * 1024 * 1024))
66-
.layer(TraceLayer::new_for_http())
65+
.layer(TraceLayer::new_for_http()),
6766
)
6867
.with_state(state);
6968

@@ -115,10 +114,7 @@ async fn check_blob(
115114
info!("Checking blob: {}/{}", name, digest);
116115

117116
match state.storage.get_blob(&digest).await {
118-
Ok(Some(blob)) => (
119-
StatusCode::OK,
120-
[("Content-Length", blob.len().to_string())],
121-
),
117+
Ok(Some(blob)) => (StatusCode::OK, [("Content-Length", blob.len().to_string())]),
122118
_ => (StatusCode::NOT_FOUND, [("Content-Length", "0".to_string())]),
123119
}
124120
}
@@ -154,10 +150,7 @@ async fn start_upload(
154150

155151
(
156152
StatusCode::ACCEPTED,
157-
[(
158-
"Location",
159-
format!("/v2/{}/blobs/uploads/{}", name, uuid),
160-
)],
153+
[("Location", format!("/v2/{}/blobs/uploads/{}", name, uuid))],
161154
)
162155
}
163156

@@ -237,7 +230,11 @@ async fn finish_upload(
237230
format!("sha256:{}", hex::encode(hasher.finalize()))
238231
});
239232

240-
if let Err(e) = state.storage.store_blob(digest_str.clone(), upload_data).await {
233+
if let Err(e) = state
234+
.storage
235+
.store_blob(digest_str.clone(), upload_data)
236+
.await
237+
{
241238
warn!("Failed to store blob: {}", e);
242239
return (
243240
StatusCode::INTERNAL_SERVER_ERROR,
@@ -302,7 +299,10 @@ async fn put_manifest(
302299
warn!("Failed to store manifest by digest: {}", e);
303300
}
304301

305-
info!("Stored manifest with digest: {} (type: {})", digest, content_type);
302+
info!(
303+
"Stored manifest with digest: {} (type: {})",
304+
digest, content_type
305+
);
306306

307307
(
308308
StatusCode::CREATED,

src/storage.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::error::{RegistryError, Result};
21
use crate::config::StorageBackend;
2+
use crate::error::{RegistryError, Result};
33
use async_trait::async_trait;
44
use std::collections::HashMap;
55
use std::path::PathBuf;
@@ -87,7 +87,7 @@ impl DiskStorage {
8787
fs::create_dir_all(path.join("manifests")).await?;
8888
fs::create_dir_all(path.join("blobs")).await?;
8989
fs::create_dir_all(path.join("uploads")).await?;
90-
90+
9191
Ok(Self {
9292
base_path: path,
9393
_temp_dir: None,
@@ -97,11 +97,11 @@ impl DiskStorage {
9797
pub async fn temp() -> Result<Self> {
9898
let temp_dir = tempfile::tempdir()?;
9999
let path = temp_dir.path().to_path_buf();
100-
100+
101101
fs::create_dir_all(path.join("manifests")).await?;
102102
fs::create_dir_all(path.join("blobs")).await?;
103103
fs::create_dir_all(path.join("uploads")).await?;
104-
104+
105105
Ok(Self {
106106
base_path: path,
107107
_temp_dir: Some(temp_dir),
@@ -110,12 +110,16 @@ impl DiskStorage {
110110

111111
fn manifest_path(&self, key: &str) -> PathBuf {
112112
let safe_key = key.replace(['/', ':'], "_");
113-
self.base_path.join("manifests").join(format!("{}.json", safe_key))
113+
self.base_path
114+
.join("manifests")
115+
.join(format!("{}.json", safe_key))
114116
}
115117

116118
fn manifest_meta_path(&self, key: &str) -> PathBuf {
117119
let safe_key = key.replace(['/', ':'], "_");
118-
self.base_path.join("manifests").join(format!("{}.meta", safe_key))
120+
self.base_path
121+
.join("manifests")
122+
.join(format!("{}.meta", safe_key))
119123
}
120124

121125
fn blob_path(&self, digest: &str) -> PathBuf {
@@ -133,25 +137,26 @@ impl Storage for DiskStorage {
133137
async fn store_manifest(&self, key: String, entry: ManifestEntry) -> Result<()> {
134138
let manifest_path = self.manifest_path(&key);
135139
let meta_path = self.manifest_meta_path(&key);
136-
140+
137141
fs::write(&manifest_path, &entry.data).await?;
138142
fs::write(&meta_path, &entry.content_type).await?;
139-
143+
140144
Ok(())
141145
}
142146

143147
async fn get_manifest(&self, key: &str) -> Result<Option<ManifestEntry>> {
144148
let manifest_path = self.manifest_path(key);
145149
let meta_path = self.manifest_meta_path(key);
146-
150+
147151
if !manifest_path.exists() {
148152
return Ok(None);
149153
}
150-
154+
151155
let data = fs::read(&manifest_path).await?;
152-
let content_type = fs::read_to_string(&meta_path).await
156+
let content_type = fs::read_to_string(&meta_path)
157+
.await
153158
.unwrap_or_else(|_| "application/vnd.docker.distribution.manifest.v2+json".to_string());
154-
159+
155160
Ok(Some(ManifestEntry { data, content_type }))
156161
}
157162

@@ -163,11 +168,11 @@ impl Storage for DiskStorage {
163168

164169
async fn get_blob(&self, digest: &str) -> Result<Option<Vec<u8>>> {
165170
let blob_path = self.blob_path(digest);
166-
171+
167172
if !blob_path.exists() {
168173
return Ok(None);
169174
}
170-
175+
171176
let data = fs::read(&blob_path).await?;
172177
Ok(Some(data))
173178
}
@@ -180,28 +185,28 @@ impl Storage for DiskStorage {
180185

181186
async fn append_upload(&self, uuid: &str, data: &[u8]) -> Result<()> {
182187
let upload_path = self.upload_path(uuid);
183-
188+
184189
if !upload_path.exists() {
185190
return Err(RegistryError::UploadNotFound(uuid.to_string()));
186191
}
187-
192+
188193
let mut existing = fs::read(&upload_path).await?;
189194
existing.extend_from_slice(data);
190195
fs::write(&upload_path, &existing).await?;
191-
196+
192197
Ok(())
193198
}
194199

195200
async fn finish_upload(&self, uuid: &str) -> Result<Option<Vec<u8>>> {
196201
let upload_path = self.upload_path(uuid);
197-
202+
198203
if !upload_path.exists() {
199204
return Ok(None);
200205
}
201-
206+
202207
let data = fs::read(&upload_path).await?;
203208
fs::remove_file(&upload_path).await?;
204-
209+
205210
Ok(Some(data))
206211
}
207212
}

tests/integration_test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use bollard::query_parameters::{CreateImageOptions, ListImagesOptions, PushImageOptions, RemoveImageOptions, TagImageOptions};
1+
use bollard::query_parameters::{
2+
CreateImageOptions, ListImagesOptions, PushImageOptions, RemoveImageOptions, TagImageOptions,
3+
};
24
use bollard::Docker;
35
use futures_util::stream::StreamExt;
46
use registry_testkit::{RegistryConfig, RegistryServer};
@@ -139,8 +141,7 @@ async fn test_docker_push_pull() {
139141
.await
140142
.unwrap();
141143

142-
let mut push_stream =
143-
docker.push_image(&registry_image, None::<PushImageOptions>, None);
144+
let mut push_stream = docker.push_image(&registry_image, None::<PushImageOptions>, None);
144145

145146
while let Some(result) = push_stream.next().await {
146147
let info = result.unwrap();

0 commit comments

Comments
 (0)