Skip to content

Commit 7208cf9

Browse files
committed
Refectoring
1 parent 13ec07f commit 7208cf9

File tree

5 files changed

+89
-83
lines changed

5 files changed

+89
-83
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/unpfs/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/unpfs/src/main.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern crate env_logger;
55
extern crate filetime;
66

77
use std::fs;
8-
use std::ffi::OsStr;
98
use std::path::PathBuf;
109
use std::io::{Seek, SeekFrom, Read, Write};
1110
use std::os::unix::prelude::*;
@@ -23,7 +22,7 @@ struct UnpfsFid {
2322
}
2423

2524
impl UnpfsFid {
26-
fn new<P: AsRef<OsStr> + ?Sized>(path: &P) -> UnpfsFid {
25+
fn new<P: AsRef<std::ffi::OsStr> + ?Sized>(path: &P) -> UnpfsFid {
2726
UnpfsFid { realpath: PathBuf::from(path), file: None, }
2827
}
2928
}
@@ -32,12 +31,6 @@ struct Unpfs {
3231
realroot: PathBuf,
3332
}
3433

35-
impl Unpfs {
36-
fn new(mountpoint: &str) -> Unpfs {
37-
Unpfs { realroot: PathBuf::from(mountpoint), }
38-
}
39-
}
40-
4134
impl Filesystem for Unpfs {
4235
type Fid = UnpfsFid;
4336

@@ -197,8 +190,8 @@ impl Filesystem for Unpfs {
197190
}
198191

199192
fn rstatfs(&mut self, fid: &mut Fid<Self::Fid>) -> Result<Fcall> {
200-
let fs = nix::sys::statvfs::vfs::Statvfs::for_path(&fid.aux().realpath);
201-
Ok(Fcall::Rstatfs { statfs: From::from(fs?) })
193+
let fs = nix::sys::statvfs::vfs::Statvfs::for_path(&fid.aux().realpath)?;
194+
Ok(Fcall::Rstatfs { statfs: From::from(fs) })
202195
}
203196
}
204197

@@ -209,15 +202,13 @@ fn unpfs_main(args: Vec<String>) -> rs9p::Result<i32> {
209202
return Ok(-1);
210203
}
211204

212-
let mountpoint = &args[2];
213-
if !fs::metadata(mountpoint)?.is_dir() {
205+
let (addr, mountpoint) = (&args[1], PathBuf::from(&args[2]));
206+
if !fs::metadata(mountpoint.as_path())?.is_dir() {
214207
return res!(io_err!(Other, "mount point must be a directory"));
215208
}
216209

217-
println!("[*] Ready to accept clients: {}", args[1]);
218-
rs9p::srv_spawn(Unpfs::new(mountpoint), &args[1])?;
219-
220-
return Ok(0);
210+
println!("[*] Ready to accept clients: {}", addr);
211+
rs9p::srv_spawn(Unpfs { realroot: mountpoint }, addr).and(Ok(0))
221212
}
222213

223214
fn main() {

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//! rs9p is a library to develop 9P2000.L virtual filesystems in Rust.
1313
//! All you have to do is to implement `Filesystem` trait.
1414
15+
#![feature(question_mark_carrier)]
16+
1517
#[macro_use]
1618
extern crate log;
1719
#[macro_use]

0 commit comments

Comments
 (0)