Formatting

This commit is contained in:
Antoine Gersant 2016-08-28 17:43:15 -07:00
parent f7726c0ad9
commit 16c609cd20
3 changed files with 33 additions and 48 deletions

View file

@ -110,7 +110,7 @@ fn serve(request: &mut Request, collection: &mut Collection) -> IronResult<Respo
Err(e) => return Err(IronError::new(e, status::NotFound)),
Ok(p) => p,
};
let metadata = match fs::metadata(real_path.as_path()) {
Ok(meta) => meta,
Err(e) => {
@ -120,7 +120,7 @@ fn serve(request: &mut Request, collection: &mut Collection) -> IronResult<Respo
_ => status::InternalServerError,
};
return Err(IronError::new(e, status));
},
}
};
if !metadata.is_file() {
@ -128,4 +128,4 @@ fn serve(request: &mut Request, collection: &mut Collection) -> IronResult<Respo
}
Ok(Response::with((status::Ok, real_path)))
}
}

View file

@ -37,9 +37,7 @@ pub struct Directory {
}
impl Directory {
pub fn read(collection: &Collection,
path: &Path)
-> Result<Directory, PError> {
pub fn read(collection: &Collection, path: &Path) -> Result<Directory, PError> {
let virtual_path = try!(collection.vfs.real_to_virtual(path));
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
@ -64,17 +62,16 @@ pub struct Collection {
vfs: Vfs,
}
const CONFIG_MOUNT_DIRS : &'static str = "mount_dirs";
const CONFIG_MOUNT_DIR_NAME : &'static str = "name";
const CONFIG_MOUNT_DIR_SOURCE : &'static str = "source";
const CONFIG_MOUNT_DIRS: &'static str = "mount_dirs";
const CONFIG_MOUNT_DIR_NAME: &'static str = "name";
const CONFIG_MOUNT_DIR_SOURCE: &'static str = "source";
impl Collection {
pub fn new() -> Collection {
Collection { vfs: Vfs::new() }
}
pub fn load_config(&mut self, config_path: &Path) -> Result<(), PError>
{
pub fn load_config(&mut self, config_path: &Path) -> Result<(), PError> {
// Open
let mut config_file = match File::open(config_path) {
Ok(c) => c,
@ -113,26 +110,26 @@ impl Collection {
};
for dir in mount_dirs {
let name = match dir.lookup(CONFIG_MOUNT_DIR_NAME) {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let name = match name.as_str() {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let name = match dir.lookup(CONFIG_MOUNT_DIR_NAME) {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let name = match name.as_str() {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let source = match dir.lookup(CONFIG_MOUNT_DIR_SOURCE) {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let source = match source.as_str() {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let source = PathBuf::from(source);
try!(self.mount(name, source.as_path()));
let source = match dir.lookup(CONFIG_MOUNT_DIR_SOURCE) {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let source = match source.as_str() {
None => return Err(PError::ConfigMountDirsParseError),
Some(n) => n,
};
let source = PathBuf::from(source);
try!(self.mount(name, source.as_path()));
}
Ok(())

View file

@ -58,24 +58,12 @@ impl fmt::Display for PError {
match *self {
PError::Io(ref err) => write!(f, "IO error: {}", err),
PError::PathDecoding => write!(f, "Path decoding error"),
PError::ConflictingMount => {
write!(f, "Mount point already has a target directory")
}
PError::PathNotInVfs => {
write!(f, "Requested path does not index a mount point")
}
PError::CannotServeDirectory => {
write!(f, "Only individual files can be served")
}
PError::ConfigFileOpenError => {
write!(f, "Could not open config file")
}
PError::ConfigFileReadError => {
write!(f, "Could not read config file")
}
PError::ConfigFileParseError => {
write!(f, "Could not parse config file")
}
PError::ConflictingMount => write!(f, "Mount point already has a target directory"),
PError::PathNotInVfs => write!(f, "Requested path does not index a mount point"),
PError::CannotServeDirectory => write!(f, "Only individual files can be served"),
PError::ConfigFileOpenError => write!(f, "Could not open config file"),
PError::ConfigFileReadError => write!(f, "Could not read config file"),
PError::ConfigFileParseError => write!(f, "Could not parse config file"),
PError::ConfigMountDirsParseError => {
write!(f, "Could not parse mount directories in config file")
}