mirror of
https://github.com/house-of-vanity/mus-fuse.git
synced 2025-07-06 21:24:09 +00:00
Add autounmount on exit and SIGINT handler.
This commit is contained in:
@ -19,3 +19,4 @@ env_logger = "0.7.1"
|
|||||||
log = { version = "^0.4.5", features = ["std"] }
|
log = { version = "^0.4.5", features = ["std"] }
|
||||||
size_format = "1.0.2"
|
size_format = "1.0.2"
|
||||||
base64 = "0.12.0"
|
base64 = "0.12.0"
|
||||||
|
ctrlc = "3.1.4"
|
||||||
|
60
src/main.rs
60
src/main.rs
@ -1,5 +1,3 @@
|
|||||||
// Fuse staff
|
|
||||||
|
|
||||||
extern crate base64;
|
extern crate base64;
|
||||||
extern crate fuse;
|
extern crate fuse;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
@ -19,13 +17,8 @@ use std::fmt;
|
|||||||
use time::Timespec;
|
use time::Timespec;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
use std::process;
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate env_logger;
|
|
||||||
|
|
||||||
use chrono::Local;
|
|
||||||
use env_logger::Builder;
|
|
||||||
use log::LevelFilter;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
// Download lib staff
|
// Download lib staff
|
||||||
use percent_encoding::percent_decode_str;
|
use percent_encoding::percent_decode_str;
|
||||||
@ -453,18 +446,8 @@ impl Filesystem for JsonFilesystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Builder::new()
|
env_logger::init();
|
||||||
.format(|buf, record| {
|
info!("Logger initialized. Set RUST_LOG=[debug,error,info,warn,trace] Default: info");
|
||||||
writeln!(
|
|
||||||
buf,
|
|
||||||
"{} [{}] - {}",
|
|
||||||
Local::now().format("%Y-%m-%dT%H:%M:%S"),
|
|
||||||
record.level(),
|
|
||||||
record.args()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.filter(None, LevelFilter::Info)
|
|
||||||
.init();
|
|
||||||
let mountpoint = match env::args().nth(1) {
|
let mountpoint = match env::args().nth(1) {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
@ -527,15 +510,29 @@ fn main() {
|
|||||||
let lib = match get_tracks(&server) {
|
let lib = match get_tracks(&server) {
|
||||||
Ok(library) => library,
|
Ok(library) => library,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
panic!("Can't fetch library from remote server: {}", err);
|
error!("Can't fetch library from remote server. Probably server not running or auth failed.");
|
||||||
|
error!(
|
||||||
|
"Provide Basic Auth credentials by setting envs {} and {}",
|
||||||
|
http_user_var, http_pass_var
|
||||||
|
);
|
||||||
|
panic!("Error: {}", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
info!("Remote library host: {}", &server);
|
info!("Remote library host: {}", &server);
|
||||||
let fs = JsonFilesystem::new(&lib, server);
|
let fs = JsonFilesystem::new(&lib, server);
|
||||||
let options = ["-o", "ro", "-o", "fsname=musfs", "-o", "sync_read"]
|
let options = [
|
||||||
.iter()
|
"-o",
|
||||||
.map(|o| o.as_ref())
|
"ro",
|
||||||
.collect::<Vec<&OsStr>>();
|
"-o",
|
||||||
|
"fsname=musfs",
|
||||||
|
"-o",
|
||||||
|
"sync_read",
|
||||||
|
"-o",
|
||||||
|
"auto_unmount",
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|o| o.as_ref())
|
||||||
|
.collect::<Vec<&OsStr>>();
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Caching {}B bytes in head of files.",
|
"Caching {}B bytes in head of files.",
|
||||||
@ -543,6 +540,15 @@ fn main() {
|
|||||||
);
|
);
|
||||||
info!("Max cache is {} files.", MAX_CACHE_SIZE);
|
info!("Max cache is {} files.", MAX_CACHE_SIZE);
|
||||||
info!("Mount options: {:?}", options);
|
info!("Mount options: {:?}", options);
|
||||||
|
let mut mount: fuse::BackgroundSession;
|
||||||
fuse::mount(fs, &mountpoint, &options).expect("Couldn't mount filesystem");
|
unsafe {
|
||||||
|
mount =
|
||||||
|
fuse::spawn_mount(fs, &mountpoint, &options).expect("Couldn't mount filesystem");
|
||||||
|
}
|
||||||
|
ctrlc::set_handler(move || {
|
||||||
|
println!("Exitting...");
|
||||||
|
process::exit(0x0000);
|
||||||
|
})
|
||||||
|
.expect("Error setting Ctrl-C handler");
|
||||||
|
loop {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user