src/pxar/fuse.rs: cleanup - remove setup_session (moved into new)

This commit is contained in:
Dietmar Maurer 2019-11-26 11:04:46 +01:00
parent 2a11191072
commit 970687c982
1 changed files with 38 additions and 53 deletions

View File

@ -161,14 +161,9 @@ impl Session {
/// ("ro,default_permissions"). /// ("ro,default_permissions").
pub fn from_path(archive_path: &Path, options: &OsStr, verbose: bool) -> Result<Self, Error> { pub fn from_path(archive_path: &Path, options: &OsStr, verbose: bool) -> Result<Self, Error> {
let file = File::open(archive_path)?; 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 reader = BufReader::new(file);
let decoder = Decoder::new(reader)?; 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`. /// Create a new low level fuse session using the given `Decoder`.
@ -184,7 +179,43 @@ impl Session {
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let args = Self::setup_args(options, verbose)?; let args = Self::setup_args(options, verbose)?;
let oprs = Self::setup_callbacks(); 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::<Operations>(),
// 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<Vec<CString>, Error> { fn setup_args(options: &OsStr, verbose: bool) -> Result<Vec<CString>, Error> {
@ -216,52 +247,6 @@ impl Session {
oprs oprs
} }
fn setup_session(
decoder: Decoder,
args: Vec<CString>,
oprs: Operations,
verbose: bool,
) -> Result<Self, Error> {
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::<Operations>(),
// 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. /// Mount the filesystem on the given mountpoint.
/// ///
/// Actually mount the filesystem for this session on the provided mountpoint /// Actually mount the filesystem for this session on the provided mountpoint