From ddbdf80d51b9deb0ace440a928931d8734054965 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 11 Jan 2019 08:41:33 +0100 Subject: [PATCH] avoid compiler warnings --- src/backup/archive_index.rs | 18 +++++++----------- src/backup/chunker.rs | 2 -- src/backup/image_index.rs | 2 +- src/catar/decoder.rs | 16 +++++++--------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/backup/archive_index.rs b/src/backup/archive_index.rs index 229f4bb7..1e8918e5 100644 --- a/src/backup/archive_index.rs +++ b/src/backup/archive_index.rs @@ -8,7 +8,7 @@ use std::fs::File; use std::path::{Path, PathBuf}; use std::os::unix::io::AsRawFd; use uuid::Uuid; -use chrono::{Local, TimeZone}; +//use chrono::{Local, TimeZone}; #[repr(C)] pub struct ArchiveIndexHeader { @@ -78,7 +78,7 @@ impl <'a> ArchiveIndexReader<'a> { let size = stat.st_size as usize; - let index_size = (size - header_size); + let index_size = size - header_size; if (index_size % 40) != 0 { bail!("got unexpected file size for {:?}", path); } @@ -132,7 +132,7 @@ impl <'a> ArchiveIndexReader<'a> { unsafe { std::slice::from_raw_parts(self.index.add(pos*40+8), 32) } } - pub fn mark_used_chunks(&self, status: &mut GarbageCollectionStatus) -> Result<(), Error> { + pub fn mark_used_chunks(&self, _status: &mut GarbageCollectionStatus) -> Result<(), Error> { for pos in 0..self.index_entries { let digest = self.chunk_digest(pos); @@ -149,7 +149,7 @@ impl <'a> ArchiveIndexReader<'a> { let mut buffer = Vec::with_capacity(1024*1024); for pos in 0..self.index_entries { - let end = self.chunk_end(pos); + let _end = self.chunk_end(pos); let digest = self.chunk_digest(pos); //println!("Dump {:08x}", end ); self.store.read_chunk(digest, &mut buffer)?; @@ -292,7 +292,7 @@ impl <'a> std::io::Seek for BufferedArchiveReader<'a> { fn seek(&mut self, pos: std::io::SeekFrom) -> Result { - use std::io::{SeekFrom, Error, ErrorKind}; + use std::io::{SeekFrom}; let new_offset = match pos { SeekFrom::Start(start_offset) => start_offset as i64, @@ -300,6 +300,7 @@ impl <'a> std::io::Seek for BufferedArchiveReader<'a> { SeekFrom::Current(offset) => (self.read_offset as i64) + offset, }; + use std::io::{Error, ErrorKind}; if (new_offset < 0) || (new_offset > (self.archive_size as i64)) { return Err(Error::new( ErrorKind::Other, @@ -334,7 +335,7 @@ impl <'a> ArchiveIndexWriter<'a> { let mut tmp_path = full_path.clone(); tmp_path.set_extension("tmp_aidx"); - let mut file = std::fs::OpenOptions::new() + let file = std::fs::OpenOptions::new() .create(true).truncate(true) .read(true) .write(true) @@ -419,7 +420,6 @@ impl <'a> ArchiveIndexWriter<'a> { match self.store.insert_chunk(&self.chunk_buffer) { Ok((is_duplicate, digest)) => { println!("ADD CHUNK {:016x} {} {} {}", self.chunk_offset, chunk_size, is_duplicate, digest_to_hex(&digest)); - let chunk_end = self.writer.write(unsafe { &std::mem::transmute::(self.chunk_offset as u64) })?; self.writer.write(&digest)?; self.chunk_buffer.truncate(0); @@ -430,8 +430,6 @@ impl <'a> ArchiveIndexWriter<'a> { return Err(Error::new(ErrorKind::Other, err.to_string())); } } - - Ok(()) } } @@ -439,8 +437,6 @@ impl <'a> Write for ArchiveIndexWriter<'a> { fn write(&mut self, data: &[u8]) -> std::result::Result { - use std::io::{Error, ErrorKind}; - let chunker = &mut self.chunker; let pos = chunker.scan(data); diff --git a/src/backup/chunker.rs b/src/backup/chunker.rs index bac582ee..2ac053c3 100644 --- a/src/backup/chunker.rs +++ b/src/backup/chunker.rs @@ -8,8 +8,6 @@ //! Hash](https://en.wikipedia.org/wiki/Rolling_hash) artikel from //! wikipedia. -use std::io::Write; - const CA_CHUNKER_WINDOW_SIZE: usize = 48; pub struct Chunker { diff --git a/src/backup/image_index.rs b/src/backup/image_index.rs index 3351e447..e362b2de 100644 --- a/src/backup/image_index.rs +++ b/src/backup/image_index.rs @@ -80,7 +80,7 @@ impl <'a> ImageIndexReader<'a> { Err(err) => bail!("fstat {:?} failed - {}", path, err), }; - let expected_index_size = ((stat.st_size as usize) - header_size); + let expected_index_size = (stat.st_size as usize) - header_size; if index_size != expected_index_size { bail!("got unexpected file size for {:?} ({} != {})", path, index_size, expected_index_size); diff --git a/src/catar/decoder.rs b/src/catar/decoder.rs index 43f89c88..877d85b1 100644 --- a/src/catar/decoder.rs +++ b/src/catar/decoder.rs @@ -154,11 +154,12 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { Ok(()) } - fn restore_attributes(&mut self, entry: &CaFormatEntry) -> Result { + fn restore_attributes(&mut self, _entry: &CaFormatEntry) -> Result { loop { let head: CaFormatHeader = self.read_item()?; match head.htype { + // fimxe: impl ... _ => return Ok(head), } } @@ -287,9 +288,6 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { let head: CaFormatHeader = self.read_item()?; match head.htype { CA_FORMAT_SYMLINK => { - if ((mode & libc::S_IFMT) != libc::S_IFLNK) { - bail!("detected unexpected symlink item."); - } let target = self.read_symlink(head.size)?; println!("TARGET: {:?}", target); if let Err(err) = symlinkat(&target, parent_fd, filename) { @@ -320,7 +318,7 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { Err(err) => bail!("open file {:?} failed - {}", path, err), }; - let mut head = self.restore_attributes(&entry)?; + let head = self.restore_attributes(&entry)?; if head.htype != CA_FORMAT_PAYLOAD { bail!("got unknown header type for file entry {:016x}", head.htype); @@ -333,7 +331,7 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { //self.reader.seek(SeekFrom::Current(need as i64))?; let mut done = 0; - while (done < need) { + while done < need { let todo = need - done; let n = if todo > read_buffer.len() { read_buffer.len() } else { todo }; let data = &mut read_buffer[..n]; @@ -363,7 +361,7 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { bail!("wrong filename header type for object [{}..{}]", start, end); } - let mut name_len = u64::from_le(head.size); + let name_len = u64::from_le(head.size); let entry_start = start + name_len; @@ -454,7 +452,7 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { i, start, end, item_offset, goodbye_start, start); } let item_start = goodbye_start - item_offset; - let item_hash = u64::from_le(item.hash); + let _item_hash = u64::from_le(item.hash); let item_end = item_start + u64::from_le(item.size); if item_end > goodbye_start { bail!("goodbye entry {} end out of range [{}..{}]", @@ -513,7 +511,7 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> { fn file_openat(parent: RawFd, filename: &OsStr, flags: OFlag, mode: Mode) -> Result { - let fd = filename.with_nix_path(|cstr| unsafe { + let fd = filename.with_nix_path(|cstr| { nix::fcntl::openat(parent, cstr.as_ref(), flags, mode) })??;