Less boilerplate for VFS config

This commit is contained in:
Antoine Gersant 2017-06-29 00:16:00 -07:00
parent 29bc678c82
commit 104381af5d
3 changed files with 11 additions and 15 deletions

View file

@ -5,7 +5,7 @@ use std::path;
use toml;
use errors::*;
use db::NewMountPoint;
use db::MountPoint;
use ddns::DDNSConfig;
#[derive(Deserialize)]
@ -18,7 +18,7 @@ pub struct User {
pub struct UserConfig {
pub album_art_pattern: Option<String>,
pub reindex_every_n_seconds: Option<u64>,
pub mount_dirs: Option<Vec<NewMountPoint>>,
pub mount_dirs: Option<Vec<MountPoint>>,
pub users: Option<Vec<User>>,
pub ydns: Option<DDNSConfig>,
}

View file

@ -130,12 +130,15 @@ impl DB {
}
fn get_vfs(&self) -> Result<Vfs> {
use self::mount_points::dsl::*;
let mut vfs = Vfs::new();
let connection = self.connection.lock().unwrap();
let connection = connection.deref();
let mount_points: Vec<MountPoint> = mount_points::table.get_results(connection)?;
for mount_point in mount_points {
vfs.mount(&Path::new(&mount_point.real_path), &mount_point.name)?;
let points: Vec<MountPoint> = mount_points
.select((source, name))
.get_results(connection)?;
for point in points {
vfs.mount(&Path::new(&point.source), &point.name)?;
}
Ok(vfs)
}

View file

@ -99,18 +99,11 @@ impl NewUser {
// VFS
#[derive(Debug, Queryable)]
pub struct MountPoint {
id: i32,
pub real_path: String,
pub name: String,
}
#[derive(Deserialize, Insertable)]
#[derive(Debug, Deserialize, Insertable, Queryable)]
#[table_name="mount_points"]
pub struct NewMountPoint {
pub name: String,
pub struct MountPoint {
pub source: String,
pub name: String,
}