Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
n-dusan committed Dec 28, 2023
1 parent 32c7c82 commit 80d9f01
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
8 changes: 5 additions & 3 deletions src/server/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ use actix_http::body::MessageBody;
use actix_service::ServiceFactory;
use std::sync::OnceLock;

/// Name of the header to guard current documents
static HEADER_NAME: OnceLock<String> = OnceLock::new();
/// Values of the header to guard current documents
static HEADER_VALUES: OnceLock<Vec<String>> = OnceLock::new();

#[allow(clippy::expect_used)]
/// Remove leading and trailing `/`s from the `path` string.
fn clean_path(path: &str) -> String {
Expand Down Expand Up @@ -175,10 +180,7 @@ pub fn init_app(

match stelae_guard {
Some(guard) => {
static HEADER_NAME: OnceLock<String> = OnceLock::new();
HEADER_NAME.get_or_init(|| guard);

static HEADER_VALUES: OnceLock<Vec<String>> = OnceLock::new();
HEADER_VALUES.get_or_init(|| {
state
.archive
Expand Down
10 changes: 5 additions & 5 deletions src/stelae/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Archive {
let root: Stele;
if let Some(individual_path) = path {
tracing::info!("Serving individual Stele at path: {:?}", individual_path);
root = Stele::new(self.path.clone(), None, None, Some(individual_path), true)?;
root = Stele::new(&self.path, None, None, Some(individual_path), true)?;
} else {
let conf = self.get_config()?;

Expand All @@ -59,7 +59,7 @@ impl Archive {
tracing::info!("Serving {}/{} at path: {:?}", &org, &name, self.path);

root = Stele::new(
self.path.clone(),
&self.path,
Some(name),
Some(org.clone()),
Some(self.path.clone().join(org)),
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Archive {
continue;
}
let child = Stele::new(
self.path.clone(),
&self.path,
Some(name),
Some(org.clone()),
Some(parent_dir.join(org)),
Expand Down Expand Up @@ -140,9 +140,9 @@ fn raise_error_if_in_existing_archive(path: &Path) -> anyhow::Result<bool> {
#[derive(Deserialize, Serialize)]
pub struct Config {
/// The root Stele for this archive
root: stele::Config,
pub root: stele::Config,
/// Whether this is a shallow archive (all repos depth=1)
shallow: bool,
pub shallow: bool,
/// Custom HTTP headers used to interact with the Stele
pub headers: Option<Headers>,
}
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/stelae/stele.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The Stele module contains the Stele object for interacting with
//! Stelae.
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use super::types::repositories::Repository;
use crate::{
Expand Down Expand Up @@ -34,7 +34,7 @@ impl Stele {
/// Will panic if unable to determine the current root Stele.
#[allow(clippy::unwrap_used, clippy::shadow_reuse)]
pub fn new(
archive_path: PathBuf,
archive_path: &Path,
name: Option<String>,
org: Option<String>,
path: Option<PathBuf>,
Expand All @@ -52,13 +52,13 @@ impl Stele {
});
let path = path.unwrap_or_else(|| archive_path.join(&org));
let mut stele = Self {
archive_path: archive_path.clone(),
archive_path: archive_path.to_path_buf(),
repositories: None,
root,
auth_repo: Repo {
archive_path: archive_path.to_string_lossy().to_string(),
path: path.join(&name),
org: org.clone(),
org,
name: name.clone(),
repo: GitRepository::open(path.join(&name)).unwrap(),
},
Expand Down Expand Up @@ -109,8 +109,8 @@ impl Stele {
/// Returns the first fallback repository found, or None if no fallback repository is found.
#[must_use]
pub fn get_fallback_repo(&self) -> Option<Repository> {
if let &Some(ref repositories) = &self.repositories {
for (name, repository) in &repositories.repositories {
if let Some(repositories) = &self.repositories {
for repository in repositories.repositories.values() {
let custom = &repository.custom;
if let Some(ref is_fallback) = custom.is_fallback {
if *is_fallback {
Expand Down
17 changes: 10 additions & 7 deletions src/stelae/types/repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use serde_json::Value;
/// {
/// "scopes": ["us/ca/cities/san-mateo"],
/// "repositories": {
/// "test_org_1/data_repo_1": {
/// "`test_org_1/data_repo_1"`: {
/// "custom": {
/// "routes": ["example-route-glob-pattern-1"]
/// }
/// },
/// "test_org_1/data_repo_2": {
/// "`test_org_1/data_repo_2"`: {
/// "custom": {
/// "serve-prefix": "_prefix"
/// }
Expand Down Expand Up @@ -85,6 +85,7 @@ impl Repositories {
/// Get the repositories sorted by the length of their routes, longest first.
///
/// This is needed for serving current documents because Actix routes are matched in the order they are added.
#[must_use]
pub fn get_sorted_repositories(&self) -> Vec<&Repository> {
let mut result = Vec::new();
for repository in self.repositories.values() {
Expand All @@ -103,11 +104,13 @@ impl Repositories {
}
}

#[allow(clippy::missing_trait_methods)]
impl<'de> Deserialize<'de> for Repositories {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
/// Visitor for the Repositories struct
struct RepositoriesVisitor;

impl<'de> Visitor<'de> for RepositoriesVisitor {
Expand All @@ -131,7 +134,7 @@ impl<'de> Deserialize<'de> for Repositories {
"repositories" => {
let repos: HashMap<String, Value> = map.next_value()?;
let mut new_repos = HashMap::new();
for (key, value) in repos {
for (map_key, value) in repos {
let custom_value = value.get("custom").ok_or_else(|| {
serde::de::Error::custom("Missing 'custom' field")
})?;
Expand All @@ -142,10 +145,10 @@ impl<'de> Deserialize<'de> for Repositories {
))
})?;
let repo = Repository {
name: key.clone(),
name: map_key.clone(),
custom,
};
new_repos.insert(key, repo);
new_repos.insert(map_key, repo);
}
repositories = new_repos;
}
Expand All @@ -160,8 +163,8 @@ impl<'de> Deserialize<'de> for Repositories {
})
}
}

const FIELDS: &'static [&'static str] = &["scopes", "repositories"];
/// Expected fields in the `repositories.json` file.
const FIELDS: &[&'static str] = &["scopes", "repositories"];
deserializer.deserialize_struct("Repositories", FIELDS, RepositoriesVisitor)
}
}
1 change: 1 addition & 0 deletions src/utils/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl fmt::Debug for Repo {
}
}

#[allow(clippy::missing_trait_methods, clippy::unwrap_used)]
impl Clone for Repo {
fn clone(&self) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn get_contenttype(path: &str) -> ContentType {
.extension()
.map_or("html", |ext| ext.to_str().map_or("", |ext_str| ext_str));
let mime = file_extension_to_mime(extension).first_or(mime::TEXT_HTML);
if (mime.type_(), mime.subtype().as_str()) == ((mime::APPLICATION, "rdf")) {
if (mime.type_(), mime.subtype().as_str()) == (mime::APPLICATION, "rdf") {
return ContentType(mime::TEXT_PLAIN);
}
ContentType(mime)
Expand Down

0 comments on commit 80d9f01

Please sign in to comment.