avoid compiler warnings

This commit is contained in:
Dietmar Maurer 2019-01-11 08:41:33 +01:00
parent 373ef4a504
commit ddbdf80d51
4 changed files with 15 additions and 23 deletions

View File

@ -8,7 +8,7 @@ use std::fs::File;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use uuid::Uuid; use uuid::Uuid;
use chrono::{Local, TimeZone}; //use chrono::{Local, TimeZone};
#[repr(C)] #[repr(C)]
pub struct ArchiveIndexHeader { pub struct ArchiveIndexHeader {
@ -78,7 +78,7 @@ impl <'a> ArchiveIndexReader<'a> {
let size = stat.st_size as usize; let size = stat.st_size as usize;
let index_size = (size - header_size); let index_size = size - header_size;
if (index_size % 40) != 0 { if (index_size % 40) != 0 {
bail!("got unexpected file size for {:?}", path); 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) } 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 { for pos in 0..self.index_entries {
let digest = self.chunk_digest(pos); let digest = self.chunk_digest(pos);
@ -149,7 +149,7 @@ impl <'a> ArchiveIndexReader<'a> {
let mut buffer = Vec::with_capacity(1024*1024); let mut buffer = Vec::with_capacity(1024*1024);
for pos in 0..self.index_entries { 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); let digest = self.chunk_digest(pos);
//println!("Dump {:08x}", end ); //println!("Dump {:08x}", end );
self.store.read_chunk(digest, &mut buffer)?; 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<u64, std::io::Error> { fn seek(&mut self, pos: std::io::SeekFrom) -> Result<u64, std::io::Error> {
use std::io::{SeekFrom, Error, ErrorKind}; use std::io::{SeekFrom};
let new_offset = match pos { let new_offset = match pos {
SeekFrom::Start(start_offset) => start_offset as i64, 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, 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)) { if (new_offset < 0) || (new_offset > (self.archive_size as i64)) {
return Err(Error::new( return Err(Error::new(
ErrorKind::Other, ErrorKind::Other,
@ -334,7 +335,7 @@ impl <'a> ArchiveIndexWriter<'a> {
let mut tmp_path = full_path.clone(); let mut tmp_path = full_path.clone();
tmp_path.set_extension("tmp_aidx"); tmp_path.set_extension("tmp_aidx");
let mut file = std::fs::OpenOptions::new() let file = std::fs::OpenOptions::new()
.create(true).truncate(true) .create(true).truncate(true)
.read(true) .read(true)
.write(true) .write(true)
@ -419,7 +420,6 @@ impl <'a> ArchiveIndexWriter<'a> {
match self.store.insert_chunk(&self.chunk_buffer) { match self.store.insert_chunk(&self.chunk_buffer) {
Ok((is_duplicate, digest)) => { Ok((is_duplicate, digest)) => {
println!("ADD CHUNK {:016x} {} {} {}", self.chunk_offset, chunk_size, is_duplicate, digest_to_hex(&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::<u64, [u8;8]>(self.chunk_offset as u64) })?; self.writer.write(unsafe { &std::mem::transmute::<u64, [u8;8]>(self.chunk_offset as u64) })?;
self.writer.write(&digest)?; self.writer.write(&digest)?;
self.chunk_buffer.truncate(0); self.chunk_buffer.truncate(0);
@ -430,8 +430,6 @@ impl <'a> ArchiveIndexWriter<'a> {
return Err(Error::new(ErrorKind::Other, err.to_string())); 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<usize, std::io::Error> { fn write(&mut self, data: &[u8]) -> std::result::Result<usize, std::io::Error> {
use std::io::{Error, ErrorKind};
let chunker = &mut self.chunker; let chunker = &mut self.chunker;
let pos = chunker.scan(data); let pos = chunker.scan(data);

View File

@ -8,8 +8,6 @@
//! Hash](https://en.wikipedia.org/wiki/Rolling_hash) artikel from //! Hash](https://en.wikipedia.org/wiki/Rolling_hash) artikel from
//! wikipedia. //! wikipedia.
use std::io::Write;
const CA_CHUNKER_WINDOW_SIZE: usize = 48; const CA_CHUNKER_WINDOW_SIZE: usize = 48;
pub struct Chunker { pub struct Chunker {

View File

@ -80,7 +80,7 @@ impl <'a> ImageIndexReader<'a> {
Err(err) => bail!("fstat {:?} failed - {}", path, err), 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 { if index_size != expected_index_size {
bail!("got unexpected file size for {:?} ({} != {})", bail!("got unexpected file size for {:?} ({} != {})",
path, index_size, expected_index_size); path, index_size, expected_index_size);

View File

@ -154,11 +154,12 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> {
Ok(()) Ok(())
} }
fn restore_attributes(&mut self, entry: &CaFormatEntry) -> Result<CaFormatHeader, Error> { fn restore_attributes(&mut self, _entry: &CaFormatEntry) -> Result<CaFormatHeader, Error> {
loop { loop {
let head: CaFormatHeader = self.read_item()?; let head: CaFormatHeader = self.read_item()?;
match head.htype { match head.htype {
// fimxe: impl ...
_ => return Ok(head), _ => return Ok(head),
} }
} }
@ -287,9 +288,6 @@ impl <'a, R: Read + Seek> CaTarDecoder<'a, R> {
let head: CaFormatHeader = self.read_item()?; let head: CaFormatHeader = self.read_item()?;
match head.htype { match head.htype {
CA_FORMAT_SYMLINK => { CA_FORMAT_SYMLINK => {
if ((mode & libc::S_IFMT) != libc::S_IFLNK) {
bail!("detected unexpected symlink item.");
}
let target = self.read_symlink(head.size)?; let target = self.read_symlink(head.size)?;
println!("TARGET: {:?}", target); println!("TARGET: {:?}", target);
if let Err(err) = symlinkat(&target, parent_fd, filename) { 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), 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 { if head.htype != CA_FORMAT_PAYLOAD {
bail!("got unknown header type for file entry {:016x}", head.htype); 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))?; //self.reader.seek(SeekFrom::Current(need as i64))?;
let mut done = 0; let mut done = 0;
while (done < need) { while done < need {
let todo = need - done; let todo = need - done;
let n = if todo > read_buffer.len() { read_buffer.len() } else { todo }; let n = if todo > read_buffer.len() { read_buffer.len() } else { todo };
let data = &mut read_buffer[..n]; 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); 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; 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); i, start, end, item_offset, goodbye_start, start);
} }
let item_start = goodbye_start - item_offset; 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); let item_end = item_start + u64::from_le(item.size);
if item_end > goodbye_start { if item_end > goodbye_start {
bail!("goodbye entry {} end out of range [{}..{}]", 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<std::fs::File, Error> { fn file_openat(parent: RawFd, filename: &OsStr, flags: OFlag, mode: Mode) -> Result<std::fs::File, Error> {
let fd = filename.with_nix_path(|cstr| unsafe { let fd = filename.with_nix_path(|cstr| {
nix::fcntl::openat(parent, cstr.as_ref(), flags, mode) nix::fcntl::openat(parent, cstr.as_ref(), flags, mode)
})??; })??;