Skip to content

Commit 4a7d270

Browse files
committed
If we are a mirror, allow incrementing download count to fail
This might fail because we don't have any crates in the database; we just want to be an API mirror and pass along the redirect URL.
1 parent a28e79c commit 4a7d270

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/krate.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,16 @@ pub fn download(req: &mut Request) -> CargoResult<Response> {
828828
let crate_name = &req.params()["crate_id"];
829829
let version = &req.params()["version"];
830830

831-
try!(increment_download_counts(req, crate_name, version));
831+
// If we are a mirror, ignore failure to update download counts.
832+
// API-only mirrors won't have any crates in their database, and
833+
// incrementing the download count will look up the crate in the
834+
// database. Mirrors just want to pass along a redirect URL.
835+
if req.app().config.mirror {
836+
let _ = increment_download_counts(req, crate_name, version);
837+
} else {
838+
try!(increment_download_counts(req, crate_name, version));
839+
}
840+
832841
let redirect_url = format!("https://{}/crates/{}/{}-{}.crate",
833842
req.app().bucket.host(),
834843
crate_name, crate_name, version);

0 commit comments

Comments
 (0)