Skip to content

Commit cdd9649

Browse files
committed
refactor: extract config.json as a constant
1 parent 665d9a0 commit cdd9649

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/cargo/sources/registry/http_remote.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'cfg> HttpRegistry<'cfg> {
383383
}
384384
let config_json_path = self
385385
.assert_index_locked(&self.index_path)
386-
.join("config.json");
386+
.join(RegistryConfig::NAME);
387387
match fs::read(&config_json_path) {
388388
Ok(raw_data) => match serde_json::from_slice(&raw_data) {
389389
Ok(json) => {
@@ -404,12 +404,12 @@ impl<'cfg> HttpRegistry<'cfg> {
404404
fn config(&mut self) -> Poll<CargoResult<&RegistryConfig>> {
405405
debug!("loading config");
406406
let index_path = self.assert_index_locked(&self.index_path);
407-
let config_json_path = index_path.join("config.json");
408-
if self.is_fresh(Path::new("config.json")) && self.config_cached()?.is_some() {
407+
let config_json_path = index_path.join(RegistryConfig::NAME);
408+
if self.is_fresh(Path::new(RegistryConfig::NAME)) && self.config_cached()?.is_some() {
409409
return Poll::Ready(Ok(self.registry_config.as_ref().unwrap()));
410410
}
411411

412-
match ready!(self.load(Path::new(""), Path::new("config.json"), None)?) {
412+
match ready!(self.load(Path::new(""), Path::new(RegistryConfig::NAME), None)?) {
413413
LoadResponse::Data {
414414
raw_data,
415415
index_version: _,
@@ -543,7 +543,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
543543
}
544544
StatusCode::Unauthorized
545545
if !self.auth_required
546-
&& path == Path::new("config.json")
546+
&& path == Path::new(RegistryConfig::NAME)
547547
&& self.config.cli_unstable().registry_auth =>
548548
{
549549
debug!("re-attempting request for config.json with authorization included.");
@@ -593,7 +593,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
593593
}
594594
}
595595

596-
if path != Path::new("config.json") {
596+
if path != Path::new(RegistryConfig::NAME) {
597597
self.auth_required = ready!(self.config()?).auth_required;
598598
} else if !self.auth_required {
599599
// Check if there's a cached config that says auth is required.

src/cargo/sources/registry/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ impl<'cfg> Source for RegistrySource<'cfg> {
856856
}
857857
}
858858

859+
impl RegistryConfig {
860+
/// File name of [`RegistryConfig`].
861+
const NAME: &str = "config.json";
862+
}
863+
859864
/// Get the maximum upack size that Cargo permits
860865
/// based on a given `size` of your compressed file.
861866
///

src/cargo/sources/registry/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
304304
debug!("loading config");
305305
self.prepare()?;
306306
self.config.assert_package_cache_locked(&self.index_path);
307-
match ready!(self.load(Path::new(""), Path::new("config.json"), None)?) {
307+
match ready!(self.load(Path::new(""), Path::new(RegistryConfig::NAME), None)?) {
308308
LoadResponse::Data { raw_data, .. } => {
309309
trace!("config loaded");
310310
let mut cfg: RegistryConfig = serde_json::from_slice(&raw_data)?;

0 commit comments

Comments
 (0)