Less boilerplate for VFS config
This commit is contained in:
parent
29bc678c82
commit
104381af5d
3 changed files with 11 additions and 15 deletions
|
@ -5,7 +5,7 @@ use std::path;
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use db::NewMountPoint;
|
use db::MountPoint;
|
||||||
use ddns::DDNSConfig;
|
use ddns::DDNSConfig;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -18,7 +18,7 @@ pub struct User {
|
||||||
pub struct UserConfig {
|
pub struct UserConfig {
|
||||||
pub album_art_pattern: Option<String>,
|
pub album_art_pattern: Option<String>,
|
||||||
pub reindex_every_n_seconds: Option<u64>,
|
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 users: Option<Vec<User>>,
|
||||||
pub ydns: Option<DDNSConfig>,
|
pub ydns: Option<DDNSConfig>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,12 +130,15 @@ impl DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_vfs(&self) -> Result<Vfs> {
|
fn get_vfs(&self) -> Result<Vfs> {
|
||||||
|
use self::mount_points::dsl::*;
|
||||||
let mut vfs = Vfs::new();
|
let mut vfs = Vfs::new();
|
||||||
let connection = self.connection.lock().unwrap();
|
let connection = self.connection.lock().unwrap();
|
||||||
let connection = connection.deref();
|
let connection = connection.deref();
|
||||||
let mount_points: Vec<MountPoint> = mount_points::table.get_results(connection)?;
|
let points: Vec<MountPoint> = mount_points
|
||||||
for mount_point in mount_points {
|
.select((source, name))
|
||||||
vfs.mount(&Path::new(&mount_point.real_path), &mount_point.name)?;
|
.get_results(connection)?;
|
||||||
|
for point in points {
|
||||||
|
vfs.mount(&Path::new(&point.source), &point.name)?;
|
||||||
}
|
}
|
||||||
Ok(vfs)
|
Ok(vfs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,18 +99,11 @@ impl NewUser {
|
||||||
|
|
||||||
|
|
||||||
// VFS
|
// VFS
|
||||||
#[derive(Debug, Queryable)]
|
#[derive(Debug, Deserialize, Insertable, Queryable)]
|
||||||
pub struct MountPoint {
|
|
||||||
id: i32,
|
|
||||||
pub real_path: String,
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Insertable)]
|
|
||||||
#[table_name="mount_points"]
|
#[table_name="mount_points"]
|
||||||
pub struct NewMountPoint {
|
pub struct MountPoint {
|
||||||
pub name: String,
|
|
||||||
pub source: String,
|
pub source: String,
|
||||||
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue