File: umount.rs

package info (click to toggle)
rust-sys-mount 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2018-2022 System76 <info@system76.com>
// SPDX-License-Identifier: MIT OR Apache-2.0

extern crate clap;
extern crate sys_mount;

use clap::{Arg, Command};
use std::process::ExitCode;
use sys_mount::{unmount, UnmountFlags};

fn main() -> ExitCode {
    let matches = Command::new("umount")
        .arg(Arg::new("lazy").short('l').long("lazy"))
        .arg(Arg::new("source").required(true))
        .get_matches();

    let src = matches.get_one::<String>("source").unwrap();

    let flags = if matches.get_flag("lazy") {
        UnmountFlags::DETACH
    } else {
        UnmountFlags::empty()
    };

    let Err(why) = unmount(src, flags) else {
        return ExitCode::SUCCESS;
    };

    eprintln!("failed to unmount {}: {}", src, why);
    ExitCode::FAILURE
}