Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# renovate: datasource=github-tags depName=rust lookupName=rust-lang/rust
ARG RUST_VERSION=1.88.0
ARG RUST_VERSION=1.89.0

FROM rust:$RUST_VERSION

Expand Down
10 changes: 5 additions & 5 deletions crates/crates_io_database/src/models/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ impl Crate {
return Err(InvalidFeature::Empty);
}
let mut chars = name.chars();
if let Some(ch) = chars.next() {
if !(unicode_xid::UnicodeXID::is_xid_start(ch) || ch == '_' || ch.is_ascii_digit()) {
return Err(InvalidFeature::Start(ch, name.into()));
}
if let Some(ch) = chars.next()
&& !(unicode_xid::UnicodeXID::is_xid_start(ch) || ch == '_' || ch.is_ascii_digit())
{
return Err(InvalidFeature::Start(ch, name.into()));
}
for ch in chars {
if !(unicode_xid::UnicodeXID::is_xid_continue(ch)
Expand All @@ -320,7 +320,7 @@ impl Crate {
Crate::validate_feature_name(dep_feat)
} else if let Some((_, dep)) = name.split_once("dep:") {
Crate::validate_dependency_name(dep)?;
return Ok(());
Ok(())
} else {
Crate::validate_feature_name(name)
}
Expand Down
16 changes: 7 additions & 9 deletions crates/crates_io_markdown/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,9 @@ impl UrlRelativeEvaluate<'_> for SanitizeUrl {
new_url.push('/');
}
new_url += url;
if add_sanitize_query {
if let Ok(mut parsed_url) = Url::parse(&new_url) {
parsed_url.query_pairs_mut().append_pair("sanitize", "true");
new_url = parsed_url.into();
}
if add_sanitize_query && let Ok(mut parsed_url) = Url::parse(&new_url) {
parsed_url.query_pairs_mut().append_pair("sanitize", "true");
new_url = parsed_url.into();
}
Cow::Owned(new_url)
})
Expand Down Expand Up @@ -303,10 +301,10 @@ pub fn text_to_html<P: AsRef<Path>>(
return markdown_to_html(text, base_url, base_dir);
}

if let Some(ext) = path_in_vcs.extension().and_then(|ext| ext.to_str()) {
if MARKDOWN_EXTENSIONS.contains(&ext.to_lowercase().as_str()) {
return markdown_to_html(text, base_url, base_dir);
}
if let Some(ext) = path_in_vcs.extension().and_then(|ext| ext.to_str())
&& MARKDOWN_EXTENSIONS.contains(&ext.to_lowercase().as_str())
{
return markdown_to_html(text, base_url, base_dir);
}

encode_minimal(text).replace('\n', "<br>\n")
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.88.0"
channel = "1.89.0"
9 changes: 4 additions & 5 deletions src/controllers/helpers/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,13 @@ fn is_useragent_or_ip_blocked(config: &Server, req: &Parts) -> bool {
}

// check if client ip is blocked, needs to be an IPv4 address
if let Some(client_ip) = client_ip {
if config
if let Some(client_ip) = client_ip
&& config
.page_offset_cidr_blocklist
.iter()
.any(|blocked| blocked.contains(**client_ip))
{
return true;
}
{
return true;
}

false
Expand Down
36 changes: 17 additions & 19 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,16 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go

let pkg_path_in_vcs = tarball_info.vcs_info.map(|info| info.path_in_vcs);

if let Some(readme) = metadata.readme {
if !readme.is_empty() {
jobs::RenderAndUploadReadme::new(
version.id,
readme,
metadata
.readme_file
.unwrap_or_else(|| String::from("README.md")),
repository,
pkg_path_in_vcs,
).enqueue(conn).await?;
}
if let Some(readme) = metadata.readme && !readme.is_empty() {
jobs::RenderAndUploadReadme::new(
version.id,
readme,
metadata
.readme_file
.unwrap_or_else(|| String::from("README.md")),
repository,
pkg_path_in_vcs,
).enqueue(conn).await?;
}

// Upload crate tarball
Expand Down Expand Up @@ -912,13 +910,13 @@ pub fn validate_dependency(dep: &EncodableCrateDependency) -> AppResult<()> {
Crate::validate_feature(feature).map_err(bad_request)?;
}

if let Some(registry) = &dep.registry {
if !registry.is_empty() {
return Err(bad_request(format_args!(
"Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.",
dep.name
)));
}
if let Some(registry) = &dep.registry
&& !registry.is_empty()
{
return Err(bad_request(format_args!(
"Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.",
dep.name
)));
}

match semver::VersionReq::parse(&dep.version_req) {
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ pub async fn list_crates(
// To avoid breaking existing users, seek-based pagination is only used if an explicit page has
// not been provided. This way clients relying on meta.next_page will use the faster seek-based
// paginations, while client hardcoding pages handling will use the slower offset-based code.
let (total, next_page, prev_page, data) = if !explicit_page && seek.is_some() {
let seek = seek.unwrap();
let (total, next_page, prev_page, data) = if !explicit_page && let Some(seek) = seek {
if let Some(condition) = seek
.after(&pagination.page)?
.map(|s| filter_params.seek_after(&s))
Expand Down
54 changes: 27 additions & 27 deletions src/controllers/user/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,35 @@ pub async fn update_user(
return Err(bad_request("current user does not match requested user"));
}

if let Some(publish_notifications) = &user_update.user.publish_notifications {
if user.publish_notifications != *publish_notifications {
diesel::update(user)
.set(users::publish_notifications.eq(*publish_notifications))
.execute(&mut conn)
.await?;

if !publish_notifications {
let email_address = user.verified_email(&mut conn).await?;

if let Some(email_address) = email_address {
let email = EmailMessage::from_template(
"unsubscribe_notifications",
context! {
user_name => user.gh_login,
domain => state.emails.domain
},
);

match email {
Ok(email) => {
if let Err(error) = state.emails.send(&email_address, email).await {
warn!(
"Failed to send publish notifications unsubscribe email to {email_address}: {error}"
);
}
if let Some(publish_notifications) = &user_update.user.publish_notifications
&& user.publish_notifications != *publish_notifications
{
diesel::update(user)
.set(users::publish_notifications.eq(*publish_notifications))
.execute(&mut conn)
.await?;

if !publish_notifications {
let email_address = user.verified_email(&mut conn).await?;

if let Some(email_address) = email_address {
let email = EmailMessage::from_template(
"unsubscribe_notifications",
context! {
user_name => user.gh_login,
domain => state.emails.domain
},
);

match email {
Ok(email) => {
if let Err(error) = state.emails.send(&email_address, email).await {
warn!(
"Failed to send publish notifications unsubscribe email to {email_address}: {error}"
);
}
Err(error) => warn!("Failed to render unsubscribe email template: {error}"),
}
Err(error) => warn!("Failed to render unsubscribe email template: {error}"),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/middleware/block_traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ pub fn block_routes(
matched_path: Option<&MatchedPath>,
state: &AppState,
) -> Result<(), BoxedAppError> {
if let Some(matched_path) = matched_path {
if state.config.blocked_routes.contains(matched_path.as_str()) {
let body = "This route is temporarily blocked. See https://status.crates.io.";
return Err(custom(StatusCode::SERVICE_UNAVAILABLE, body));
}
if let Some(matched_path) = matched_path
&& state.config.blocked_routes.contains(matched_path.as_str())
{
let body = "This route is temporarily blocked. See https://status.crates.io.";
return Err(custom(StatusCode::SERVICE_UNAVAILABLE, body));
}

Ok(())
Expand Down
16 changes: 8 additions & 8 deletions src/worker/jobs/generate_og_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ impl BackgroundJob for GenerateOgImage {
let og_image_path = format!("og-images/{crate_name}.png");

// Invalidate CloudFront CDN
if let Some(cloudfront) = ctx.cloudfront() {
if let Err(error) = cloudfront.invalidate(&og_image_path).await {
warn!("Failed to invalidate CloudFront CDN for {crate_name}: {error}");
}
if let Some(cloudfront) = ctx.cloudfront()
&& let Err(error) = cloudfront.invalidate(&og_image_path).await
{
warn!("Failed to invalidate CloudFront CDN for {crate_name}: {error}");
}

// Invalidate Fastly CDN
if let Some(fastly) = ctx.fastly() {
if let Err(error) = fastly.invalidate(&og_image_path).await {
warn!("Failed to invalidate Fastly CDN for {crate_name}: {error}");
}
if let Some(fastly) = ctx.fastly()
&& let Err(error) = fastly.invalidate(&og_image_path).await
{
warn!("Failed to invalidate Fastly CDN for {crate_name}: {error}");
}

info!("CDN invalidation completed for crate {crate_name}");
Expand Down
Loading