From 970687c98293bfb0007e173abfda46cc6e5d951c Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 26 Nov 2019 11:04:46 +0100 Subject: [PATCH] src/pxar/fuse.rs: cleanup - remove setup_session (moved into new) --- src/pxar/fuse.rs | 91 ++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 53 deletions(-) diff --git a/src/pxar/fuse.rs b/src/pxar/fuse.rs index 14a40c60..365f2b11 100644 --- a/src/pxar/fuse.rs +++ b/src/pxar/fuse.rs @@ -161,14 +161,9 @@ impl Session { /// ("ro,default_permissions"). pub fn from_path(archive_path: &Path, options: &OsStr, verbose: bool) -> Result { let file = File::open(archive_path)?; - let args = Self::setup_args(options, verbose)?; - let oprs = Self::setup_callbacks(); - - // By storing the decoder as userdata of the session, each request may - // access it. let reader = BufReader::new(file); let decoder = Decoder::new(reader)?; - Self::setup_session(decoder, args, oprs, verbose) + Self::new(decoder, options, verbose) } /// Create a new low level fuse session using the given `Decoder`. @@ -184,7 +179,43 @@ impl Session { ) -> Result { let args = Self::setup_args(options, verbose)?; let oprs = Self::setup_callbacks(); - Self::setup_session(decoder, args, oprs, verbose) + + let ctx = Context { + decoder, + goodbye_cache: None, + attr_cache: None, + ino_offset: 0, + }; + + let session_ctx = Box::new(Mutex::new(ctx)); + let arg_ptrs: Vec<_> = args.iter().map(|opt| opt.as_ptr()).collect(); + let fuse_args = FuseArgs { + argc: arg_ptrs.len() as i32, + argv: arg_ptrs.as_ptr(), + allocated: 0, + }; + let session_ptr = unsafe { + fuse_session_new( + Some(&fuse_args), + Some(&oprs), + std::mem::size_of::(), + // Ownership of session_ctx is passed to the session here. + // It has to be reclaimed before dropping the session to free + // the `Context` and close the underlying file. This is done inside + // the destroy callback function. + Box::into_raw(session_ctx) as ConstPtr, + ) + }; + + if session_ptr.is_null() { + bail!("error while creating new fuse session"); + } + + if unsafe { fuse_set_signal_handlers(session_ptr) } != 0 { + bail!("error while setting signal handlers"); + } + + Ok(Self { ptr: session_ptr, verbose }) } fn setup_args(options: &OsStr, verbose: bool) -> Result, Error> { @@ -216,52 +247,6 @@ impl Session { oprs } - fn setup_session( - decoder: Decoder, - args: Vec, - oprs: Operations, - verbose: bool, - ) -> Result { - let ctx = Context { - decoder, - goodbye_cache: None, - attr_cache: None, - ino_offset: 0, - }; - let session_ctx = Box::new(Mutex::new(ctx)); - let arg_ptrs: Vec<_> = args.iter().map(|opt| opt.as_ptr()).collect(); - let fuse_args = FuseArgs { - argc: arg_ptrs.len() as i32, - argv: arg_ptrs.as_ptr(), - allocated: 0, - }; - let session_ptr = unsafe { - fuse_session_new( - Some(&fuse_args), - Some(&oprs), - std::mem::size_of::(), - // Ownership of session_ctx is passed to the session here. - // It has to be reclaimed before dropping the session to free - // the `Context` and close the underlying file. This is done inside - // the destroy callback function. - Box::into_raw(session_ctx) as ConstPtr, - ) - }; - - if session_ptr.is_null() { - bail!("error while creating new fuse session"); - } - - if unsafe { fuse_set_signal_handlers(session_ptr) } != 0 { - bail!("error while setting signal handlers"); - } - - Ok(Self { - ptr: session_ptr, - verbose, - }) - } - /// Mount the filesystem on the given mountpoint. /// /// Actually mount the filesystem for this session on the provided mountpoint