Fixed clippy lints
This commit is contained in:
parent
5a7c2008b5
commit
102678015b
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
//! Minimal bitflags type implementation allowing to check if a set of flags
|
//! Minimal bitflags type implementation allowing to check if a set of flags
|
||||||
//! contains a specific flag. The type must implement Copy and Bitand with u32.
|
//! contains a specific flag. The type must implement Copy and Bitand with u32.
|
||||||
use core::ops::BitAnd;
|
use core::ops::BitAnd;
|
||||||
|
@ -47,7 +47,7 @@ impl Cmd for Base32 {
|
|||||||
} else if index > 0 {
|
} else if index > 0 {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
let contents = get_contents(&file)?;
|
let contents = get_contents(file)?;
|
||||||
if matches.get_flag("DECODE") {
|
if matches.get_flag("DECODE") {
|
||||||
decode_base32(contents, matches.get_flag("IGNORE"))?;
|
decode_base32(contents, matches.get_flag("IGNORE"))?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,7 @@ impl Cmd for Base64 {
|
|||||||
} else if index > 0 {
|
} else if index > 0 {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
let contents = get_contents(&file)?;
|
let contents = get_contents(file)?;
|
||||||
if matches.get_flag("DECODE") {
|
if matches.get_flag("DECODE") {
|
||||||
decode_base64(contents, matches.get_flag("IGNORE"))?;
|
decode_base64(contents, matches.get_flag("IGNORE"))?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -348,7 +348,7 @@ fn completions(prefix: &str, matches: &ArgMatches, usr: bool) -> Result<(), io::
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
if matches.get_flag("zsh") || matches.get_flag("all") {
|
if matches.get_flag("zsh") || matches.get_flag("all") {
|
||||||
let mut outdir = basedir.clone();
|
let mut outdir = basedir;
|
||||||
outdir.push("zsh");
|
outdir.push("zsh");
|
||||||
outdir.push("site-functions");
|
outdir.push("site-functions");
|
||||||
COMMANDS.iter().try_for_each(|cmd| {
|
COMMANDS.iter().try_for_each(|cmd| {
|
||||||
|
@ -59,15 +59,13 @@ impl Cmd for Chmod {
|
|||||||
};
|
};
|
||||||
if let Err(e) = action.apply() {
|
if let Err(e) = action.apply() {
|
||||||
if !matches.get_flag("quiet") {
|
if !matches.get_flag("quiet") {
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if matches.get_flag("recursive") {
|
if matches.get_flag("recursive") && action.path.is_dir() {
|
||||||
if action.path.is_dir() {
|
|
||||||
if let Err(e) = action.recurse() {
|
if let Err(e) = action.recurse() {
|
||||||
if !matches.get_flag("quiet") {
|
if !matches.get_flag("quiet") {
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +134,7 @@ impl Action<'_> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_child(&self, entry: DirEntry) -> Self {
|
fn get_child(&self, entry: DirEntry) -> Self {
|
||||||
Self {
|
Self {
|
||||||
path: entry.path().to_path_buf(),
|
path: entry.path().to_path_buf(),
|
||||||
feedback: self.feedback,
|
feedback: self.feedback,
|
||||||
@ -148,7 +146,7 @@ impl Action<'_> {
|
|||||||
let walker = WalkDir::new(&self.path).max_open(1);
|
let walker = WalkDir::new(&self.path).max_open(1);
|
||||||
for entry in walker {
|
for entry in walker {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let action = self.into_child(entry);
|
let action = self.get_child(entry);
|
||||||
action.apply()?;
|
action.apply()?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -56,12 +56,11 @@ impl Cmd for Chgrp {
|
|||||||
feedback,
|
feedback,
|
||||||
};
|
};
|
||||||
if let Some(r) = recurse {
|
if let Some(r) = recurse {
|
||||||
if action.path.is_dir() {
|
if action.path.is_dir()
|
||||||
|
&& action.path.is_symlink()
|
||||||
|
&& r.traversal != Traversal::NoLinks
|
||||||
|
{
|
||||||
action.recurse(recurse)?;
|
action.recurse(recurse)?;
|
||||||
} else if action.path.is_symlink() {
|
|
||||||
if r.traversal != Traversal::NoLinks {
|
|
||||||
action.recurse(recurse)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.apply()?;
|
action.apply()?;
|
||||||
@ -127,7 +126,7 @@ impl Action<'_> {
|
|||||||
println!("{} retained as {}", &self.path.display(), &self.group.name);
|
println!("{} retained as {}", &self.path.display(), &self.group.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_child(&self, entry: DirEntry) -> Result<Self, Box<dyn Error>> {
|
fn as_child(&self, entry: DirEntry) -> Result<Self, Box<dyn Error>> {
|
||||||
let path = entry.path().to_path_buf();
|
let path = entry.path().to_path_buf();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
path,
|
path,
|
||||||
@ -140,13 +139,10 @@ impl Action<'_> {
|
|||||||
let walker = WalkDir::new(&self.path)
|
let walker = WalkDir::new(&self.path)
|
||||||
.max_open(1)
|
.max_open(1)
|
||||||
.same_file_system(recurse.map_or(false, |x| x.same_filesystem))
|
.same_file_system(recurse.map_or(false, |x| x.same_filesystem))
|
||||||
.follow_links(recurse.map_or(false, |x| match x.traversal {
|
.follow_links(recurse.map_or(false, |x| matches!(x.traversal, Traversal::FullLinks)));
|
||||||
Traversal::FullLinks => true,
|
|
||||||
_ => false,
|
|
||||||
}));
|
|
||||||
for entry in walker {
|
for entry in walker {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let action = self.into_child(entry)?;
|
let action = self.as_child(entry)?;
|
||||||
action.apply()?;
|
action.apply()?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -68,12 +68,11 @@ impl Cmd for Chown {
|
|||||||
feedback,
|
feedback,
|
||||||
};
|
};
|
||||||
if let Some(r) = recurse {
|
if let Some(r) = recurse {
|
||||||
if action.path.is_dir() {
|
if action.path.is_dir()
|
||||||
|
&& action.path.is_symlink()
|
||||||
|
&& r.traversal != Traversal::NoLinks
|
||||||
|
{
|
||||||
action.recurse(recurse)?;
|
action.recurse(recurse)?;
|
||||||
} else if action.path.is_symlink() {
|
|
||||||
if r.traversal != Traversal::NoLinks {
|
|
||||||
action.recurse(recurse)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.apply()?;
|
action.apply()?;
|
||||||
@ -119,6 +118,7 @@ fn args() -> [Arg; 8] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
enum Traversal {
|
enum Traversal {
|
||||||
CliLinks,
|
CliLinks,
|
||||||
FullLinks,
|
FullLinks,
|
||||||
@ -245,7 +245,7 @@ impl Action<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_child(&self, entry: DirEntry) -> Result<Self, Box<dyn Error>> {
|
fn as_child(&self, entry: DirEntry) -> Result<Self, Box<dyn Error>> {
|
||||||
let path = entry.path().to_path_buf();
|
let path = entry.path().to_path_buf();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
path,
|
path,
|
||||||
@ -259,13 +259,10 @@ impl Action<'_> {
|
|||||||
let walker = WalkDir::new(&self.path)
|
let walker = WalkDir::new(&self.path)
|
||||||
.max_open(1)
|
.max_open(1)
|
||||||
.same_file_system(recurse.map_or(false, |x| x.same_filesystem))
|
.same_file_system(recurse.map_or(false, |x| x.same_filesystem))
|
||||||
.follow_links(recurse.map_or(false, |x| match x.traversal {
|
.follow_links(recurse.map_or(false, |x| matches!(x.traversal, Traversal::FullLinks)));
|
||||||
Traversal::FullLinks => true,
|
|
||||||
_ => false,
|
|
||||||
}));
|
|
||||||
for entry in walker {
|
for entry in walker {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let action = self.into_child(entry)?;
|
let action = self.as_child(entry)?;
|
||||||
action.apply()?;
|
action.apply()?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -59,7 +59,7 @@ impl Cmd for Chroot {
|
|||||||
} else {
|
} else {
|
||||||
env::set_current_dir("/")?;
|
env::set_current_dir("/")?;
|
||||||
}
|
}
|
||||||
return Err(command.exec().into());
|
Err(command.exec().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path(&self) -> Option<shitbox::Path> {
|
fn path(&self) -> Option<shitbox::Path> {
|
||||||
|
@ -44,8 +44,7 @@ impl Cmd for Df {
|
|||||||
if let Some(files) = matches.get_many::<String>("file") {
|
if let Some(files) = matches.get_many::<String>("file") {
|
||||||
for f in files {
|
for f in files {
|
||||||
let entry = MntEntries::new("/proc/mounts")?
|
let entry = MntEntries::new("/proc/mounts")?
|
||||||
.filter(|e| e.dir.as_str() == f)
|
.find(|e| e.dir.as_str() == f)
|
||||||
.next()
|
|
||||||
.ok_or(io::Error::new(io::ErrorKind::Other, "no such filesystem"))?;
|
.ok_or(io::Error::new(io::ErrorKind::Other, "no such filesystem"))?;
|
||||||
print_stats(&entry.fsname, &entry.dir, units)?;
|
print_stats(&entry.fsname, &entry.dir, units)?;
|
||||||
}
|
}
|
||||||
@ -109,8 +108,8 @@ fn print_stats(fs: &str, mntpt: &str, units: Units) -> Result<(), Box<dyn Error>
|
|||||||
Units::Kilo => st.f_frsize / 1024,
|
Units::Kilo => st.f_frsize / 1024,
|
||||||
Units::Natural => st.f_frsize,
|
Units::Natural => st.f_frsize,
|
||||||
};
|
};
|
||||||
let total = st.f_blocks * bs as u64;
|
let total = st.f_blocks * bs;
|
||||||
let avail = st.f_bfree * bs as u64;
|
let avail = st.f_bfree * bs;
|
||||||
let used = total - avail;
|
let used = total - avail;
|
||||||
let mut capacity = if total > 0 { (used * 100) / total } else { 0 };
|
let mut capacity = if total > 0 { (used * 100) / total } else { 0 };
|
||||||
if used * 100 != capacity * (used + avail) {
|
if used * 100 != capacity * (used + avail) {
|
||||||
|
@ -38,7 +38,7 @@ impl Cmd for Expand {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +64,10 @@ impl Cmd for Ln {
|
|||||||
} else {
|
} else {
|
||||||
SymTarget::ToLink
|
SymTarget::ToLink
|
||||||
};
|
};
|
||||||
if files.len() > 1 {
|
if files.len() > 1 && !dest.is_dir() {
|
||||||
if !dest.is_dir() {
|
return Err(
|
||||||
return Err(io::Error::new(
|
io::Error::new(io::ErrorKind::Other, "destination must be a directory").into(),
|
||||||
io::ErrorKind::Other,
|
);
|
||||||
"destination must be a directory",
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for f in files {
|
for f in files {
|
||||||
let source = PathBuf::from(f);
|
let source = PathBuf::from(f);
|
||||||
@ -115,14 +111,12 @@ fn do_link(
|
|||||||
let name = source.file_name().unwrap();
|
let name = source.file_name().unwrap();
|
||||||
dest.push(name);
|
dest.push(name);
|
||||||
}
|
}
|
||||||
if dest.exists() {
|
if dest.exists() && force {
|
||||||
if force {
|
|
||||||
unistd::unlink(
|
unistd::unlink(
|
||||||
dest.to_str()
|
dest.to_str()
|
||||||
.ok_or(io::Error::new(io::ErrorKind::Other, "invalid utf8"))?,
|
.ok_or(io::Error::new(io::ErrorKind::Other, "invalid utf8"))?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if symbolic {
|
if symbolic {
|
||||||
os::unix::fs::symlink(&source, &dest)?;
|
os::unix::fs::symlink(&source, &dest)?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,7 +62,7 @@ impl Cmd for MkTemp {
|
|||||||
let fname = cname.to_str()?;
|
let fname = cname.to_str()?;
|
||||||
println!("{fname}");
|
println!("{fname}");
|
||||||
if matches.get_flag("dryrun") {
|
if matches.get_flag("dryrun") {
|
||||||
fs::remove_dir(&fname)?;
|
fs::remove_dir(fname)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let raw_fd = unsafe { libc::mkstemp(ptr) };
|
let raw_fd = unsafe { libc::mkstemp(ptr) };
|
||||||
@ -73,7 +73,7 @@ impl Cmd for MkTemp {
|
|||||||
let fname = cname.to_str()?;
|
let fname = cname.to_str()?;
|
||||||
println!("{fname}");
|
println!("{fname}");
|
||||||
if matches.get_flag("dryrun") {
|
if matches.get_flag("dryrun") {
|
||||||
fs::remove_file(&fname)?;
|
fs::remove_file(fname)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -43,7 +43,7 @@ impl Cmd for Realpath {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match env::current_dir().and_then(|d| fs::canonicalize(d)) {
|
match env::current_dir().and_then(fs::canonicalize) {
|
||||||
Ok(p) => println!("{}", p.display()),
|
Ok(p) => println!("{}", p.display()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if matches.get_flag("quiet") {
|
if matches.get_flag("quiet") {
|
||||||
|
@ -42,7 +42,7 @@ impl Cmd for Rev {
|
|||||||
}?;
|
}?;
|
||||||
stdout.reset()?;
|
stdout.reset()?;
|
||||||
}
|
}
|
||||||
rev_file(&file)?;
|
rev_file(file)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -83,7 +83,7 @@ impl Cmd for Rm {
|
|||||||
for act in actions.items {
|
for act in actions.items {
|
||||||
if let Err(e) = act.apply() {
|
if let Err(e) = act.apply() {
|
||||||
if !act.force {
|
if !act.force {
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ impl Action {
|
|||||||
Ok(None) => return Ok(()),
|
Ok(None) => return Ok(()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !self.force {
|
if !self.force {
|
||||||
return Err(e.into());
|
return Err(e);
|
||||||
} else {
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ impl Action {
|
|||||||
} else {
|
} else {
|
||||||
match File::open(&self.path)
|
match File::open(&self.path)
|
||||||
.and_then(|fd| fd.metadata())
|
.and_then(|fd| fd.metadata())
|
||||||
.and_then(|meta| Ok(FileType::from(meta)))
|
.map(FileType::from)
|
||||||
{
|
{
|
||||||
Ok(ft) => ft,
|
Ok(ft) => ft,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -220,7 +220,7 @@ impl Action {
|
|||||||
} else {
|
} else {
|
||||||
File::open(path)
|
File::open(path)
|
||||||
.and_then(|fd| fd.metadata())
|
.and_then(|fd| fd.metadata())
|
||||||
.and_then(|meta| Ok(FileType::from(meta)))?
|
.map(FileType::from)?
|
||||||
};
|
};
|
||||||
eprint!("rm: remove {ft} '{}'? ", &self.path);
|
eprint!("rm: remove {ft} '{}'? ", &self.path);
|
||||||
let mut reply = String::new();
|
let mut reply = String::new();
|
||||||
@ -277,10 +277,7 @@ impl AllActions {
|
|||||||
let mut reply = String::new();
|
let mut reply = String::new();
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let _read = stdin.read_line(&mut reply);
|
let _read = stdin.read_line(&mut reply);
|
||||||
match reply.trim_end() {
|
matches!(reply.trim_end(), "y" | "Y" | "yes" | "Yes")
|
||||||
"y" | "Y" | "yes" | "Yes" => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ fn get_values<'a>(
|
|||||||
}
|
}
|
||||||
if flags.contains(Flags::Max) {
|
if flags.contains(Flags::Max) {
|
||||||
f.max = 0;
|
f.max = 0;
|
||||||
contents.lines().into_iter().for_each(|line| {
|
contents.lines().for_each(|line| {
|
||||||
let max = line.chars().count();
|
let max = line.chars().count();
|
||||||
f.max = cmp::max(max, f.max);
|
f.max = cmp::max(max, f.max);
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc, clippy::too_many_lines)]
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::{error, ffi::c_long};
|
use std::{error, ffi::c_long};
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ impl Cmd for B2sum {
|
|||||||
let line = line?;
|
let line = line?;
|
||||||
let mut split = line.split_whitespace();
|
let mut split = line.split_whitespace();
|
||||||
let sum = split.next().ok_or::<io::Error>(
|
let sum = split.next().ok_or::<io::Error>(
|
||||||
io::Error::new(io::ErrorKind::Other, "invalid checksum file").into(),
|
io::Error::new(io::ErrorKind::Other, "invalid checksum file"),
|
||||||
)?;
|
)?;
|
||||||
let file = split.next().ok_or::<io::Error>(
|
let file = split.next().ok_or::<io::Error>(
|
||||||
io::Error::new(io::ErrorKind::Other, "invalid checksum file").into(),
|
io::Error::new(io::ErrorKind::Other, "invalid checksum file"),
|
||||||
)?;
|
)?;
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
let mut fd = File::open(file)?;
|
let mut fd = File::open(file)?;
|
||||||
|
@ -348,7 +348,7 @@ fn completions(prefix: &str, matches: &ArgMatches, usr: bool) -> Result<(), io::
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
if matches.get_flag("zsh") || matches.get_flag("all") {
|
if matches.get_flag("zsh") || matches.get_flag("all") {
|
||||||
let mut outdir = basedir.clone();
|
let mut outdir = basedir;
|
||||||
outdir.push("zsh");
|
outdir.push("zsh");
|
||||||
outdir.push("site-functions");
|
outdir.push("site-functions");
|
||||||
COMMANDS.iter().try_for_each(|cmd| {
|
COMMANDS.iter().try_for_each(|cmd| {
|
||||||
|
@ -47,10 +47,10 @@ pub fn check_sums(file: &str, hashtype: HashType, erred: &mut usize) -> Result<(
|
|||||||
let line = line?;
|
let line = line?;
|
||||||
let mut split = line.split_whitespace();
|
let mut split = line.split_whitespace();
|
||||||
let sum = split.next().ok_or::<io::Error>(
|
let sum = split.next().ok_or::<io::Error>(
|
||||||
io::Error::new(io::ErrorKind::Other, "invalid checksum file").into(),
|
io::Error::new(io::ErrorKind::Other, "invalid checksum file"),
|
||||||
)?;
|
)?;
|
||||||
let file = split.next().ok_or::<io::Error>(
|
let file = split.next().ok_or::<io::Error>(
|
||||||
io::Error::new(io::ErrorKind::Other, "invalid checksum file").into(),
|
io::Error::new(io::ErrorKind::Other, "invalid checksum file"),
|
||||||
)?;
|
)?;
|
||||||
let s = match hashtype {
|
let s = match hashtype {
|
||||||
HashType::Md5 => compute_hash(file, Md5::new())?,
|
HashType::Md5 => compute_hash(file, Md5::new())?,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
use errno::Errno;
|
use errno::Errno;
|
||||||
use sc::*;
|
use sc::syscall;
|
||||||
use std::{error::Error, ffi::CString};
|
use std::{error::Error, ffi::CString};
|
||||||
|
|
||||||
mod mntent;
|
mod mntent;
|
||||||
@ -12,7 +14,7 @@ pub use self::{
|
|||||||
mntflags::{Flags as MntFlags, ParseFlagsError},
|
mntflags::{Flags as MntFlags, ParseFlagsError},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Wraps the Linux SYS_mount syscall in a nicer interface
|
/// Wraps the Linux `SYS_mount` syscall in a nicer interface
|
||||||
pub fn mount(
|
pub fn mount(
|
||||||
dev: &str,
|
dev: &str,
|
||||||
mountpoint: &str,
|
mountpoint: &str,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(clippy::must_use_candidate)]
|
||||||
//! A Rust reimplementation of libc's mntent, for parsing /etc/fstab or
|
//! A Rust reimplementation of libc's mntent, for parsing /etc/fstab or
|
||||||
//! /proc/mounts
|
//! /proc/mounts
|
||||||
use super::{MntEntries, MntFlags};
|
use super::{MntEntries, MntFlags};
|
||||||
@ -52,7 +53,7 @@ impl MntEntry {
|
|||||||
if self.fstype != "swap" {
|
if self.fstype != "swap" {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let dev = self.device().map(|x| x.to_str().map(|x| x.to_string()));
|
let dev = self.device().map(|x| x.to_str().map(ToString::to_string));
|
||||||
let Ok(Some(dev)) = dev else { return false };
|
let Ok(Some(dev)) = dev else { return false };
|
||||||
let Ok(fd) = File::open("/proc/swaps") else {
|
let Ok(fd) = File::open("/proc/swaps") else {
|
||||||
return false;
|
return false;
|
||||||
@ -64,7 +65,7 @@ impl MntEntry {
|
|||||||
};
|
};
|
||||||
let swap = line.split_whitespace().next();
|
let swap = line.split_whitespace().next();
|
||||||
if let Some(swap) = swap {
|
if let Some(swap) = swap {
|
||||||
if swap == &dev {
|
if swap == dev {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,14 +180,11 @@ fn dev_from_uuid(s: &str) -> io::Result<PathBuf> {
|
|||||||
for dev in devs {
|
for dev in devs {
|
||||||
let tags = dev.tags();
|
let tags = dev.tags();
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
match tag.typ() {
|
if let TagType::Superblock(SuperblockTag::Uuid) = tag.typ() {
|
||||||
TagType::Superblock(SuperblockTag::Uuid) => {
|
|
||||||
if uuid.to_lowercase().as_str().trim() == tag.value().trim() {
|
if uuid.to_lowercase().as_str().trim() == tag.value().trim() {
|
||||||
return dev.name().canonicalize();
|
return dev.name().canonicalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
||||||
@ -202,14 +200,11 @@ fn dev_from_label(s: &str) -> io::Result<PathBuf> {
|
|||||||
for dev in devs {
|
for dev in devs {
|
||||||
let tags = dev.tags();
|
let tags = dev.tags();
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
match tag.typ() {
|
if let TagType::Superblock(SuperblockTag::Label) = tag.typ() {
|
||||||
TagType::Superblock(SuperblockTag::Label) => {
|
|
||||||
if label == tag.value() {
|
if label == tag.value() {
|
||||||
return dev.name().canonicalize();
|
return dev.name().canonicalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
||||||
@ -225,14 +220,11 @@ fn dev_from_partuuid(s: &str) -> io::Result<PathBuf> {
|
|||||||
for dev in devs {
|
for dev in devs {
|
||||||
let tags = dev.tags();
|
let tags = dev.tags();
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
match tag.typ() {
|
if let TagType::Partition(PartitionTag::PartEntryUuid) = tag.typ() {
|
||||||
TagType::Partition(PartitionTag::PartEntryUuid) => {
|
|
||||||
if partlabel == tag.value() {
|
if partlabel == tag.value() {
|
||||||
return dev.name().canonicalize();
|
return dev.name().canonicalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
||||||
@ -248,14 +240,11 @@ fn dev_from_partlabel(s: &str) -> io::Result<PathBuf> {
|
|||||||
for dev in devs {
|
for dev in devs {
|
||||||
let tags = dev.tags();
|
let tags = dev.tags();
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
match tag.typ() {
|
if let TagType::Partition(PartitionTag::PartEntryName) = tag.typ() {
|
||||||
TagType::Partition(PartitionTag::PartEntryName) => {
|
|
||||||
if partlabel == tag.value() {
|
if partlabel == tag.value() {
|
||||||
return dev.name().canonicalize();
|
return dev.name().canonicalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
Err(io::Error::new(io::ErrorKind::Other, "device not found"))
|
||||||
|
@ -5,6 +5,7 @@ use std::{
|
|||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[repr(u32)]
|
||||||
pub enum Flags {
|
pub enum Flags {
|
||||||
ReadOnly = 1,
|
ReadOnly = 1,
|
||||||
NoSuid = 2,
|
NoSuid = 2,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc, clippy::must_use_candidate)]
|
||||||
//! Wraps certain libc functions around groups and users
|
//! Wraps certain libc functions around groups and users
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! Common arguments to be re-used across multiple commands. Using these args
|
//! Common arguments to be re-used across multiple commands. Using these args
|
||||||
//! instead of implementing from scratch increases consistency across applets
|
//! instead of implementing from scratch increases consistency across applets
|
||||||
|
#![allow(clippy::must_use_candidate)]
|
||||||
use clap::{Arg, ArgAction};
|
use clap::{Arg, ArgAction};
|
||||||
|
|
||||||
pub fn verbose() -> Arg {
|
pub fn verbose() -> Arg {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
use std::{env, path::PathBuf, string::ToString};
|
use std::{env, path::PathBuf, string::ToString};
|
||||||
|
|
||||||
pub mod args;
|
pub mod args;
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
use errno::Errno;
|
use errno::Errno;
|
||||||
use sc::*;
|
use sc::syscall;
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
ffi::{c_long, CString},
|
ffi::CString,
|
||||||
fs::File,
|
fs::File,
|
||||||
mem,
|
mem,
|
||||||
os::fd::AsRawFd,
|
os::fd::AsRawFd,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn mknod(path: &str, mode: u32, dev: u64) -> Result<(), Box<dyn Error>> {
|
pub fn mknod(path: &str, mode: u32, dev: u64) -> Result<(), Box<dyn Error>> {
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
syscall!(
|
syscall!(
|
||||||
@ -26,7 +25,6 @@ pub fn mknod(path: &str, mode: u32, dev: u64) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn mkfifo(path: &str, mode: u32) -> Result<(), Box<dyn Error>> {
|
pub fn mkfifo(path: &str, mode: u32) -> Result<(), Box<dyn Error>> {
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
syscall!(
|
syscall!(
|
||||||
@ -44,7 +42,6 @@ pub fn mkfifo(path: &str, mode: u32) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn statfs(dir: &str) -> Result<libc::statvfs, Box<dyn Error>> {
|
pub fn statfs(dir: &str) -> Result<libc::statvfs, Box<dyn Error>> {
|
||||||
let mut buf = mem::MaybeUninit::<libc::statvfs>::uninit();
|
let mut buf = mem::MaybeUninit::<libc::statvfs>::uninit();
|
||||||
let fd = File::open(dir)?;
|
let fd = File::open(dir)?;
|
||||||
@ -54,6 +51,6 @@ pub fn statfs(dir: &str) -> Result<libc::statvfs, Box<dyn Error>> {
|
|||||||
Ok(buf)
|
Ok(buf)
|
||||||
} else {
|
} else {
|
||||||
let e = unsafe { *libc::__errno_location() };
|
let e = unsafe { *libc::__errno_location() };
|
||||||
Err(Errno::from(e as c_long).into())
|
Err(Errno::from(i64::from(e)).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
use errno::Errno;
|
use errno::Errno;
|
||||||
use libc::utsname;
|
use libc::utsname;
|
||||||
use sc::syscall;
|
use sc::syscall;
|
||||||
use std::{error::Error, ffi::CString, fs::File, os::fd::AsRawFd, u8};
|
use std::{error::Error, ffi::CString, fs::File, os::fd::AsRawFd, ptr, u8};
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn new_utsname() -> utsname {
|
fn new_utsname() -> utsname {
|
||||||
utsname {
|
utsname {
|
||||||
sysname: [0; 65],
|
sysname: [0; 65],
|
||||||
@ -15,11 +16,11 @@ fn new_utsname() -> utsname {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
pub fn gethostname() -> Result<String, Box<dyn Error>> {
|
pub fn gethostname() -> Result<String, Box<dyn Error>> {
|
||||||
let mut uts = new_utsname();
|
let mut uts = new_utsname();
|
||||||
unsafe {
|
unsafe {
|
||||||
let ret = syscall!(UNAME, &mut uts as *mut utsname);
|
let ret = syscall!(UNAME, ptr::addr_of_mut!(uts));
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
return Err(Errno::from(ret).into());
|
return Err(Errno::from(ret).into());
|
||||||
}
|
}
|
||||||
@ -30,10 +31,9 @@ pub fn gethostname() -> Result<String, Box<dyn Error>> {
|
|||||||
.map(|x| *x as u8)
|
.map(|x| *x as u8)
|
||||||
.take_while(|x| *x != 0)
|
.take_while(|x| *x != 0)
|
||||||
.collect();
|
.collect();
|
||||||
String::from_utf8(name).map_err(|e| e.into())
|
String::from_utf8(name).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn sethostname(name: &str) -> Result<(), Errno> {
|
pub fn sethostname(name: &str) -> Result<(), Errno> {
|
||||||
let ret = unsafe { syscall!(SETHOSTNAME, name.as_ptr(), name.len()) };
|
let ret = unsafe { syscall!(SETHOSTNAME, name.as_ptr(), name.len()) };
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
@ -43,7 +43,6 @@ pub fn sethostname(name: &str) -> Result<(), Errno> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn link(source: &str, dest: &str) -> Result<(), Box<dyn Error>> {
|
pub fn link(source: &str, dest: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
syscall!(
|
syscall!(
|
||||||
@ -62,7 +61,6 @@ pub fn link(source: &str, dest: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn unlink(name: &str) -> Result<(), Box<dyn Error>> {
|
pub fn unlink(name: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let ret = unsafe { syscall!(UNLINKAT, libc::AT_FDCWD, CString::new(name)?.as_ptr(), 0) };
|
let ret = unsafe { syscall!(UNLINKAT, libc::AT_FDCWD, CString::new(name)?.as_ptr(), 0) };
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
@ -72,7 +70,7 @@ pub fn unlink(name: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
pub fn readlink(name: &str) -> Result<String, Box<dyn Error>> {
|
pub fn readlink(name: &str) -> Result<String, Box<dyn Error>> {
|
||||||
let mut buf = Vec::<i8>::with_capacity(1024);
|
let mut buf = Vec::<i8>::with_capacity(1024);
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
@ -90,13 +88,12 @@ pub fn readlink(name: &str) -> Result<String, Box<dyn Error>> {
|
|||||||
.map(|x| *x as u8)
|
.map(|x| *x as u8)
|
||||||
.take_while(|x| *x != 0)
|
.take_while(|x| *x != 0)
|
||||||
.collect();
|
.collect();
|
||||||
String::from_utf8(path).map_err(|e| e.into())
|
String::from_utf8(path).map_err(Into::into)
|
||||||
} else {
|
} else {
|
||||||
Err(Errno::from(ret).into())
|
Err(Errno::from(ret).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn fdatasync(fd: &File) -> Result<(), Errno> {
|
pub fn fdatasync(fd: &File) -> Result<(), Errno> {
|
||||||
let ret = unsafe { syscall!(FDATASYNC, fd.as_raw_fd()) };
|
let ret = unsafe { syscall!(FDATASYNC, fd.as_raw_fd()) };
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
@ -106,7 +103,6 @@ pub fn fdatasync(fd: &File) -> Result<(), Errno> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn syncfs(fd: &File) -> Result<(), Errno> {
|
pub fn syncfs(fd: &File) -> Result<(), Errno> {
|
||||||
let ret = unsafe { syscall!(SYNCFS, fd.as_raw_fd()) };
|
let ret = unsafe { syscall!(SYNCFS, fd.as_raw_fd()) };
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
@ -116,7 +112,6 @@ pub fn syncfs(fd: &File) -> Result<(), Errno> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn fsync(fd: &File) -> Result<(), Errno> {
|
pub fn fsync(fd: &File) -> Result<(), Errno> {
|
||||||
let ret = unsafe { syscall!(FSYNC, fd.as_raw_fd()) };
|
let ret = unsafe { syscall!(FSYNC, fd.as_raw_fd()) };
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
@ -126,12 +121,10 @@ pub fn fsync(fd: &File) -> Result<(), Errno> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn sync() {
|
pub fn sync() {
|
||||||
unsafe { syscall!(SYNC) };
|
unsafe { syscall!(SYNC) };
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn symlink(source: &str, dest: &str) -> Result<(), Box<dyn Error>> {
|
pub fn symlink(source: &str, dest: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
syscall!(
|
syscall!(
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(clippy::must_use_candidate)]
|
||||||
use bitflags::BitFlags;
|
use bitflags::BitFlags;
|
||||||
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
|
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
|
||||||
|
|
||||||
@ -80,7 +81,9 @@ impl BitOrAssign<Bit> for u32 {
|
|||||||
|
|
||||||
impl Bit {
|
impl Bit {
|
||||||
pub fn as_char(&self, mode: u32) -> char {
|
pub fn as_char(&self, mode: u32) -> char {
|
||||||
if mode & *self != 0 {
|
if mode & *self == 0 {
|
||||||
|
'-'
|
||||||
|
} else {
|
||||||
match self {
|
match self {
|
||||||
Self::Suid | Self::Sgid => 's',
|
Self::Suid | Self::Sgid => 's',
|
||||||
Self::Sticky => 't',
|
Self::Sticky => 't',
|
||||||
@ -91,8 +94,6 @@ impl Bit {
|
|||||||
Self::OExec if mode.contains(Self::Sticky) => 't',
|
Self::OExec if mode.contains(Self::Sticky) => 't',
|
||||||
Self::UExec | Self::GExec | Self::OExec => 'x',
|
Self::UExec | Self::GExec | Self::OExec => 'x',
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
'-'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
//! Functions for parsing and managing permissions
|
//! Functions for parsing and managing permissions
|
||||||
mod bit;
|
mod bit;
|
||||||
mod parser;
|
mod parser;
|
||||||
|
@ -348,7 +348,7 @@ fn completions(prefix: &str, matches: &ArgMatches, usr: bool) -> Result<(), io::
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
if matches.get_flag("zsh") || matches.get_flag("all") {
|
if matches.get_flag("zsh") || matches.get_flag("all") {
|
||||||
let mut outdir = basedir.clone();
|
let mut outdir = basedir;
|
||||||
outdir.push("zsh");
|
outdir.push("zsh");
|
||||||
outdir.push("site-functions");
|
outdir.push("site-functions");
|
||||||
COMMANDS.iter().try_for_each(|cmd| {
|
COMMANDS.iter().try_for_each(|cmd| {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
use clap::{ArgMatches, Command};
|
||||||
use shitbox::Cmd;
|
use shitbox::Cmd;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
@ -9,7 +9,7 @@ impl Cmd for Mount {
|
|||||||
Command::new("mount")
|
Command::new("mount")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
fn run(&self, _matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ use std::{
|
|||||||
io::{self, Read, Seek, SeekFrom, Write},
|
io::{self, Read, Seek, SeekFrom, Write},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SWAP_MAGIC1: &'static str = "SWAPSPACE2";
|
const SWAP_MAGIC1: &str = "SWAPSPACE2";
|
||||||
const SWAP_MAGIC2: &'static str = "SWAP_SPACE";
|
const SWAP_MAGIC2: &str = "SWAP_SPACE";
|
||||||
const SWAP_MAGIC_LENGTH: u64 = 10;
|
const SWAP_MAGIC_LENGTH: u64 = 10;
|
||||||
const SWAP_LABEL_LENGTH: u64 = 16;
|
const SWAP_LABEL_LENGTH: u64 = 16;
|
||||||
const SWAP_LABEL_OFFSET: u64 = 1024 + 4 + 4 + 4 + 16;
|
const SWAP_LABEL_OFFSET: u64 = 1024 + 4 + 4 + 4 + 16;
|
||||||
@ -61,7 +61,7 @@ impl Cmd for Swaplabel {
|
|||||||
return Err(io::Error::new(io::ErrorKind::Other, "label is too long").into());
|
return Err(io::Error::new(io::ErrorKind::Other, "label is too long").into());
|
||||||
}
|
}
|
||||||
let label = CString::new(label.as_str())?;
|
let label = CString::new(label.as_str())?;
|
||||||
fd.write(label.as_bytes())?;
|
fd.write_all(label.as_bytes())?;
|
||||||
} else {
|
} else {
|
||||||
let mut label = [0; SWAP_LABEL_LENGTH as usize];
|
let mut label = [0; SWAP_LABEL_LENGTH as usize];
|
||||||
fd.read_exact(&mut label)?;
|
fd.read_exact(&mut label)?;
|
||||||
|
@ -47,7 +47,7 @@ impl Cmd for Swapoff {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(devices) = matches.get_many::<String>("device") {
|
} else if let Some(devices) = matches.get_many::<String>("device") {
|
||||||
for d in devices {
|
'devloop: for d in devices {
|
||||||
let fd = File::open("/proc/swaps")?;
|
let fd = File::open("/proc/swaps")?;
|
||||||
let reader = BufReader::new(fd);
|
let reader = BufReader::new(fd);
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
@ -61,7 +61,7 @@ impl Cmd for Swapoff {
|
|||||||
if matches.get_flag("verbose") {
|
if matches.get_flag("verbose") {
|
||||||
println!("swapoff {d}");
|
println!("swapoff {d}");
|
||||||
}
|
}
|
||||||
return Ok(());
|
continue 'devloop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let msg = format!("{d} is not swapped");
|
let msg = format!("{d} is not swapped");
|
||||||
|
@ -100,13 +100,11 @@ impl Cmd for Umount {
|
|||||||
if x.fstype == t {
|
if x.fstype == t {
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else if &x.fstype != t {
|
||||||
if &x.fstype != t {
|
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Some(spec) = matches.get_many::<String>("spec") {
|
if let Some(spec) = matches.get_many::<String>("spec") {
|
||||||
let mut r2 = false;
|
let mut r2 = false;
|
||||||
for s in spec {
|
for s in spec {
|
||||||
@ -126,8 +124,7 @@ impl Cmd for Umount {
|
|||||||
println!("umount: {} unmounted", &p.dir);
|
println!("umount: {} unmounted", &p.dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(spec) = matches.get_many::<String>("spec") {
|
||||||
if let Some(spec) = matches.get_many::<String>("spec") {
|
|
||||||
for s in spec {
|
for s in spec {
|
||||||
let mntpt = get_mntpt(s)?;
|
let mntpt = get_mntpt(s)?;
|
||||||
mount::umount(&mntpt, flags as u32)?;
|
mount::umount(&mntpt, flags as u32)?;
|
||||||
@ -136,7 +133,6 @@ impl Cmd for Umount {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +145,7 @@ fn get_mntpt(spec: &str) -> io::Result<String> {
|
|||||||
let entries = MntEntries::new("/proc/mounts")?;
|
let entries = MntEntries::new("/proc/mounts")?;
|
||||||
for e in entries {
|
for e in entries {
|
||||||
if e.fsname == spec {
|
if e.fsname == spec {
|
||||||
return Ok(e.dir.clone());
|
return Ok(e.dir);
|
||||||
} else if e.dir == spec {
|
} else if e.dir == spec {
|
||||||
return Ok(spec.to_string());
|
return Ok(spec.to_string());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user