Skip to main content

lb_fs/
mount.rs

1use std::fs;
2use tokio::process::Command;
3use tracing::info;
4
5// see https://github.com/xetdata/nfsserve for more mount examples
6#[cfg(target_os = "macos")]
7pub fn mount() {
8    fs::create_dir_all("/tmp/lockbook").unwrap();
9
10    Command::new("mount_nfs")
11        .arg("-o")
12        .arg("nolocks,vers=3,tcp,rsize=131072,actimeo=120,port=11111,mountport=11111")
13        .arg("localhost:/")
14        .arg("/tmp/lockbook")
15        .spawn()
16        .unwrap();
17}
18
19// see https://github.com/xetdata/nfsserve for more mount examples
20#[cfg(target_os = "linux")]
21pub fn mount() {
22    fs::create_dir_all("/tmp/lockbook").unwrap();
23
24    Command::new("sudo")
25        .arg("mount.nfs")
26        .arg("-o")
27        .arg("user,noacl,nolock,vers=3,tcp,wsize=1048576,rsize=131072,actimeo=120,port=11111,mountport=11111")
28        .arg("localhost:/")
29        .arg("/tmp/lockbook")
30        .spawn()
31        .unwrap();
32}
33
34#[cfg(target_os = "windows")]
35pub fn mount() {
36    fs::create_dir_all("/tmp/lockbook").unwrap();
37
38    Command::new("mount.exe")
39        .arg("-o")
40        .arg("anon,nolock,mtype=soft,fileaccess=6,casesensitive,lang=ansi,rsize=128,wsize=128,timeout=60,retry=2")
41        .arg("localhost:/")
42        .arg("/tmp/lockbook")
43        .spawn()
44        .unwrap();
45}
46
47#[cfg(target_os = "linux")]
48pub async fn umount() -> bool {
49    info!("umounting");
50    let wait_result = Command::new("sudo")
51        .arg("umount")
52        .arg("/tmp/lockbook")
53        .spawn()
54        .unwrap()
55        .wait()
56        .await
57        .unwrap();
58
59    wait_result.success()
60}
61
62#[cfg(target_os = "macos")]
63pub async fn umount() -> bool {
64    info!("umounting");
65    let wait_result = Command::new("umount")
66        .arg("/tmp/lockbook")
67        .spawn()
68        .unwrap()
69        .wait()
70        .await
71        .unwrap();
72
73    wait_result.success()
74}
75
76#[cfg(target_os = "windows")]
77pub async fn umount() -> bool {
78    info!("todo");
79    todo!()
80}