]> git.proxmox.com Git - proxmox.git/commitdiff
sys: rust fmt
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 10 Apr 2022 15:22:39 +0000 (17:22 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 10 Apr 2022 15:39:31 +0000 (17:39 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
13 files changed:
proxmox-sys/src/command.rs
proxmox-sys/src/crypt.rs
proxmox-sys/src/fd/raw_fd_num.rs
proxmox-sys/src/fs/acl.rs
proxmox-sys/src/fs/file.rs
proxmox-sys/src/fs/mod.rs
proxmox-sys/src/linux/mod.rs
proxmox-sys/src/linux/pid.rs
proxmox-sys/src/linux/procfs/mountinfo.rs
proxmox-sys/src/linux/socket.rs
proxmox-sys/src/logrotate.rs
proxmox-sys/src/worker_task_context.rs
proxmox-sys/tests/xattr.rs

index b99466da0c32574bc495a382fa4e2400c359ada6..bc2ff2496c2e55c3e54bf26eb5ecf30cc9114ff8 100644 (file)
@@ -1,6 +1,6 @@
 //! Helpers to run a [Command] and check status code
 
-use std::process::{Output, Command};
+use std::process::{Command, Output};
 
 use anyhow::{bail, format_err, Error};
 
index 28e21aee3d0e04cdebf317214e1da610a800b16d..ab4268523678b889299d8e412fe8400e09c18f81 100644 (file)
@@ -56,7 +56,6 @@ pub fn crypt(password: &[u8], salt: &[u8]) -> Result<String, Error> {
 
 /// Encrypt a pasword using sha256 hashing method
 pub fn encrypt_pw(password: &str) -> Result<String, Error> {
-
     let salt = crate::linux::random_data(8)?;
     let salt = format!("$5${}$", base64::encode_config(&salt, base64::CRYPT));
 
index 7356c05f161efbc04d38d58df4bee05ec1f1de88..1b83c6d63d10d6ae4039e18d870cadf3f1b712b4 100644 (file)
@@ -52,4 +52,3 @@ impl std::ops::Deref for RawFdNum {
         self.as_fd_ref()
     }
 }
-
index 80e27812d06054890017fbedabd9118192d00f8e..6cf00fe64ebed46c36acbf7496a8ce7aad0b2227 100644 (file)
@@ -76,7 +76,10 @@ impl Drop for ACL {
     fn drop(&mut self) {
         let ret = unsafe { acl_free(self.ptr) };
         if ret != 0 {
-            panic!("invalid pointer encountered while dropping ACL - {}", Errno::last());
+            panic!(
+                "invalid pointer encountered while dropping ACL - {}",
+                Errno::last()
+            );
         }
     }
 }
@@ -97,7 +100,7 @@ impl ACL {
         if ptr.is_null() {
             return Err(Errno::last());
         }
+
         Ok(ACL { ptr })
     }
 
@@ -146,9 +149,12 @@ impl ACL {
         }
     }
 
-    pub fn add_entry_full(&mut self, tag: ACLTag, qualifier: Option<u64>, permissions: u64)
-        -> Result<(), nix::errno::Errno>
-    {
+    pub fn add_entry_full(
+        &mut self,
+        tag: ACLTag,
+        qualifier: Option<u64>,
+        permissions: u64,
+    ) -> Result<(), nix::errno::Errno> {
         let mut entry = self.create_entry()?;
         entry.set_tag_type(tag)?;
         if let Some(qualifier) = qualifier {
@@ -240,7 +246,10 @@ impl<'a> ACLEntry<'a> {
         let result = unsafe { *(qualifier as *const u32) as u64 };
         let ret = unsafe { acl_free(qualifier) };
         if ret != 0 {
-            panic!("invalid pointer encountered while dropping ACL qualifier - {}", Errno::last());
+            panic!(
+                "invalid pointer encountered while dropping ACL qualifier - {}",
+                Errno::last()
+            );
         }
 
         Ok(result)
@@ -272,7 +281,10 @@ impl<'a> Iterator for &'a mut ACLEntriesIterator {
         let res = unsafe { acl_get_entry(self.acl.ptr, self.current, &mut entry_ptr) };
         self.current = ACL_NEXT_ENTRY;
         if res == 1 {
-            return Some(ACLEntry { ptr: entry_ptr, _phantom: PhantomData });
+            return Some(ACLEntry {
+                ptr: entry_ptr,
+                _phantom: PhantomData,
+            });
         }
 
         None
@@ -312,10 +324,15 @@ impl ACLXAttrBuffer {
     /// Add ACL entry to buffer.
     pub fn add_entry(&mut self, tag: ACLTag, qualifier: Option<u64>, permissions: u64) {
         self.buffer.extend_from_slice(&(tag as u16).to_le_bytes());
-        self.buffer.extend_from_slice(&(permissions as u16).to_le_bytes());
+        self.buffer
+            .extend_from_slice(&(permissions as u16).to_le_bytes());
         match qualifier {
-            Some(qualifier) => self.buffer.extend_from_slice(&(qualifier as u32).to_le_bytes()),
-            None => self.buffer.extend_from_slice(&ACL_UNDEFINED_ID.to_le_bytes()),
+            Some(qualifier) => self
+                .buffer
+                .extend_from_slice(&(qualifier as u32).to_le_bytes()),
+            None => self
+                .buffer
+                .extend_from_slice(&ACL_UNDEFINED_ID.to_le_bytes()),
         }
     }
 
@@ -325,7 +342,9 @@ impl ACLXAttrBuffer {
     }
 
     /// The buffer always contains at least the version, it is never empty
-    pub const fn is_empty(&self) -> bool { false }
+    pub const fn is_empty(&self) -> bool {
+        false
+    }
 
     /// Borrow raw buffer as mut slice.
     pub fn as_mut_slice(&mut self) -> &mut [u8] {
index 180a35f2957fe146b1f2e10867fb1e830b70472c..a096db43037b19a54680c5fa9f70688c827815dd 100644 (file)
@@ -316,7 +316,6 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
     }
 }
 
-
 // /usr/include/linux/fs.h: #define BLKGETSIZE64 _IOR(0x12,114,size_t)
 // return device size in bytes (u64 *arg)
 nix::ioctl_read!(blkgetsize64, 0x12, 114, u64);
index ee4ef423e835a6c22ae00aaef75b5c3a306e4580..4aa06b2055cf4943b5a6230aa2a0b1eb61131b9e 100644 (file)
@@ -1,12 +1,12 @@
-//! File system related utilities 
+//! File system related utilities
 use std::fs::File;
 use std::path::Path;
 
 use anyhow::{bail, Error};
 
-use std::os::unix::io::{AsRawFd, RawFd};
-use nix::unistd::{Gid, Uid};
 use nix::sys::stat;
+use nix::unistd::{Gid, Uid};
+use std::os::unix::io::{AsRawFd, RawFd};
 
 pub mod acl;
 
@@ -68,11 +68,9 @@ impl CreateOptions {
     }
 
     pub fn apply_to(&self, file: &mut File, path: &Path) -> Result<(), Error> {
-
         // clippy bug?: from_bits_truncate is actually a const fn...
         #[allow(clippy::or_fun_call)]
-        let mode: stat::Mode = self.perm
-            .unwrap_or(stat::Mode::from_bits_truncate(0o644));
+        let mode: stat::Mode = self.perm.unwrap_or(stat::Mode::from_bits_truncate(0o644));
 
         if let Err(err) = stat::fchmod(file.as_raw_fd(), mode) {
             bail!("fchmod {:?} failed: {}", path, err);
index 7477a4e6a42c8b5c3dc32a71b962fcf7b69b2f3d..fce3b8b4c8632d200d3da6126a765c7ce840e8cd 100644 (file)
@@ -1,6 +1,6 @@
 //! Linux specific helpers and syscall wrapper
 
-use anyhow::{bail,Error};
+use anyhow::{bail, Error};
 
 use proxmox_io::vec;
 
index 07d71632573e5d9a0788a0b5335be58322576881..9d70824360cd54fdc956a6f01b20d52736fe3ea1 100644 (file)
@@ -14,8 +14,8 @@ use nix::NixPath;
 use proxmox_lang::{c_str, error::io_err_other};
 
 use crate::error::SysResult;
-use crate::linux::procfs::{MountInfo, PidStat};
 use crate::fd::Fd;
+use crate::linux::procfs::{MountInfo, PidStat};
 use crate::{c_result, c_try};
 
 /// asm-generic pidfd_open syscall number
index 2848425c6bea1929574729fb85b2b136049f88b9..ab449c6a3d800ab1d085cc15fc8f194132df2b54 100644 (file)
@@ -311,10 +311,7 @@ fn test_entry() {
         }]
     );
     assert_eq!(entry.fs_type, "cgroup");
-    assert_eq!(
-        entry.mount_source.as_deref(),
-        Some(OsStr::new("cgroup"))
-    );
+    assert_eq!(entry.mount_source.as_deref(), Some(OsStr::new("cgroup")));
     assert_eq!(entry.super_options, "rw,blkio");
 
     let l2 = b"49 28 0:44 / /proxmox/debian rw,relatime shared:27 - autofs systemd-1 \
@@ -340,10 +337,7 @@ fn test_entry() {
         }]
     );
     assert_eq!(entry.fs_type, "autofs");
-    assert_eq!(
-        entry.mount_source.as_deref(),
-        Some(OsStr::new("systemd-1"))
-    );
+    assert_eq!(entry.mount_source.as_deref(), Some(OsStr::new("systemd-1")));
     assert_eq!(
         entry.super_options,
         "rw,fd=26,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=27726"
index 6c63c3c2f841d0a7eba09765e138d6f8802edaa0..a9a575cb310a6693c826453262f24c3bcd7b96d9 100644 (file)
@@ -1,7 +1,7 @@
 use std::os::unix::io::RawFd;
 
-use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle};
 use nix::sys::socket::setsockopt;
+use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle};
 
 /// Set TCP keepalive time on a socket
 ///
@@ -9,11 +9,7 @@ use nix::sys::socket::setsockopt;
 ///
 /// The default on Linux is 7200 (2 hours) which is far too long for
 /// many of our use cases.
-pub fn set_tcp_keepalive(
-    socket_fd: RawFd,
-    tcp_keepalive_time: u32,
-) -> nix::Result<()> {
-
+pub fn set_tcp_keepalive(socket_fd: RawFd, tcp_keepalive_time: u32) -> nix::Result<()> {
     setsockopt(socket_fd, KeepAlive, &true)?;
     setsockopt(socket_fd, TcpKeepIdle, &tcp_keepalive_time)?;
 
index 6b82970bab6d836a46636f9126be065e9f2d3a05..704a18ce0c31e00d3b44d6fdb1ba696e0f669e24 100644 (file)
@@ -1,14 +1,14 @@
 //! Log rotation helper
 
-use std::path::{Path, PathBuf};
-use std::fs::{File, rename};
-use std::os::unix::io::{FromRawFd, IntoRawFd};
+use std::fs::{rename, File};
 use std::io::Read;
+use std::os::unix::io::{FromRawFd, IntoRawFd};
+use std::path::{Path, PathBuf};
 
 use anyhow::{bail, Error};
 use nix::unistd;
 
-use crate::fs::{CreateOptions, make_tmp_file};
+use crate::fs::{make_tmp_file, CreateOptions};
 
 /// Used for rotating log files and iterating over them
 pub struct LogRotate {
@@ -47,7 +47,7 @@ impl LogRotate {
         LogRotateFileNames {
             base_path: self.base_path.clone(),
             count: 0,
-            compress: self.compress
+            compress: self.compress,
         }
     }
 
@@ -58,7 +58,11 @@ impl LogRotate {
         }
     }
 
-    fn compress(source_path: &Path, target_path: &Path, options: &CreateOptions) -> Result<(), Error> {
+    fn compress(
+        source_path: &Path,
+        target_path: &Path,
+        options: &CreateOptions,
+    ) -> Result<(), Error> {
         let mut source = File::open(source_path)?;
         let (fd, tmp_path) = make_tmp_file(target_path, options.clone())?;
         let target = unsafe { File::from_raw_fd(fd.into_raw_fd()) };
@@ -114,14 +118,14 @@ impl LogRotate {
 
         filenames.push(PathBuf::from(next_filename));
 
-        for i in (0..count-1).rev() {
+        for i in (0..count - 1).rev() {
             if self.compress
                 && filenames[i].extension() != Some(std::ffi::OsStr::new("zst"))
-                && filenames[i+1].extension() == Some(std::ffi::OsStr::new("zst"))
+                && filenames[i + 1].extension() == Some(std::ffi::OsStr::new("zst"))
             {
-                Self::compress(&filenames[i], &filenames[i+1], &self.options)?;
+                Self::compress(&filenames[i], &filenames[i + 1], &self.options)?;
             } else {
-                rename(&filenames[i], &filenames[i+1])?;
+                rename(&filenames[i], &filenames[i + 1])?;
             }
         }
 
@@ -137,15 +141,11 @@ impl LogRotate {
     }
 
     /// Conditional rotate if file bigger than 'max_size'
-    pub fn rotate(
-        &mut self,
-        max_size: u64,
-    ) -> Result<bool, Error> {
-
+    pub fn rotate(&mut self, max_size: u64) -> Result<bool, Error> {
         let metadata = match self.base_path.metadata() {
             Ok(metadata) => metadata,
             Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(false),
-            Err(err) =>  bail!("unable to open {:?} - {}", self.base_path, err),
+            Err(err) => bail!("unable to open {:?} - {}", self.base_path, err),
         };
 
         if metadata.len() > max_size {
index eeb4d797eb7568e0a69488737f2ef3463df5f133..89d5756073df2cc522da933ff472fdffb5a00c61 100644 (file)
@@ -4,7 +4,6 @@ use anyhow::{bail, Error};
 ///
 /// A worker task is a long running task, which usually logs output into a separate file.
 pub trait WorkerTaskContext: Send + Sync {
-
     /// Test if there was a request to abort the task.
     fn abort_requested(&self) -> bool;
 
@@ -19,7 +18,6 @@ pub trait WorkerTaskContext: Send + Sync {
     /// Test if there was a request to shutdown the server.
     fn shutdown_requested(&self) -> bool;
 
-
     /// This should fail with a reasonable error message if there was
     /// a request to shutdown the server.
     fn fail_on_shutdown(&self) -> Result<(), Error> {
index 55ce81ac616e3fb1b31bc6da936eaa1191a0fd25..43ae523d9415b05df751baa6611726401e7dc3a6 100644 (file)
@@ -1,11 +1,11 @@
-use std::path::PathBuf;
 use std::fs::OpenOptions;
 use std::os::unix::io::AsRawFd;
+use std::path::PathBuf;
 
 use nix::errno::Errno;
 
 use proxmox_lang::c_str;
-use proxmox_sys::fs::xattr::{fgetxattr,fsetxattr};
+use proxmox_sys::fs::xattr::{fgetxattr, fsetxattr};
 
 #[test]
 fn test_fsetxattr_fgetxattr() {
@@ -18,7 +18,6 @@ fn test_fsetxattr_fgetxattr() {
         .open(&path)
         .unwrap();
 
-
     let fd = file.as_raw_fd();
 
     if let Err(Errno::EOPNOTSUPP) = fsetxattr(fd, c_str!("user.attribute0"), b"value0") {
@@ -46,4 +45,4 @@ fn test_fsetxattr_fgetxattr() {
     );
 
     std::fs::remove_file(&path).unwrap();
-}
\ No newline at end of file
+}