This is an automated email from the ASF dual-hosted git repository.

hgruszecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git


The following commit(s) were added to refs/heads/master by this push:
     new cd41fa75 fix(server): fix clippy nursery and pedantic lints in 
archiver (#1840)
cd41fa75 is described below

commit cd41fa75907919608e202fbca86f50c82bdb2986
Author: Hubert Gruszecki <[email protected]>
AuthorDate: Sat Jun 7 11:33:08 2025 +0200

    fix(server): fix clippy nursery and pedantic lints in archiver (#1840)
---
 core/server/src/archiver/disk.rs |  9 +++++----
 core/server/src/archiver/mod.rs  | 31 ++++++++++++++++++++++++++-----
 core/server/src/archiver/s3.rs   | 29 +++++++++++++----------------
 core/server/src/build.rs         |  2 +-
 core/server/src/versioning.rs    |  1 +
 5 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/core/server/src/archiver/disk.rs b/core/server/src/archiver/disk.rs
index 99a82653..c0affe7f 100644
--- a/core/server/src/archiver/disk.rs
+++ b/core/server/src/archiver/disk.rs
@@ -30,8 +30,9 @@ pub struct DiskArchiver {
 }
 
 impl DiskArchiver {
-    pub fn new(config: DiskArchiverConfig) -> Self {
-        DiskArchiver { config }
+    #[must_use]
+    pub const fn new(config: DiskArchiverConfig) -> Self {
+        Self { config }
     }
 }
 
@@ -75,14 +76,14 @@ impl Archiver for DiskArchiver {
             let source = Path::new(file);
             if !source.exists() {
                 return Err(ArchiverError::FileToArchiveNotFound {
-                    file_path: file.to_string(),
+                    file_path: (*file).to_string(),
                 });
             }
 
             let base_directory = base_directory.as_deref().unwrap_or_default();
             let destination = 
Path::new(&self.config.path).join(base_directory).join(file);
             let destination_path = 
destination.to_str().unwrap_or_default().to_owned();
-            fs::create_dir_all(destination.parent().unwrap())
+            fs::create_dir_all(destination.parent().expect("Path should have a 
parent directory"))
                 .await
                 .with_error_context(|error| {
                     format!("{COMPONENT} (error: {error}) - failed to create 
file: {file} at path: {destination_path}",)
diff --git a/core/server/src/archiver/mod.rs b/core/server/src/archiver/mod.rs
index 7b6aaa34..1ecf48b7 100644
--- a/core/server/src/archiver/mod.rs
+++ b/core/server/src/archiver/mod.rs
@@ -32,7 +32,7 @@ use crate::archiver::s3::S3Archiver;
 
 pub const COMPONENT: &str = "ARCHIVER";
 
-#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Display, Copy, 
Clone)]
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Display, Copy, 
Clone)]
 #[serde(rename_all = "lowercase")]
 pub enum ArchiverKindType {
     #[default]
@@ -46,9 +46,9 @@ impl FromStr for ArchiverKindType {
     type Err = String;
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         match s.to_lowercase().as_str() {
-            "disk" => Ok(ArchiverKindType::Disk),
-            "s3" => Ok(ArchiverKindType::S3),
-            _ => Err(format!("Unknown archiver kind: {}", s)),
+            "disk" => Ok(Self::Disk),
+            "s3" => Ok(Self::S3),
+            _ => Err(format!("Unknown archiver kind: {s}")),
         }
     }
 }
@@ -75,15 +75,26 @@ pub enum ArchiverKind {
 }
 
 impl ArchiverKind {
-    pub fn get_disk_archiver(config: DiskArchiverConfig) -> Self {
+    #[must_use]
+    pub const fn get_disk_archiver(config: DiskArchiverConfig) -> Self {
         Self::Disk(DiskArchiver::new(config))
     }
 
+    /// Creates an S3 archiver.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if the S3 archiver cannot be initialized.
     pub fn get_s3_archiver(config: S3ArchiverConfig) -> Result<Self, 
ArchiverError> {
         let archiver = S3Archiver::new(config)?;
         Ok(Self::S3(archiver))
     }
 
+    /// Initializes the archiver.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if the archiver cannot be initialized.
     pub async fn init(&self) -> Result<(), ArchiverError> {
         match self {
             Self::Disk(a) => a.init().await,
@@ -91,6 +102,11 @@ impl ArchiverKind {
         }
     }
 
+    /// Checks if a file is archived.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if the check cannot be performed.
     pub async fn is_archived(
         &self,
         file: &str,
@@ -102,6 +118,11 @@ impl ArchiverKind {
         }
     }
 
+    /// Archives the specified files.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if the files cannot be archived.
     pub async fn archive(
         &self,
         files: &[&str],
diff --git a/core/server/src/archiver/s3.rs b/core/server/src/archiver/s3.rs
index fb6c054c..036945d9 100644
--- a/core/server/src/archiver/s3.rs
+++ b/core/server/src/archiver/s3.rs
@@ -34,6 +34,11 @@ pub struct S3Archiver {
 }
 
 impl S3Archiver {
+    /// Creates a new S3 archiver.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if the S3 client cannot be initialized or credentials 
are invalid.
     pub fn new(config: S3ArchiverConfig) -> Result<Self, ArchiverError> {
         let credentials = Credentials::new(
             Some(&config.key_id),
@@ -47,16 +52,8 @@ impl S3Archiver {
         let bucket = Bucket::new(
             &config.bucket,
             Region::Custom {
-                endpoint: config
-                    .endpoint
-                    .map(|e| e.to_owned())
-                    .unwrap_or("".to_owned())
-                    .to_owned(),
-                region: config
-                    .region
-                    .map(|r| r.to_owned())
-                    .unwrap_or("".to_owned())
-                    .to_owned(),
+                endpoint: config.endpoint.map_or_else(String::new, |e| e),
+                region: config.region.map_or_else(String::new, |r| r),
             },
             credentials,
         )
@@ -76,7 +73,7 @@ impl S3Archiver {
         let destination = Path::new(&self.tmp_upload_dir).join(path);
         let destination_path = 
destination.to_str().unwrap_or_default().to_owned();
         debug!("Creating temporary S3 upload directory: {destination_path}");
-        fs::create_dir_all(destination.parent().unwrap())
+        fs::create_dir_all(destination.parent().expect("Path should have a 
parent directory"))
             .await
             .with_error_context(|error| {
                 format!(
@@ -130,7 +127,7 @@ impl Archiver for S3Archiver {
             return Ok(false);
         }
 
-        let (_, status) = response.unwrap();
+        let (_, status) = response.expect("Response should be valid if not an 
error");
         if status == 200 {
             debug!("File: {file} is archived on S3.");
             return Ok(true);
@@ -148,7 +145,7 @@ impl Archiver for S3Archiver {
         for path in files {
             if !Path::new(path).exists() {
                 return Err(ArchiverError::FileToArchiveNotFound {
-                    file_path: path.to_string(),
+                    file_path: (*path).to_string(),
                 });
             }
 
@@ -170,11 +167,11 @@ impl Archiver for S3Archiver {
                     format!("{COMPONENT} (error: {error}) - failed to remove 
temporary file: {source} after S3 failure")
                 })?;
                 return Err(ArchiverError::CannotArchiveFile {
-                    file_path: path.to_string(),
+                    file_path: (*path).to_string(),
                 });
             }
 
-            let response = response.unwrap();
+            let response = response.expect("Response should be valid if not an 
error");
             let status = response.status_code();
             if status == 200 {
                 debug!("Archived file: {path} on S3.");
@@ -189,7 +186,7 @@ impl Archiver for S3Archiver {
                 format!("{COMPONENT} (error: {error}) - failed to remove 
temporary file: {source} after invalid status code")
             })?;
             return Err(ArchiverError::CannotArchiveFile {
-                file_path: path.to_string(),
+                file_path: (*path).to_string(),
             });
         }
         Ok(())
diff --git a/core/server/src/build.rs b/core/server/src/build.rs
index a3b07277..0f863728 100644
--- a/core/server/src/build.rs
+++ b/core/server/src/build.rs
@@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
             workspace_root
                 .join("configs")
                 .canonicalize()
-                .unwrap()
+                .unwrap_or_else(|e| panic!("Failed to canonicalize path, 
error: {e}"))
                 .display()
         );
     } else {
diff --git a/core/server/src/versioning.rs b/core/server/src/versioning.rs
index 97182e6d..657e48ba 100644
--- a/core/server/src/versioning.rs
+++ b/core/server/src/versioning.rs
@@ -64,6 +64,7 @@ impl SemanticVersion {
         Err(IggyError::InvalidVersion(VERSION.into()))
     }
 
+    #[must_use]
     pub fn is_equal_to(&self, other: &SemanticVersion) -> bool {
         self.major == other.major && self.minor == other.minor && self.patch 
== other.patch
     }

Reply via email to