Repository: astral-sh/uv
File: crates/uv-publish/src/lib.rs (Rust)

Code before:
                        }
                    }
                }
                Err(PublishError::PublishSend(
                    file.to_path_buf(),
                    registry.clone(),
                    err,
                ))
            }
        };
    }
}

/// Validate a file against a registry.
pub async fn validate(
    file: &Path,
    form_metadata: &FormMetadata,
    raw_filename: &str,
    registry: &DisplaySafeUrl,
    client: &BaseClient,
    credentials: &Credentials,
) -> Result<(), PublishError> {
    if PyxTokenStore::from_settings()
        .as_ref()
        .is_ok_and(|store| store.is_known_url(registry))
    {
        debug!("Performing validation request for {registry}");

        let mut validation_url = registry.clone();
        validation_url
            .path_segments_mut()
            .expect("URL must have path segments")
            .push("validate");

        let request = build_validation_request(
            raw_filename,
            &validation_url,
            client,
            credentials,
            form_metadata,
        );

        let response = request.send().await.map_err(|err| {
            PublishError::Validate(
                file.to_path_buf(),
                registry.clone(),
                PublishSendError::ReqwestMiddleware(err),
            )
        })?;

        handle_response(&validation_url, response)

Review comment (bug):
We should probably fail if we can't load the authentication?

Does `--dry-run` do anything if this early-exits? I guess it runs `--check-url`? Should we log the case where validation doesn't run at least?

Code after:
            form_metadata,
        );

        let response = request.send().await.map_err(|err| {
            PublishError::Validate(
                file.to_path_buf(),
                registry.clone(),
                PublishSendError::ReqwestMiddleware(err),
            )
        })?;

        handle_response(&validation_url, response)
            .await
            .map_err(|err| PublishError::Validate(file.to_path_buf(), registry.clone(), err))?;
    } else {
        debug!("Skipping validation request for unsupported publish URL: {registry}");
    }

    Ok(())
}

/// Check whether we should skip the upload of a file because it already exists on the index.
pub async fn check_url(
    check_url_client: &CheckUrlClient<'_>,
    file: &Path,
    filename: &DistFilename,
    download_concurrency: &Semaphore,
) -> Result<bool, PublishError> {
    let CheckUrlClient {
        index_url,
        registry_client_builder,
        client,
        index_capabilities,
        cache,
    } = check_url_client;

    // Avoid using the PyPI 10min default cache.
    let cache_refresh = (*cache)
        .clone()
        .with_refresh(Refresh::from_args(None, vec![filename.name().clone()]));
    let registry_client = registry_client_builder
        .clone()
        .cache(cache_refresh)
        .wrap_existing(client);

    debug!("Checking for {filename} in the registry");
    let response = match registry_client
        .package_metadata(
            filename.name(),
            Some(index_url.into()),
            index_capabilities,