indexedlog: address clippy warnings

Summary:
These were from a wide variety of warnings. The only one I haven't addressed is
that clippy complains that Pin<Box<Vec<u8>>> can be replaced by Pin<Vec<u8>>. I
haven't investigated too much into it, someone more familiar with this code can
probably figure out if this is buggy or not :)

Reviewed By: DurhamG

Differential Revision: D20469647

fbshipit-source-id: d42891d95c1d21b625230234994ab49bbc45b961
This commit is contained in:
Xavier Deguillard 2020-03-18 10:12:50 -07:00 committed by Facebook GitHub Bot
parent d94e0538f8
commit 8c1f033f50
5 changed files with 10 additions and 14 deletions

View File

@ -1637,7 +1637,7 @@ impl MemChecksum {
// See the comment in `read_from` for `start_chunk_index`. // See the comment in `read_from` for `start_chunk_index`.
// It is the starting index for // It is the starting index for
let start_chunk_index = (self.start >> self.chunk_size_logarithm) as usize; let start_chunk_index = (self.start >> self.chunk_size_logarithm) as usize;
return &self.xxhash_list[start_chunk_index..]; &self.xxhash_list[start_chunk_index..]
} }
/// Reset the `chunk_size_logarithm`. /// Reset the `chunk_size_logarithm`.

View File

@ -694,8 +694,7 @@ impl Log {
pub(crate) fn finalize_indexes(&mut self) -> crate::Result<()> { pub(crate) fn finalize_indexes(&mut self) -> crate::Result<()> {
let result: crate::Result<_> = (|| { let result: crate::Result<_> = (|| {
let dir = self.dir.clone(); let dir = self.dir.clone();
if let Some(ref dir) = dir.as_opt_path() { if let Some(dir) = dir.as_opt_path() {
let dir = dir.clone();
if !self.mem_buf.is_empty() { if !self.mem_buf.is_empty() {
return Err(crate::Error::programming( return Err(crate::Error::programming(
"sync() should be called before finalize_indexes()", "sync() should be called before finalize_indexes()",

View File

@ -83,12 +83,11 @@ impl OpenOptions {
let result: crate::Result<_> = (|| { let result: crate::Result<_> = (|| {
let meta_path = multi_meta_path(path); let meta_path = multi_meta_path(path);
let mut multimeta = MultiMeta::default(); let mut multimeta = MultiMeta::default();
match multimeta.read_file(&meta_path) { if let Err(e) = multimeta.read_file(&meta_path) {
Err(e) => match e.kind() { match e.kind() {
io::ErrorKind::NotFound => (), // not fatal. io::ErrorKind::NotFound => (), // not fatal.
_ => return Err(e).context(&meta_path, "when opening MultiLog"), _ => return Err(e).context(&meta_path, "when opening MultiLog"),
}, }
Ok(_) => (),
}; };
let locked = if self let locked = if self
@ -107,7 +106,7 @@ impl OpenOptions {
let mut logs = Vec::with_capacity(self.name_open_options.len()); let mut logs = Vec::with_capacity(self.name_open_options.len());
for (name, opts) in self.name_open_options.iter() { for (name, opts) in self.name_open_options.iter() {
let fspath = path.join(name); let fspath = path.join(name);
let name_ref: &str = name.as_ref(); let name_ref: &str = name;
if !multimeta.metas.contains_key(name_ref) { if !multimeta.metas.contains_key(name_ref) {
// Create a new Log if it does not exist in MultiMeta. // Create a new Log if it does not exist in MultiMeta.
utils::mkdir_p(&fspath)?; utils::mkdir_p(&fspath)?;
@ -160,7 +159,7 @@ impl MultiLog {
/// A lock must be provided to prove that there is no race condition. /// A lock must be provided to prove that there is no race condition.
/// The lock is usually obtained via `lock()`. /// The lock is usually obtained via `lock()`.
pub fn write_meta(&mut self, lock: &LockGuard) -> crate::Result<()> { pub fn write_meta(&mut self, lock: &LockGuard) -> crate::Result<()> {
if lock.0.path() != &self.path { if lock.0.path() != self.path {
let msg = format!( let msg = format!(
"Invalid lock used to write_meta (Lock path = {:?}, MultiLog path = {:?})", "Invalid lock used to write_meta (Lock path = {:?}, MultiLog path = {:?})",
lock.0.path(), lock.0.path(),

View File

@ -392,7 +392,7 @@ impl RotateLog {
return Ok(0); return Ok(0);
} }
if self.writable_log().iter_dirty().nth(0).is_none() { if self.writable_log().iter_dirty().next().is_none() {
// Read-only path, no need to take directory lock. // Read-only path, no need to take directory lock.
if let Ok(latest) = read_latest(self.dir.as_ref().unwrap()) { if let Ok(latest) = read_latest(self.dir.as_ref().unwrap()) {
if latest != self.latest { if latest != self.latest {

View File

@ -81,9 +81,7 @@ pub fn mmap_path(path: &Path, len: u64) -> crate::Result<Bytes> {
Err(err).context(path, "cannot open for mmap") Err(err).context(path, "cannot open for mmap")
} }
})?; })?;
Ok(Bytes::from( Ok(mmap_bytes(&file, Some(len)).context(path, "cannot mmap")?)
mmap_bytes(&file, Some(len)).context(path, "cannot mmap")?,
))
} }
} }
@ -141,7 +139,7 @@ pub fn atomic_write(
// should also result in a non-empty file. However, we have seen empty // should also result in a non-empty file. However, we have seen empty
// files sometimes without OS crashes (see https://fburl.com/bky2zu9e). // files sometimes without OS crashes (see https://fburl.com/bky2zu9e).
if SYMLINK_ATOMIC_WRITE.load(atomic::Ordering::SeqCst) { if SYMLINK_ATOMIC_WRITE.load(atomic::Ordering::SeqCst) {
if let Ok(_) = atomic_write_symlink(path, content) { if atomic_write_symlink(path, content).is_ok() {
return Ok(()); return Ok(());
} }
} }