diff --git a/src/backup/catalog_shell.rs b/src/backup/catalog_shell.rs index 90aaeb4d..286f6ef6 100644 --- a/src/backup/catalog_shell.rs +++ b/src/backup/catalog_shell.rs @@ -7,8 +7,6 @@ use std::path::Path; use failure::*; use libc; -use crate::backup::*; -use crate::client::*; use crate::pxar::*; use super::catalog::{CatalogReader, DirEntry}; @@ -21,7 +19,7 @@ pub struct Shell { /// List of paths selected for a restore selected: HashSet>, /// Decoder instance for the current pxar archive - decoder: Decoder>, + decoder: Decoder, /// Root directory for the give archive as stored in the catalog root: Vec, } @@ -60,7 +58,7 @@ impl Shell { pub fn new( mut catalog: CatalogReader, archive_name: &str, - decoder: Decoder> + decoder: Decoder, ) -> Result { let catalog_root = catalog.root()?; // The root for the given archive as stored in the catalog diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 779645f8..e508d5f4 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -1707,7 +1707,6 @@ async fn mount_do(param: Value, pipe: Option) -> Result { let most_used = index.find_most_used_chunks(8); let chunk_reader = RemoteChunkReader::new(client.clone(), crypt_config, most_used); let reader = BufferedDynamicReader::new(index, chunk_reader); - //let decoder = pxar::Decoder::new(Box::::new(reader))?; let decoder = pxar::Decoder::new(reader)?; let options = OsStr::new("ro,default_permissions"); let mut session = pxar::fuse::Session::from_decoder(decoder, &options, pipe.is_none()) diff --git a/src/pxar/decoder.rs b/src/pxar/decoder.rs index 598fab0a..7c5143df 100644 --- a/src/pxar/decoder.rs +++ b/src/pxar/decoder.rs @@ -26,9 +26,13 @@ pub struct DirectoryEntry { pub entry: PxarEntry, } +/// Trait to create ReadSeek Decoder trait objects. +trait ReadSeek: Read + Seek {} +impl ReadSeek for R {} + // This one needs Read+Seek -pub struct Decoder { - inner: SequentialDecoder, +pub struct Decoder { + inner: SequentialDecoder>, root_start: u64, root_end: u64, } @@ -36,10 +40,11 @@ pub struct Decoder { const HEADER_SIZE: u64 = std::mem::size_of::() as u64; const GOODBYE_ITEM_SIZE: u64 = std::mem::size_of::() as u64; -impl Decoder { - pub fn new(mut reader: R) -> Result { +impl Decoder { + pub fn new(mut reader: R) -> Result { let root_end = reader.seek(SeekFrom::End(0))?; - let inner = SequentialDecoder::new(reader, super::flags::DEFAULT); + let boxed_reader: Box = Box::new(reader); + let inner = SequentialDecoder::new(boxed_reader, super::flags::DEFAULT); Ok(Self { inner, root_start: 0, root_end }) } diff --git a/src/pxar/fuse.rs b/src/pxar/fuse.rs index a790cf41..cb216744 100644 --- a/src/pxar/fuse.rs +++ b/src/pxar/fuse.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::convert::TryFrom; use std::ffi::{CStr, CString, OsStr}; use std::fs::File; -use std::io::{BufReader, Read, Seek}; +use std::io::BufReader; use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::path::Path; use std::sync::Mutex; @@ -83,8 +83,8 @@ struct FuseArgs { /// `Context` for callback functions providing the decoder, caches and the /// offset within the archive for the i-node given by the caller. -struct Context { - decoder: Decoder, +struct Context { + decoder: Decoder, goodbye_cache: Option<(Inode, Vec<(PxarGoodbyeItem, Offset, Offset)>)>, attr_cache: Option<(Inode, PxarAttributes)>, ino_offset: Offset, @@ -92,10 +92,9 @@ struct Context { /// `Session` stores a pointer to the session context and is used to mount the /// archive to the given mountpoint. -pub struct Session { +pub struct Session { ptr: MutPtr, verbose: bool, - _phantom: std::marker::PhantomData, } /// `Operations` defines the callback function table of supported operations. @@ -151,7 +150,9 @@ struct Operations { copy_file_range: Option, } -impl Session> { + +impl Session { + /// Create a new low level fuse session. /// /// `Session` is created using the provided mount options and sets the @@ -169,9 +170,7 @@ impl Session> { let decoder = Decoder::new(reader)?; Self::setup_session(decoder, args, oprs, verbose) } -} -impl Session { fn setup_args(options: &OsStr, verbose: bool) -> Result, Error> { // First argument should be the executable name let mut arguments = vec![ @@ -202,7 +201,7 @@ impl Session { } fn setup_session( - decoder: Decoder, + decoder: Decoder, args: Vec, oprs: Operations, verbose: bool, @@ -244,7 +243,6 @@ impl Session { Ok(Self { ptr: session_ptr, verbose, - _phantom: std::marker::PhantomData, }) } @@ -255,7 +253,7 @@ impl Session { /// Options have to be provided as comma separated OsStr, e.g. /// ("ro,default_permissions"). pub fn from_decoder( - decoder: Decoder, + decoder: Decoder, options: &OsStr, verbose: bool, ) -> Result { @@ -319,10 +317,10 @@ impl Session { /// The error code will be used to reply to libfuse. fn run_in_context(req: Request, inode: u64, code: F) where - F: FnOnce(&mut Context) -> Result<(), i32>, + F: FnOnce(&mut Context) -> Result<(), i32>, { let boxed_ctx = unsafe { - let ptr = fuse_req_userdata(req) as *mut Mutex>; + let ptr = fuse_req_userdata(req) as *mut Mutex; Box::from_raw(ptr) }; let result = boxed_ctx @@ -532,7 +530,7 @@ impl Session { } } -impl Drop for Session { +impl Drop for Session { fn drop(&mut self) { unsafe { fuse_session_unmount(self.ptr); @@ -593,7 +591,7 @@ struct EntryParam { /// Update the goodbye table to the one corresponding to the i-node offset, both /// given in the `Context`. -fn update_goodbye_cache(mut ctx: &mut Context) -> Result<(), i32> { +fn update_goodbye_cache(mut ctx: &mut Context) -> Result<(), i32> { if let Some((off, _)) = &ctx.goodbye_cache { if *off == ctx.ino_offset { // Cache contains already the correct goodbye table @@ -623,8 +621,8 @@ fn update_goodbye_cache(mut ctx: &mut Context) -> Result<(), /// The matching items archive offset, entry and payload size are returned. /// If there is no entry with matching `filename` and `hash` a `libc::ENOENT` is /// returned. -fn find_goodbye_entry( - mut ctx: &mut Context, +fn find_goodbye_entry( + mut ctx: &mut Context, filename: &CStr, hash: u64, ) -> Result<(u64, PxarEntry, PxarAttributes, u64), i32> {