Broke stat out into workspace crate; Reduced clap features for smaller

size;
This commit is contained in:
Nathan Fisher 2023-02-21 00:07:16 -05:00
parent 102678015b
commit 44914ced6f
10 changed files with 61 additions and 182 deletions

174
Cargo.lock generated
View File

@ -38,7 +38,7 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi 0.1.19", "hermit-abi",
"libc", "libc",
"winapi", "winapi",
] ]
@ -120,12 +120,6 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]] [[package]]
name = "cexpr" name = "cexpr"
version = "0.4.0" version = "0.4.0"
@ -143,9 +137,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "clang-sys" name = "clang-sys"
version = "1.4.0" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a"
dependencies = [ dependencies = [
"glob", "glob",
"libc", "libc",
@ -161,7 +155,7 @@ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"strsim 0.8.0", "strsim",
"textwrap 0.11.0", "textwrap 0.11.0",
"unicode-width", "unicode-width",
"vec_map", "vec_map",
@ -175,9 +169,6 @@ checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"clap_lex", "clap_lex",
"is-terminal",
"strsim 0.10.0",
"termcolor",
] ]
[[package]] [[package]]
@ -276,27 +267,6 @@ dependencies = [
name = "errno" name = "errno"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.6" version = "0.14.6"
@ -331,40 +301,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]] [[package]]
name = "humantime" name = "humantime"
version = "2.1.0" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "is-terminal"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -393,12 +335,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.17" version = "0.4.17"
@ -428,7 +364,7 @@ name = "mount"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"blkid", "blkid",
"errno 0.1.0", "errno",
"sc", "sc",
] ]
@ -514,20 +450,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno 0.2.8",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.11" version = "1.0.11"
@ -584,7 +506,7 @@ dependencies = [
"clap_mangen", "clap_mangen",
"data-encoding", "data-encoding",
"digest", "digest",
"errno 0.1.0", "errno",
"lazy_static", "lazy_static",
"libc", "libc",
"md-5", "md-5",
@ -598,6 +520,7 @@ dependencies = [
"textwrap 0.16.0", "textwrap 0.16.0",
"unistd", "unistd",
"unix-mode", "unix-mode",
"unix-stat",
"walkdir", "walkdir",
] ]
@ -625,12 +548,6 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.23.0" version = "0.23.0"
@ -736,7 +653,7 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
name = "unistd" name = "unistd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"errno 0.1.0", "errno",
"libc", "libc",
"sc", "sc",
] ]
@ -749,6 +666,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "unix-stat"
version = "0.1.0"
dependencies = [
"errno",
"libc",
"sc",
]
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.8.2" version = "0.8.2"
@ -811,69 +737,3 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[workspace] [workspace]
members = [ "bitflags-mini", "errno", "mount", "pw", "unistd", "unix-mode" ] members = [ "bitflags-mini", "errno", "mount", "pw", "unistd", "unix-mode", "unix-stat" ]
[[bin]] [[bin]]
name = "corebox" name = "corebox"
@ -25,7 +25,6 @@ sc = "0.2"
[dependencies] [dependencies]
atty = "0.2" atty = "0.2"
blake2b_simd = "1.0" blake2b_simd = "1.0"
clap = "4.1"
clap_complete = "4.1" clap_complete = "4.1"
clap_complete_nushell = "0.1" clap_complete_nushell = "0.1"
clap_mangen = "0.2" clap_mangen = "0.2"
@ -46,6 +45,11 @@ walkdir = "2.3"
package = "bitflags-mini" package = "bitflags-mini"
path = "bitflags-mini" path = "bitflags-mini"
[dependencies.clap]
version = "4.1"
default_features = false
features = ["std", "help", "usage", "error-context"]
[dependencies.errno] [dependencies.errno]
package = "errno" package = "errno"
path = "errno" path = "errno"
@ -57,6 +61,10 @@ path = "unix-mode"
[dependencies.mount] [dependencies.mount]
path = "mount" path = "mount"
[dependencies.stat]
package = "unix-stat"
path = "unix-stat"
[dependencies.unistd] [dependencies.unistd]
package = "unistd" package = "unistd"
path = "unistd" path = "unistd"

View File

@ -102,7 +102,7 @@ impl fmt::Display for Units {
fn print_stats(fs: &str, mntpt: &str, units: Units) -> Result<(), Box<dyn Error>> { fn print_stats(fs: &str, mntpt: &str, units: Units) -> Result<(), Box<dyn Error>> {
let p = PathBuf::from(mntpt); let p = PathBuf::from(mntpt);
if p.exists() { if p.exists() {
let st = shitbox::stat::statfs(mntpt)?; let st = stat::statfs(mntpt)?;
let bs = match units { let bs = match units {
Units::Posix => st.f_frsize / 512, Units::Posix => st.f_frsize / 512,
Units::Kilo => st.f_frsize / 1024, Units::Kilo => st.f_frsize / 1024,

View File

@ -1,7 +1,7 @@
use super::Cmd; use super::Cmd;
use clap::{Arg, ArgMatches, Command}; use clap::{Arg, ArgMatches, Command};
use mode::Parser; use mode::Parser;
use shitbox::{args, stat}; use shitbox::args;
use std::error::Error; use std::error::Error;
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@ -1,7 +1,7 @@
use super::Cmd; use super::Cmd;
use clap::{value_parser, Arg, ArgMatches, Command}; use clap::{value_parser, Arg, ArgMatches, Command};
use mode::{get_umask, Parser}; use mode::{get_umask, Parser};
use shitbox::{args, stat}; use shitbox::args;
use std::{convert::Infallible, error::Error, io, str::FromStr}; use std::{convert::Infallible, error::Error, io, str::FromStr};
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@ -53,12 +53,14 @@ impl Cmd for B2sum {
for line in reader.lines() { for line in reader.lines() {
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::Error::new(io::ErrorKind::Other, "invalid checksum file"), io::ErrorKind::Other,
)?; "invalid checksum file",
let file = split.next().ok_or::<io::Error>( ))?;
io::Error::new(io::ErrorKind::Other, "invalid checksum file"), let file = split.next().ok_or::<io::Error>(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)?;
fd.read_to_end(&mut buf)?; fd.read_to_end(&mut buf)?;

View File

@ -46,12 +46,14 @@ pub fn check_sums(file: &str, hashtype: HashType, erred: &mut usize) -> Result<(
for line in reader.lines() { for line in reader.lines() {
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::Error::new(io::ErrorKind::Other, "invalid checksum file"), io::ErrorKind::Other,
)?; "invalid checksum file",
let file = split.next().ok_or::<io::Error>( ))?;
io::Error::new(io::ErrorKind::Other, "invalid checksum file"), let file = split.next().ok_or::<io::Error>(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())?,
HashType::Sha1 => compute_hash(file, Sha1::new())?, HashType::Sha1 => compute_hash(file, Sha1::new())?,

View File

@ -6,7 +6,6 @@ pub mod args;
mod cmd; mod cmd;
pub mod fs; pub mod fs;
pub mod math; pub mod math;
pub mod stat;
pub use cmd::Cmd; pub use cmd::Cmd;

14
unix-stat/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "unix-stat"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = { workspace = true }
sc = { workspace = true }
[dependencies.errno]
package = "errno"
path = "../errno"

View File

@ -1,12 +1,6 @@
use errno::Errno; use errno::Errno;
use sc::syscall; use sc::syscall;
use std::{ use std::{error::Error, ffi::CString, fs::File, mem, os::fd::AsRawFd};
error::Error,
ffi::CString,
fs::File,
mem,
os::fd::AsRawFd,
};
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 {