From eae8aa3aa9279cadf8787dcab8d2e9f4bc9badd3 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 19 Dec 2018 12:49:23 +0100 Subject: [PATCH] cleanups: avoid compiler warnings --- src/backup/chunk_store.rs | 46 +++++++++++++++++++-------------------- src/bin/backup-client.rs | 6 ++--- src/tools.rs | 3 +-- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 223e0897..2377716a 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -17,7 +17,7 @@ pub struct ChunkStore { chunk_dir: PathBuf, hasher: Sha512Trunc256, mutex: Mutex, - lockfile: File, + _lockfile: File, } const HEX_CHARS: &'static [u8; 16] = b"0123456789abcdef"; @@ -108,7 +108,7 @@ impl ChunkStore { base, chunk_dir, hasher: Sha512Trunc256::new(), - lockfile, + _lockfile: lockfile, mutex: Mutex::new(false) }) } @@ -133,28 +133,26 @@ impl ChunkStore { let now = unsafe { libc::time(std::ptr::null_mut()) }; for entry in handle.iter() { - match entry { - Ok(entry) => { - if let Some(file_type) = entry.file_type() { - if file_type == nix::dir::Type::File { - let filename = entry.file_name(); - if let Ok(stat) = nix::sys::stat::fstatat(rawfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) { - let age = now - stat.st_atime; - println!("FOUND {} {:?}", age/(3600*24), filename); - if age/(3600*24) >= 2 { - println!("UNLINK {} {:?}", age/(3600*24), filename); - unsafe { libc::unlinkat(rawfd, filename.as_ptr(), 0); } - } - } - } - } - } - Err(_) => { - // fixme ?? - } - } - } + let entry = match entry { + Ok(entry) => entry, + Err(_) => continue /* ignore */, + }; + let file_type = match entry.file_type() { + Some(file_type) => file_type, + None => continue, + }; + if file_type != nix::dir::Type::File { continue; } + let filename = entry.file_name(); + if let Ok(stat) = nix::sys::stat::fstatat(rawfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) { + let age = now - stat.st_atime; + println!("FOUND {} {:?}", age/(3600*24), filename); + if age/(3600*24) >= 2 { + println!("UNLINK {} {:?}", age/(3600*24), filename); + unsafe { libc::unlinkat(rawfd, filename.as_ptr(), 0); } + } + } + } } pub fn sweep_used_chunks(&mut self) -> Result<(), Error> { @@ -163,7 +161,7 @@ impl ChunkStore { use nix::sys::stat::Mode; use nix::dir::Dir; - let mut base_handle = match Dir::open( + let base_handle = match Dir::open( &self.chunk_dir, OFlag::O_RDONLY, Mode::empty()) { Ok(h) => h, Err(err) => bail!("unable to open base chunk dir {:?} - {}", self.chunk_dir, err), diff --git a/src/bin/backup-client.rs b/src/bin/backup-client.rs index e1536ee4..cb4be410 100644 --- a/src/bin/backup-client.rs +++ b/src/bin/backup-client.rs @@ -7,12 +7,12 @@ use apitest::tools; use apitest::cli::command::*; use apitest::api::schema::*; use apitest::api::router::*; -use apitest::backup::chunk_store::*; -use apitest::backup::image_index::*; +//use apitest::backup::chunk_store::*; +//use apitest::backup::image_index::*; +//use apitest::config::datastore; use apitest::backup::datastore::*; use serde_json::{Value}; -use apitest::config::datastore; fn required_string_param<'a>(param: &'a Value, name: &str) -> &'a str { param[name].as_str().expect(&format!("missing parameter '{}'", name)) diff --git a/src/tools.rs b/src/tools.rs index 09a6076a..3c75bfff 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -9,7 +9,7 @@ use std::io::Read; use std::io::ErrorKind; use std::time::Duration; -use std::os::unix::io::{RawFd, AsRawFd}; +use std::os::unix::io::AsRawFd; pub mod timer; @@ -173,5 +173,4 @@ pub fn file_chunker( } Ok(()) - }