]> git.proxmox.com Git - pxar.git/commitdiff
more clippy lints
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 16 Jul 2020 09:21:13 +0000 (11:21 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 16 Jul 2020 09:40:41 +0000 (11:40 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/accessor/aio.rs
src/accessor/mod.rs
src/accessor/sync.rs
src/decoder/aio.rs
src/decoder/mod.rs
src/decoder/sync.rs
src/encoder/aio.rs
src/encoder/mod.rs
src/format/mod.rs
src/lib.rs

index 8e20dd2f092face9bc2517f50b710d2a7d8005f5..a1aaa08aae77caef0547ab070e9876c8bdfdb3f9 100644 (file)
@@ -92,7 +92,7 @@ impl<T: ReadAt> Accessor<T> {
     }
 
     /// Open a directory handle to the root of the pxar archive.
-    pub async fn open_root_ref<'a>(&'a self) -> io::Result<Directory<&'a dyn ReadAt>> {
+    pub async fn open_root_ref(&self) -> io::Result<Directory<&dyn ReadAt>> {
         Ok(Directory::new(self.inner.open_root_ref().await?))
     }
 
@@ -117,11 +117,21 @@ impl<T: Clone + ReadAt> Accessor<T> {
     }
 
     /// Allow opening a directory at a specified offset.
+    ///
+    /// # Safety
+    ///
+    /// This should only be used with offsets known to point to the end of a directory, otherwise
+    /// this usually fails, unless the data otherwise happens to look like a valid directory.
     pub async unsafe fn open_dir_at_end(&self, offset: u64) -> io::Result<Directory<T>> {
         Ok(Directory::new(self.inner.open_dir_at_end(offset).await?))
     }
 
     /// Allow opening a regular file from a specified range.
+    ///
+    /// # Safety
+    ///
+    /// Should only be used with `entry_range_info`s originating from the same archive, otherwise
+    /// the result will be undefined and likely fail (or contain unexpected data).
     pub async unsafe fn open_file_at_range(
         &self,
         entry_range_info: &accessor::EntryRangeInfo,
@@ -132,6 +142,11 @@ impl<T: Clone + ReadAt> Accessor<T> {
     }
 
     /// Allow opening arbitrary contents from a specific range.
+    ///
+    /// # Safety
+    ///
+    /// This will provide a reader over an arbitrary range of the archive file, so unless this
+    /// comes from a actual file entry data, the contents might not make much sense.
     pub unsafe fn open_contents_at_range(&self, range: Range<u64>) -> FileContents<T> {
         FileContents {
             inner: self.inner.open_contents_at_range(range),
@@ -186,7 +201,7 @@ impl<T: Clone + ReadAt> Directory<T> {
     }
 
     /// Get an iterator over the directory's contents.
-    pub fn read_dir<'a>(&'a self) -> ReadDir<'a, T> {
+    pub fn read_dir(&self) -> ReadDir<T> {
         ReadDir {
             inner: self.inner.read_dir(),
         }
@@ -313,12 +328,18 @@ impl<'a, T: Clone + ReadAt> DirEntry<'a, T> {
     }
 }
 
+/// File content read future result.
+struct ReadResult {
+    len: usize,
+    buffer: Vec<u8>,
+}
+
 /// A reader for file contents.
 pub struct FileContents<T> {
     inner: accessor::FileContentsImpl<T>,
     at: u64,
     buffer: Vec<u8>,
-    future: Option<Pin<Box<dyn Future<Output = io::Result<(usize, Vec<u8>)>> + 'static>>>,
+    future: Option<Pin<Box<dyn Future<Output = io::Result<ReadResult>> + 'static>>>,
 }
 
 // We lose `Send` via the boxed trait object and don't want to force the trait object to
@@ -343,10 +364,10 @@ impl<T: Clone + ReadAt> FileContents<T> {
                     util::scale_read_buffer(&mut buffer, dest.len());
                     let reader: accessor::FileContentsImpl<T> = this.inner.clone();
                     let at = this.at;
-                    let future: Pin<Box<dyn Future<Output = io::Result<(usize, Vec<u8>)>>>> =
+                    let future: Pin<Box<dyn Future<Output = io::Result<ReadResult>>>> =
                         Box::pin(async move {
-                            let got = reader.read_at(&mut buffer, at).await?;
-                            io::Result::Ok((got, buffer))
+                            let len = reader.read_at(&mut buffer, at).await?;
+                            io::Result::Ok(ReadResult { len, buffer })
                         });
                     // This future has the lifetime from T. Self also has this lifetime and we
                     // store this in a pinned self. T maybe a reference with a non-'static life
@@ -360,7 +381,7 @@ impl<T: Clone + ReadAt> FileContents<T> {
                         return Poll::Pending;
                     }
                     Poll::Ready(Err(err)) => return Poll::Ready(Err(err)),
-                    Poll::Ready(Ok((got, buffer))) => {
+                    Poll::Ready(Ok(ReadResult { len: got, buffer })) => {
                         this.buffer = buffer;
                         this.at += got as u64;
                         let len = got.min(dest.len());
index f9984827b4ae1cdd5d28584a2457a8db6bf24a39..0ab03a67b75408062048a879bc2f268cdcefb61e 100644 (file)
@@ -202,7 +202,7 @@ impl<T: ReadAt> AccessorImpl<T> {
         self.size
     }
 
-    pub async fn open_root_ref<'a>(&'a self) -> io::Result<DirectoryImpl<&'a dyn ReadAt>> {
+    pub async fn open_root_ref(&self) -> io::Result<DirectoryImpl<&dyn ReadAt>> {
         DirectoryImpl::open_at_end(
             &self.input as &dyn ReadAt,
             self.size,
@@ -218,7 +218,7 @@ impl<T: ReadAt> AccessorImpl<T> {
     ) {
         let new_caches = Arc::new(Caches {
             gbt_cache: cache,
-            ..*self.caches
+            //..*self.caches
         });
         self.caches = new_caches;
     }
@@ -436,7 +436,6 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
                 len * size_of::<GoodbyeItem>(),
             );
             read_exact_at(&self.input, slice, self.table_offset()).await?;
-            drop(slice);
         }
         Ok(Arc::from(data))
     }
@@ -608,6 +607,8 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
         }
     }
 
+    // while clippy is technically right about this, the compiler won't accept it (yet)
+    #[allow(clippy::needless_lifetimes)]
     async fn get_cursor<'a>(&'a self, index: usize) -> io::Result<DirEntryImpl<'a, T>> {
         let entry = &self.table[index];
         let file_goodbye_ofs = entry.offset;
@@ -881,12 +882,18 @@ impl<T: Clone + ReadAt> ReadAt for FileContentsImpl<T> {
     }
 }
 
+/// File content read future result.
+struct ReadResult {
+    len: usize,
+    buffer: Vec<u8>,
+}
+
 #[doc(hidden)]
 pub struct SeqReadAtAdapter<T> {
     input: T,
     range: Range<u64>,
     buffer: Vec<u8>,
-    future: Option<Pin<Box<dyn Future<Output = io::Result<(usize, Vec<u8>)>> + 'static>>>,
+    future: Option<Pin<Box<dyn Future<Output = io::Result<ReadResult>> + 'static>>>,
 }
 
 // We lose `Send` via the boxed trait object and don't want to force the trait object to
@@ -943,10 +950,10 @@ impl<T: ReadAt> decoder::SeqRead for SeqReadAtAdapter<T> {
                     let reader = &this.input;
 
                     let at = this.range.start;
-                    let future: Pin<Box<dyn Future<Output = io::Result<(usize, Vec<u8>)>>>> =
+                    let future: Pin<Box<dyn Future<Output = io::Result<ReadResult>>>> =
                         Box::pin(async move {
-                            let got = reader.read_at(&mut buffer, at).await?;
-                            io::Result::Ok((got, buffer))
+                            let len = reader.read_at(&mut buffer, at).await?;
+                            io::Result::Ok(ReadResult { len, buffer })
                         });
                     // Ditch the self-reference life-time now:
                     this.future = Some(unsafe { mem::transmute(future) });
@@ -957,7 +964,7 @@ impl<T: ReadAt> decoder::SeqRead for SeqReadAtAdapter<T> {
                         return Poll::Pending;
                     }
                     Poll::Ready(Err(err)) => return Poll::Ready(Err(err)),
-                    Poll::Ready(Ok((got, buffer))) => {
+                    Poll::Ready(Ok(ReadResult { len: got, buffer })) => {
                         this.buffer = buffer;
                         this.range.start += got as u64;
                         let len = got.min(dest.len());
index 50334b9bd319113d577d9ff5c934339310e80abe..15c99c44aaecb27badd689b1889f43d540490fc8 100644 (file)
@@ -108,6 +108,11 @@ impl<T: Clone + ReadAt> Accessor<T> {
     }
 
     /// Allow opening a directory at a specified offset.
+    ///
+    /// # Safety
+    ///
+    /// This should only be used with offsets known to point to the end of a directory, otherwise
+    /// this usually fails, unless the data otherwise happens to look like a valid directory.
     pub unsafe fn open_dir_at_end(&self, offset: u64) -> io::Result<Directory<T>> {
         Ok(Directory::new(poll_result_once(
             self.inner.open_dir_at_end(offset),
@@ -115,6 +120,11 @@ impl<T: Clone + ReadAt> Accessor<T> {
     }
 
     /// Allow opening a regular file from a specified range.
+    ///
+    /// # Safety
+    ///
+    /// Should only be used with `entry_range_info`s originating from the same archive, otherwise
+    /// the result will be undefined and likely fail (or contain unexpected data).
     pub unsafe fn open_file_at_range(
         &self,
         entry_range_info: &accessor::EntryRangeInfo,
@@ -125,6 +135,11 @@ impl<T: Clone + ReadAt> Accessor<T> {
     }
 
     /// Allow opening arbitrary contents from a specific range.
+    ///
+    /// # Safety
+    ///
+    /// This will provide a reader over an arbitrary range of the archive file, so unless this
+    /// comes from a actual file entry data, the contents might not make much sense.
     pub unsafe fn open_contents_at_range(&self, range: Range<u64>) -> FileContents<T> {
         FileContents {
             inner: self.inner.open_contents_at_range(range),
@@ -243,7 +258,7 @@ impl<T: Clone + ReadAt> Directory<T> {
     }
 
     /// Get an iterator over the directory's contents.
-    pub fn read_dir<'a>(&'a self) -> ReadDir<'a, T> {
+    pub fn read_dir(&self) -> ReadDir<T> {
         ReadDir {
             inner: self.inner.read_dir(),
         }
index e212c5eacd72932183d19294b0c53b6e67c0e12d..e7152b31eff1d4441bd109ea8e11092f5538c608 100644 (file)
@@ -57,6 +57,9 @@ impl<T: SeqRead> Decoder<T> {
         Self { inner }
     }
 
+    // I would normally agree with clippy, but this is async and we can at most implement Stream,
+    // which we do with feature flags...
+    #[allow(clippy::should_implement_trait)]
     /// If this is a directory entry, get the next item inside the directory.
     pub async fn next(&mut self) -> Option<io::Result<Entry>> {
         self.inner.next_do().await.transpose()
@@ -87,6 +90,7 @@ mod stream {
     ///
     /// As long as streams are poll-based this wrapper is required to turn `async fn next()` into
     /// `Stream`'s `poll_next()` interface.
+    #[allow(clippy::type_complexity)] // yeah no
     pub struct DecoderStream<T> {
         inner: super::Decoder<T>,
         future: Option<Pin<Box<dyn Future<Output = Option<io::Result<Entry>>>>>>,
index 1bfbcb9175072fd96c42800a5b261d29ead62356..9410942e3d6ab7be5020e475b0887e8ef52f4b62 100644 (file)
@@ -293,7 +293,7 @@ impl<I: SeqRead> DecoderImpl<I> {
         }
     }
 
-    pub fn content_reader<'a>(&'a mut self) -> Option<Contents<'a, I>> {
+    pub fn content_reader(&mut self) -> Option<Contents<I>> {
         if let State::InPayload { offset } = &mut self.state {
             Some(Contents::new(
                 &mut self.input,
index b0a9f76b5cd7c1550c009be0c860b3a3f0ee6ff3..a7afda1b561e4d2ce39d0245e5c683bbba641e57 100644 (file)
@@ -54,6 +54,9 @@ impl<T: SeqRead> Decoder<T> {
         Self { inner }
     }
 
+    // I would normally agree with clippy, but this here is to be consistent with the async
+    // counterpart, and we *do* implement Iterator as well, so that's fine!
+    #[allow(clippy::should_implement_trait)]
     /// If this is a directory entry, get the next item inside the directory.
     pub fn next(&mut self) -> Option<io::Result<Entry>> {
         poll_result_once(self.inner.next_do()).transpose()
index ab20a4a5cec7818c410eec1d3af209c50e4e4397..e2d5461aec0ae3da72072a0dc3c6b929cb1e00dd 100644 (file)
@@ -297,7 +297,7 @@ mod futures_writer {
         fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
             let this = unsafe { self.get_unchecked_mut() };
             match this.inner.as_mut() {
-                None => return Poll::Ready(Ok(())),
+                None => Poll::Ready(Ok(())),
                 Some(inner) => {
                     ready!(unsafe { Pin::new_unchecked(inner).poll_close(cx) })?;
                     this.inner = None;
@@ -368,7 +368,7 @@ mod tokio_writer {
         fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
             let this = unsafe { self.get_unchecked_mut() };
             match this.inner.as_mut() {
-                None => return Poll::Ready(Ok(())),
+                None => Poll::Ready(Ok(())),
                 Some(inner) => {
                     ready!(unsafe { Pin::new_unchecked(inner).poll_shutdown(cx) })?;
                     this.inner = None;
index f100939b1650c575344e8d42748d233238689589..c098dcb0510f7f543a609afed5d46c7e6f6d136b 100644 (file)
@@ -506,7 +506,7 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
                 entry_offset,
                 files_offset,
                 file_offset: Some(file_offset),
-                file_hash: file_hash,
+                file_hash,
                 ..Default::default()
             },
             parent: Some(&mut self.state),
@@ -605,7 +605,7 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
         seq_write_pxar_struct_entry(
             &mut self.output,
             format::PXAR_QUOTA_PROJID,
-            quota_project_id.clone(),
+            *quota_project_id,
         )
         .await
     }
index e9e8d1bc4ccac22bdbeac71d0b479c53fd4bdd28..2a7d377ba7a99e300777778c6d7f7de2dac37c73 100644 (file)
@@ -327,15 +327,13 @@ impl From<&std::fs::Metadata> for Entry {
 
         let file_type = meta.file_type();
         let mode = this.mode;
-        let this = if file_type.is_dir() {
+        if file_type.is_dir() {
             this.mode(mode | mode::IFDIR)
         } else if file_type.is_symlink() {
             this.mode(mode | mode::IFLNK)
         } else {
             this.mode(mode | mode::IFREG)
-        };
-
-        this
+        }
     }
 }
 
index 1e887480b7aa4914e5a9892c220ec50c1bde7b45..5d1b78140a51a23b99f28f525913f75d9b5197f9 100644 (file)
@@ -64,11 +64,8 @@ impl From<Stat> for Metadata {
 
 impl From<&std::fs::Metadata> for Metadata {
     fn from(meta: &std::fs::Metadata) -> Metadata {
-        let this = Self::from(Stat::from(meta));
-
-        // FIXME: fill the remaining metadata
-
-        this
+        // NOTE: fill the remaining metadata via feature flags?
+        Self::from(Stat::from(meta))
     }
 }
 
@@ -387,7 +384,7 @@ impl Entry {
     /// Convenience method to get just the file name portion of the current path.
     #[inline]
     pub fn file_name(&self) -> &OsStr {
-        self.path.file_name().unwrap_or(OsStr::new(""))
+        self.path.file_name().unwrap_or_else(|| OsStr::new(""))
     }
 
     /// Get the file metadata.