Formatting
This commit is contained in:
parent
f7726c0ad9
commit
16c609cd20
3 changed files with 33 additions and 48 deletions
|
@ -110,7 +110,7 @@ fn serve(request: &mut Request, collection: &mut Collection) -> IronResult<Respo
|
||||||
Err(e) => return Err(IronError::new(e, status::NotFound)),
|
Err(e) => return Err(IronError::new(e, status::NotFound)),
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
};
|
};
|
||||||
|
|
||||||
let metadata = match fs::metadata(real_path.as_path()) {
|
let metadata = match fs::metadata(real_path.as_path()) {
|
||||||
Ok(meta) => meta,
|
Ok(meta) => meta,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -120,7 +120,7 @@ fn serve(request: &mut Request, collection: &mut Collection) -> IronResult<Respo
|
||||||
_ => status::InternalServerError,
|
_ => status::InternalServerError,
|
||||||
};
|
};
|
||||||
return Err(IronError::new(e, status));
|
return Err(IronError::new(e, status));
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if !metadata.is_file() {
|
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)))
|
Ok(Response::with((status::Ok, real_path)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,7 @@ pub struct Directory {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
pub fn read(collection: &Collection,
|
pub fn read(collection: &Collection, path: &Path) -> Result<Directory, PError> {
|
||||||
path: &Path)
|
|
||||||
-> Result<Directory, PError> {
|
|
||||||
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
||||||
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
||||||
|
|
||||||
|
@ -64,17 +62,16 @@ pub struct Collection {
|
||||||
vfs: Vfs,
|
vfs: Vfs,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONFIG_MOUNT_DIRS : &'static str = "mount_dirs";
|
const CONFIG_MOUNT_DIRS: &'static str = "mount_dirs";
|
||||||
const CONFIG_MOUNT_DIR_NAME : &'static str = "name";
|
const CONFIG_MOUNT_DIR_NAME: &'static str = "name";
|
||||||
const CONFIG_MOUNT_DIR_SOURCE : &'static str = "source";
|
const CONFIG_MOUNT_DIR_SOURCE: &'static str = "source";
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn new() -> Collection {
|
pub fn new() -> Collection {
|
||||||
Collection { vfs: Vfs::new() }
|
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
|
// Open
|
||||||
let mut config_file = match File::open(config_path) {
|
let mut config_file = match File::open(config_path) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
|
@ -113,26 +110,26 @@ impl Collection {
|
||||||
};
|
};
|
||||||
|
|
||||||
for dir in mount_dirs {
|
for dir in mount_dirs {
|
||||||
let name = match dir.lookup(CONFIG_MOUNT_DIR_NAME) {
|
let name = match dir.lookup(CONFIG_MOUNT_DIR_NAME) {
|
||||||
None => return Err(PError::ConfigMountDirsParseError),
|
None => return Err(PError::ConfigMountDirsParseError),
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
};
|
};
|
||||||
let name = match name.as_str() {
|
let name = match name.as_str() {
|
||||||
None => return Err(PError::ConfigMountDirsParseError),
|
None => return Err(PError::ConfigMountDirsParseError),
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
};
|
};
|
||||||
|
|
||||||
let source = match dir.lookup(CONFIG_MOUNT_DIR_SOURCE) {
|
let source = match dir.lookup(CONFIG_MOUNT_DIR_SOURCE) {
|
||||||
None => return Err(PError::ConfigMountDirsParseError),
|
None => return Err(PError::ConfigMountDirsParseError),
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
};
|
};
|
||||||
let source = match source.as_str() {
|
let source = match source.as_str() {
|
||||||
None => return Err(PError::ConfigMountDirsParseError),
|
None => return Err(PError::ConfigMountDirsParseError),
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
};
|
};
|
||||||
let source = PathBuf::from(source);
|
let source = PathBuf::from(source);
|
||||||
|
|
||||||
try!(self.mount(name, source.as_path()));
|
try!(self.mount(name, source.as_path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
24
src/error.rs
24
src/error.rs
|
@ -58,24 +58,12 @@ impl fmt::Display for PError {
|
||||||
match *self {
|
match *self {
|
||||||
PError::Io(ref err) => write!(f, "IO error: {}", err),
|
PError::Io(ref err) => write!(f, "IO error: {}", err),
|
||||||
PError::PathDecoding => write!(f, "Path decoding error"),
|
PError::PathDecoding => write!(f, "Path decoding error"),
|
||||||
PError::ConflictingMount => {
|
PError::ConflictingMount => write!(f, "Mount point already has a target directory"),
|
||||||
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::PathNotInVfs => {
|
PError::ConfigFileOpenError => write!(f, "Could not open config file"),
|
||||||
write!(f, "Requested path does not index a mount point")
|
PError::ConfigFileReadError => write!(f, "Could not read config file"),
|
||||||
}
|
PError::ConfigFileParseError => write!(f, "Could not parse config file"),
|
||||||
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 => {
|
PError::ConfigMountDirsParseError => {
|
||||||
write!(f, "Could not parse mount directories in config file")
|
write!(f, "Could not parse mount directories in config file")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue