mirror of
https://github.com/uutils/coreutils
synced 2024-11-14 08:57:13 +00:00
Split off uucore into its own repository
This commit is contained in:
parent
e1cf3a42d5
commit
b73a664677
117 changed files with 283 additions and 2760 deletions
372
Cargo.lock
generated
372
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -157,7 +157,7 @@ default = ["unix"]
|
|||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="src/uucore" }
|
||||
uucore = "0.0.1"
|
||||
arch = { optional=true, path="src/arch" }
|
||||
base32 = { optional=true, path="src/base32" }
|
||||
base64 = { optional=true, path="src/base64" }
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "arch.rs"
|
|||
|
||||
[dependencies]
|
||||
platform-info = "0.0.1"
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "arch"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_base32"
|
|||
path = "base32.rs"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["encoding"]
|
||||
|
||||
[dependencies.clippy]
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_base64"
|
|||
path = "base64.rs"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["encoding"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_basename"
|
|||
path = "basename.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "basename"
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "cat.rs"
|
|||
quick-error = "1.2.2"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "chgrp.rs"
|
|||
walkdir = "2.1.4"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries", "fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -13,7 +13,7 @@ libc = "0.2.42"
|
|||
walker = "1.0.0"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["mode"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -13,7 +13,7 @@ glob = "0.2.11"
|
|||
walkdir = "2.1"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries", "fs"]
|
||||
|
||||
[dependencies.clippy]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "chroot.rs"
|
|||
getopts = "0.2.18"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -9,7 +9,7 @@ path = "cksum.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "cksum"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "comm.rs"
|
|||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "comm"
|
||||
|
|
|
@ -20,7 +20,7 @@ quick-error = "1.2.2"
|
|||
filetime = "0.2"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_cut"
|
|||
path = "cut.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "cut"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "date.rs"
|
|||
[dependencies]
|
||||
chrono = "0.4.4"
|
||||
clap = "2.32.0"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "date"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "dircolors.rs"
|
|||
|
||||
[dependencies]
|
||||
glob = "0.2.11"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "dircolors"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "dirname.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "dirname"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "du.rs"
|
|||
|
||||
[dependencies]
|
||||
time = "0.1.40"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "du"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_echo"
|
|||
path = "echo.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "echo"
|
||||
|
|
2
src/env/Cargo.toml
vendored
2
src/env/Cargo.toml
vendored
|
@ -10,7 +10,7 @@ path = "env.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
rust-ini = "0.13.0"
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "expand.rs"
|
|||
[dependencies]
|
||||
unicode-width = "0.1.5"
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "expand"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "expr.rs"
|
|||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
onig = "~4.3.2"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "expr"
|
||||
|
|
|
@ -9,7 +9,7 @@ path = "factor.rs"
|
|||
|
||||
[dependencies]
|
||||
rand = "0.5"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "factor"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_false"
|
|||
path = "false.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "false"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "fmt.rs"
|
|||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
unicode-width = "0.1.5"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "fmt"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_fold"
|
|||
path = "fold.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "fold"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_groups"
|
|||
path = "groups.rs"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -19,7 +19,7 @@ regex-syntax = "0.6.1"
|
|||
sha1 = "0.6.0"
|
||||
sha2 = "0.6.0"
|
||||
sha3 = "0.6.0"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "hashsum"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "head.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "head"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "hostid.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "hostid"
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "hostname.rs"
|
|||
libc = "0.2.42"
|
||||
winapi = { version = "0.3", features = ["sysinfoapi", "winsock2"] }
|
||||
getopts = "0.2"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "hostname"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_id"
|
|||
path = "id.rs"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries", "process"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "install.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = ">= 0.2"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
time = "0.1.40"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "join.rs"
|
|||
|
||||
[dependencies]
|
||||
clap = "2.32.0"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "join"
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "kill.rs"
|
|||
libc = "0.2.42"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["signals"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "link.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "link"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "ln.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "ln"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "logname.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "logname"
|
||||
|
|
|
@ -18,7 +18,7 @@ lazy_static = "1.0.1"
|
|||
unicode-width = "0.1.5"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries", "fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "mkdir.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "mkdir"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "mkfifo.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "mkfifo"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "mknod.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "^0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "mknod"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_mktemp"
|
|||
path = "mktemp.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
getopts = "0.2.18"
|
||||
rand = "0.5"
|
||||
tempfile = "2.1.5"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "more.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
redox_termios = "0.1"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "mv.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "mv"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "nice.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "nice"
|
||||
|
|
|
@ -15,7 +15,7 @@ aho-corasick = "0.6.5"
|
|||
memchr = "1.0.1"
|
||||
regex = "1.0.1"
|
||||
regex-syntax = "0.6.1"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "nl"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
libc = "0.2.42"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "nproc.rs"
|
|||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
num_cpus = "1.5"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "nproc"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "numfmt.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "numfmt"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
libc = "0.2.42"
|
||||
byteorder = "1.1.0"
|
||||
half = "1.1.1"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "od"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "paste.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "paste"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "pathchk.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "pathchk"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_pinky"
|
|||
path = "pinky.rs"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["utmpx", "entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "printenv.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "printenv"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "printf.rs"
|
|||
|
||||
[dependencies]
|
||||
itertools = "0.7.8"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "printf"
|
||||
|
|
|
@ -15,7 +15,7 @@ aho-corasick = "0.6.5"
|
|||
memchr = "1.0.1"
|
||||
regex-syntax = "0.6.1"
|
||||
regex = "1.0.1"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "ptx"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "pwd.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "pwd"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
libc = "0.2.42"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "realpath.rs"
|
|||
getopts = "0.2.18"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "relpath.rs"
|
|||
getopts = "0.2.18"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "rm.rs"
|
|||
getopts = "0.2.18"
|
||||
walkdir = "2.1.4"
|
||||
remove_dir_all = "0.5.1"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "rm"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "rmdir.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "rmdir"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "seq.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "seq"
|
||||
|
|
|
@ -14,7 +14,7 @@ filetime = "0.2.1"
|
|||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
time = "0.1.40"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "shred"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "shuf.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
rand = "0.5"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "shuf"
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "sleep.rs"
|
|||
getopts = "0.2.18"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["parse_time"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -14,7 +14,7 @@ semver = "0.9.0"
|
|||
itertools = "0.7.8"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "split.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "split"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
time = "0.1.40"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "stdbuf.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
tempdir = "0.3.7"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[build-dependencies]
|
||||
libstdbuf = { path="libstdbuf" }
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "libstdbuf.rs"
|
|||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../../uucore" }
|
||||
uucore = "0.0.1"
|
||||
libc = "0.2"
|
||||
cpp = "0.4"
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "sum.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "sum"
|
||||
|
|
|
@ -15,7 +15,7 @@ winapi = { version = "0.3", features = ["handleapi", "winerror"] }
|
|||
kernel32-sys = "0.2.2"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["wide"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "tac.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "tac"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
kernel32-sys = "0.2.2"
|
||||
libc = "0.2.42"
|
||||
winapi = "0.3"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
redox_syscall = "0.1"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "tee.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "tee"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "test.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
redox_syscall = "0.1"
|
||||
|
|
|
@ -14,7 +14,7 @@ libc = "0.2.42"
|
|||
time = "0.1.40"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["parse_time", "process"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -14,7 +14,7 @@ getopts = "0.2.18"
|
|||
time = "0.1.40"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["libc"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "tr.rs"
|
|||
getopts = "0.2.18"
|
||||
bit-set = "0.5.0"
|
||||
fnv = "1.0.5"
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "tr"
|
||||
|
|
|
@ -9,7 +9,7 @@ name = "uu_true"
|
|||
path = "true.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "true"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "truncate.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "truncate"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "tsort.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "tsort"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
libc = "0.2.42"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "uname.rs"
|
|||
[dependencies]
|
||||
clap = "2.32.0"
|
||||
platform-info = "0.0.1"
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "uname"
|
||||
|
|
|
@ -11,9 +11,7 @@ path = "unexpand.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
unicode-width = "0.1.5"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "unexpand"
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "uniq.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
uucore = { path = "../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "uniq"
|
||||
|
|
|
@ -11,7 +11,7 @@ path = "unlink.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
libc = "0.2.42"
|
||||
uucore = { path="../uucore" }
|
||||
uucore = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "unlink"
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
time = "0.1.40"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
features = ["utmpx"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -13,7 +13,7 @@ getopts = "0.2.18"
|
|||
|
||||
[dependencies.uucore]
|
||||
features = ["utmpx"]
|
||||
path = "../uucore"
|
||||
version = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "users"
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
[package]
|
||||
name = "uucore"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
failure = { version = "0.1.1", optional = true }
|
||||
failure_derive = { version = "0.1.1", optional = true }
|
||||
time = { version = "0.1.40", optional = true }
|
||||
data-encoding = { version = "^2.1", optional = true }
|
||||
libc = { version = "0.2.42", optional = true }
|
||||
wild = "2.0.1"
|
||||
nix = { version = "0.13", optional = true }
|
||||
lazy_static = { version = "1.3", optional = true }
|
||||
platform-info = { version = "0.0.1", optional = true }
|
||||
|
||||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
termion = "1.5"
|
||||
|
||||
[features]
|
||||
fs = ["libc"]
|
||||
utf8 = []
|
||||
encoding = ["data-encoding", "failure", "failure_derive"]
|
||||
parse_time = []
|
||||
mode = ["libc"]
|
||||
utmpx = ["time", "libc"]
|
||||
process = ["libc"]
|
||||
signals = []
|
||||
entries = ["libc"]
|
||||
zero-copy = ["nix", "libc", "lazy_static", "platform-info"]
|
||||
wide = []
|
||||
default = []
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
name = "uucore"
|
|
@ -1,141 +0,0 @@
|
|||
extern crate getopts;
|
||||
|
||||
pub struct HelpText<'a> {
|
||||
pub name: &'a str,
|
||||
pub version: &'a str,
|
||||
pub syntax: &'a str,
|
||||
pub summary: &'a str,
|
||||
pub long_help: &'a str,
|
||||
pub display_usage: bool,
|
||||
}
|
||||
|
||||
pub struct CoreOptions<'a> {
|
||||
options: getopts::Options,
|
||||
help_text: HelpText<'a>,
|
||||
}
|
||||
|
||||
impl<'a> CoreOptions<'a> {
|
||||
pub fn new(help_text: HelpText<'a>) -> Self {
|
||||
let mut ret = CoreOptions {
|
||||
options: getopts::Options::new(),
|
||||
help_text,
|
||||
};
|
||||
ret.options
|
||||
.optflag("", "help", "print usage information")
|
||||
.optflag("", "version", "print name and version number");
|
||||
ret
|
||||
}
|
||||
pub fn optflagopt(
|
||||
&mut self,
|
||||
short_name: &str,
|
||||
long_name: &str,
|
||||
desc: &str,
|
||||
hint: &str,
|
||||
) -> &mut CoreOptions<'a> {
|
||||
self.options.optflagopt(short_name, long_name, desc, hint);
|
||||
self
|
||||
}
|
||||
pub fn optflag(
|
||||
&mut self,
|
||||
short_name: &str,
|
||||
long_name: &str,
|
||||
desc: &str,
|
||||
) -> &mut CoreOptions<'a> {
|
||||
self.options.optflag(short_name, long_name, desc);
|
||||
self
|
||||
}
|
||||
pub fn optflagmulti(
|
||||
&mut self,
|
||||
short_name: &str,
|
||||
long_name: &str,
|
||||
desc: &str,
|
||||
) -> &mut CoreOptions<'a> {
|
||||
self.options.optflagmulti(short_name, long_name, desc);
|
||||
self
|
||||
}
|
||||
pub fn optopt(
|
||||
&mut self,
|
||||
short_name: &str,
|
||||
long_name: &str,
|
||||
desc: &str,
|
||||
hint: &str,
|
||||
) -> &mut CoreOptions<'a> {
|
||||
self.options.optopt(short_name, long_name, desc, hint);
|
||||
self
|
||||
}
|
||||
pub fn optmulti(
|
||||
&mut self,
|
||||
short_name: &str,
|
||||
long_name: &str,
|
||||
desc: &str,
|
||||
hint: &str,
|
||||
) -> &mut CoreOptions<'a> {
|
||||
self.options.optmulti(short_name, long_name, desc, hint);
|
||||
self
|
||||
}
|
||||
pub fn usage(&self, summary: &str) -> String {
|
||||
self.options.usage(summary)
|
||||
}
|
||||
pub fn parse(&mut self, args: Vec<String>) -> getopts::Matches {
|
||||
let matches = match self.options.parse(&args[1..]) {
|
||||
Ok(m) => Some(m),
|
||||
Err(f) => {
|
||||
eprint!("{}: error: ", self.help_text.name);
|
||||
eprintln!("{}", f);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}.unwrap();
|
||||
if matches.opt_present("help") {
|
||||
let usage_str = if self.help_text.display_usage {
|
||||
format!(
|
||||
"\n {}\n\n Reference\n",
|
||||
self.options.usage(self.help_text.summary)
|
||||
).replace("Options:", " Options:")
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
print!(
|
||||
"
|
||||
{0} {1}
|
||||
|
||||
{0} {2}
|
||||
{3}{4}
|
||||
",
|
||||
self.help_text.name,
|
||||
self.help_text.version,
|
||||
self.help_text.syntax,
|
||||
usage_str,
|
||||
self.help_text.long_help
|
||||
);
|
||||
exit!(0);
|
||||
} else if matches.opt_present("version") {
|
||||
println!("{} {}", self.help_text.name, self.help_text.version);
|
||||
exit!(0);
|
||||
}
|
||||
matches
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! new_coreopts {
|
||||
($syntax: expr, $summary: expr, $long_help: expr) => (
|
||||
uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText {
|
||||
name: executable!(),
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
syntax: $syntax,
|
||||
summary: $summary,
|
||||
long_help: $long_help,
|
||||
display_usage: true
|
||||
})
|
||||
);
|
||||
($syntax: expr, $summary: expr, $long_help: expr, $display_usage: expr) => (
|
||||
uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText {
|
||||
name: executable!(),
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
syntax: $syntax,
|
||||
summary: $summary,
|
||||
long_help: $long_help,
|
||||
display_usage: $display_usage
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Jian Zeng <anonymousknight96@gmail.com>
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
//
|
||||
|
||||
extern crate data_encoding;
|
||||
use self::data_encoding::{DecodeError, BASE32, BASE64};
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
pub enum EncodingError {
|
||||
#[fail(display = "{}", _0)]
|
||||
Decode(#[cause] DecodeError),
|
||||
#[fail(display = "{}", _0)]
|
||||
Io(#[cause] io::Error),
|
||||
}
|
||||
|
||||
impl From<io::Error> for EncodingError {
|
||||
fn from(err: io::Error) -> EncodingError {
|
||||
EncodingError::Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecodeError> for EncodingError {
|
||||
fn from(err: DecodeError) -> EncodingError {
|
||||
EncodingError::Decode(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub type DecodeResult = Result<Vec<u8>, EncodingError>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Format {
|
||||
Base32,
|
||||
Base64,
|
||||
}
|
||||
use self::Format::*;
|
||||
|
||||
pub fn encode(f: Format, input: &[u8]) -> String {
|
||||
match f {
|
||||
Base32 => BASE32.encode(input),
|
||||
Base64 => BASE64.encode(input),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(f: Format, input: &[u8]) -> DecodeResult {
|
||||
Ok(match f {
|
||||
Base32 => BASE32.decode(input)?,
|
||||
Base64 => BASE64.decode(input)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Data<R: Read> {
|
||||
line_wrap: usize,
|
||||
ignore_garbage: bool,
|
||||
input: R,
|
||||
format: Format,
|
||||
alphabet: &'static [u8],
|
||||
}
|
||||
|
||||
impl<R: Read> Data<R> {
|
||||
pub fn new(input: R, format: Format) -> Self {
|
||||
Data {
|
||||
line_wrap: 76,
|
||||
ignore_garbage: false,
|
||||
input,
|
||||
format,
|
||||
alphabet: match format {
|
||||
Base32 => b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
||||
Base64 => b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=+/",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn line_wrap(mut self, wrap: usize) -> Self {
|
||||
self.line_wrap = wrap;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ignore_garbage(mut self, ignore: bool) -> Self {
|
||||
self.ignore_garbage = ignore;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn decode(&mut self) -> DecodeResult {
|
||||
let mut buf = vec![];
|
||||
self.input.read_to_end(&mut buf)?;
|
||||
if self.ignore_garbage {
|
||||
buf.retain(|c| self.alphabet.contains(c));
|
||||
} else {
|
||||
buf.retain(|&c| c != b'\r' && c != b'\n');
|
||||
};
|
||||
decode(self.format, &buf)
|
||||
}
|
||||
|
||||
pub fn encode(&mut self) -> String {
|
||||
let mut buf: Vec<u8> = vec![];
|
||||
self.input.read_to_end(&mut buf).unwrap();
|
||||
encode(self.format, buf.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this will likely be phased out at some point
|
||||
pub fn wrap_print<R: Read>(data: &Data<R>, res: String) {
|
||||
let stdout = io::stdout();
|
||||
wrap_write(stdout.lock(), data.line_wrap, res).unwrap();
|
||||
}
|
||||
|
||||
pub fn wrap_write<W: Write>(mut writer: W, line_wrap: usize, res: String) -> io::Result<()> {
|
||||
use std::cmp::min;
|
||||
|
||||
if line_wrap == 0 {
|
||||
return write!(writer, "{}", res);
|
||||
}
|
||||
|
||||
let mut start = 0;
|
||||
while start < res.len() {
|
||||
let end = min(start + line_wrap, res.len());
|
||||
writeln!(writer, "{}", &res[start..end])?;
|
||||
start = end;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Jian Zeng <anonymousknight96@gmail.com>
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
//! Get password/group file entry
|
||||
//!
|
||||
//! # Examples:
|
||||
//!
|
||||
//! ```
|
||||
//! use uucore::entries::{self, Locate};
|
||||
//! assert_eq!("root", entries::uid2usr(0).unwrap());
|
||||
//! assert_eq!(0, entries::usr2uid("root").unwrap());
|
||||
//! assert!(entries::gid2grp(0).is_ok());
|
||||
//! assert!(entries::grp2gid("root").is_ok());
|
||||
//!
|
||||
//! assert!(entries::Passwd::locate(0).is_ok());
|
||||
//! assert!(entries::Passwd::locate("0").is_ok());
|
||||
//! assert!(entries::Passwd::locate("root").is_ok());
|
||||
//!
|
||||
//! assert!(entries::Group::locate(0).is_ok());
|
||||
//! assert!(entries::Group::locate("0").is_ok());
|
||||
//! assert!(entries::Group::locate("root").is_ok());
|
||||
//! ```
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
|
||||
use libc::time_t;
|
||||
use libc::{c_char, c_int, gid_t, uid_t};
|
||||
use libc::{getgrgid, getgrnam, getgroups, getpwnam, getpwuid, group, passwd};
|
||||
|
||||
use std::ptr;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Error as IOError;
|
||||
use std::io::Result as IOResult;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::borrow::Cow;
|
||||
|
||||
extern "C" {
|
||||
fn getgrouplist(
|
||||
name: *const c_char,
|
||||
gid: gid_t,
|
||||
groups: *mut gid_t,
|
||||
ngroups: *mut c_int,
|
||||
) -> c_int;
|
||||
}
|
||||
|
||||
pub fn get_groups() -> IOResult<Vec<gid_t>> {
|
||||
let ngroups = unsafe { getgroups(0, ptr::null_mut()) };
|
||||
if ngroups == -1 {
|
||||
return Err(IOError::last_os_error());
|
||||
}
|
||||
let mut groups = Vec::with_capacity(ngroups as usize);
|
||||
let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) };
|
||||
if ngroups == -1 {
|
||||
Err(IOError::last_os_error())
|
||||
} else {
|
||||
unsafe {
|
||||
groups.set_len(ngroups as usize);
|
||||
}
|
||||
Ok(groups)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Passwd {
|
||||
inner: passwd,
|
||||
}
|
||||
|
||||
macro_rules! cstr2cow {
|
||||
($v:expr) => (
|
||||
unsafe { CStr::from_ptr($v).to_string_lossy() }
|
||||
)
|
||||
}
|
||||
|
||||
impl Passwd {
|
||||
/// AKA passwd.pw_name
|
||||
pub fn name(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_name)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_uid
|
||||
pub fn uid(&self) -> uid_t {
|
||||
self.inner.pw_uid
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_gid
|
||||
pub fn gid(&self) -> gid_t {
|
||||
self.inner.pw_gid
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_gecos
|
||||
pub fn user_info(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_gecos)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_shell
|
||||
pub fn user_shell(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_shell)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_dir
|
||||
pub fn user_dir(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_dir)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_passwd
|
||||
pub fn user_passwd(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_passwd)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_class
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
|
||||
pub fn user_access_class(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.pw_class)
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_change
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
|
||||
pub fn passwd_change_time(&self) -> time_t {
|
||||
self.inner.pw_change
|
||||
}
|
||||
|
||||
/// AKA passwd.pw_expire
|
||||
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
|
||||
pub fn expiration(&self) -> time_t {
|
||||
self.inner.pw_expire
|
||||
}
|
||||
|
||||
pub fn as_inner(&self) -> &passwd {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> passwd {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn belongs_to(&self) -> Vec<gid_t> {
|
||||
let mut ngroups: c_int = 8;
|
||||
let mut groups = Vec::with_capacity(ngroups as usize);
|
||||
let gid = self.inner.pw_gid;
|
||||
let name = self.inner.pw_name;
|
||||
unsafe {
|
||||
if getgrouplist(name, gid, groups.as_mut_ptr(), &mut ngroups) == -1 {
|
||||
groups.resize(ngroups as usize, 0);
|
||||
getgrouplist(name, gid, groups.as_mut_ptr(), &mut ngroups);
|
||||
}
|
||||
groups.set_len(ngroups as usize);
|
||||
}
|
||||
groups.truncate(ngroups as usize);
|
||||
groups
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Group {
|
||||
inner: group,
|
||||
}
|
||||
|
||||
impl Group {
|
||||
/// AKA group.gr_name
|
||||
pub fn name(&self) -> Cow<str> {
|
||||
cstr2cow!(self.inner.gr_name)
|
||||
}
|
||||
|
||||
/// AKA group.gr_gid
|
||||
pub fn gid(&self) -> gid_t {
|
||||
self.inner.gr_gid
|
||||
}
|
||||
|
||||
pub fn as_inner(&self) -> &group {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> group {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch desired entry.
|
||||
pub trait Locate<K> {
|
||||
fn locate(key: K) -> IOResult<Self>
|
||||
where
|
||||
Self: ::std::marker::Sized;
|
||||
}
|
||||
|
||||
macro_rules! f {
|
||||
($fnam:ident, $fid:ident, $t:ident, $st:ident) => (
|
||||
impl Locate<$t> for $st {
|
||||
fn locate(k: $t) -> IOResult<Self> {
|
||||
unsafe {
|
||||
let data = $fid(k);
|
||||
if !data.is_null() {
|
||||
Ok($st {
|
||||
inner: ptr::read(data as *const _)
|
||||
})
|
||||
} else {
|
||||
Err(IOError::new(ErrorKind::NotFound, format!("No such id: {}", k)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Locate<&'a str> for $st {
|
||||
fn locate(k: &'a str) -> IOResult<Self> {
|
||||
if let Ok(id) = k.parse::<$t>() {
|
||||
let data = unsafe { $fid(id) };
|
||||
if !data.is_null() {
|
||||
Ok($st {
|
||||
inner: unsafe {ptr::read(data as *const _)}
|
||||
})
|
||||
} else {
|
||||
Err(IOError::new(ErrorKind::NotFound, format!("No such id: {}", id)))
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
let data = $fnam(CString::new(k).unwrap().as_ptr());
|
||||
if !data.is_null() {
|
||||
Ok($st {
|
||||
inner: ptr::read(data as *const _)
|
||||
})
|
||||
} else {
|
||||
Err(IOError::new(ErrorKind::NotFound, format!("Not found: {}", k)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
f!(getpwnam, getpwuid, uid_t, Passwd);
|
||||
f!(getgrnam, getgrgid, gid_t, Group);
|
||||
|
||||
#[inline]
|
||||
pub fn uid2usr(id: uid_t) -> IOResult<String> {
|
||||
Passwd::locate(id).map(|p| p.name().into_owned())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gid2grp(id: gid_t) -> IOResult<String> {
|
||||
Group::locate(id).map(|p| p.name().into_owned())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn usr2uid(name: &str) -> IOResult<uid_t> {
|
||||
Passwd::locate(name).map(|p| p.uid())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn grp2gid(name: &str) -> IOResult<gid_t> {
|
||||
Group::locate(name).map(|p| p.gid())
|
||||
}
|
269
src/uucore/fs.rs
269
src/uucore/fs.rs
|
@ -1,269 +0,0 @@
|
|||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Joseph Crail <jbcrail@gmail.com>
|
||||
// (c) Jian Zeng <anonymousknight96 AT gmail.com>
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
extern crate termion;
|
||||
|
||||
#[cfg(unix)]
|
||||
use super::libc;
|
||||
#[cfg(unix)]
|
||||
use super::libc::{mode_t, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH,
|
||||
S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
#[cfg(target_os = "redox")]
|
||||
use std::io;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::io::Result as IOResult;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[cfg(unix)]
|
||||
macro_rules! has {
|
||||
($mode:expr, $perm:expr) => (
|
||||
$mode & ($perm as u32) != 0
|
||||
)
|
||||
}
|
||||
|
||||
pub fn resolve_relative_path(path: &Path) -> Cow<Path> {
|
||||
if path.components().all(|e| e != Component::ParentDir) {
|
||||
return path.into();
|
||||
}
|
||||
let root = Component::RootDir.as_os_str();
|
||||
let mut result = env::current_dir().unwrap_or(PathBuf::from(root));
|
||||
for comp in path.components() {
|
||||
match comp {
|
||||
Component::ParentDir => {
|
||||
if let Ok(p) = result.read_link() {
|
||||
result = p;
|
||||
}
|
||||
result.pop();
|
||||
}
|
||||
Component::CurDir => (),
|
||||
Component::RootDir | Component::Normal(_) | Component::Prefix(_) => {
|
||||
result.push(comp.as_os_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
result.into()
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum CanonicalizeMode {
|
||||
None,
|
||||
Normal,
|
||||
Existing,
|
||||
Missing,
|
||||
}
|
||||
|
||||
fn resolve<P: AsRef<Path>>(original: P) -> IOResult<PathBuf> {
|
||||
const MAX_LINKS_FOLLOWED: u32 = 255;
|
||||
let mut followed = 0;
|
||||
let mut result = original.as_ref().to_path_buf();
|
||||
loop {
|
||||
if followed == MAX_LINKS_FOLLOWED {
|
||||
return Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
"maximum links followed",
|
||||
));
|
||||
}
|
||||
|
||||
match fs::symlink_metadata(&result) {
|
||||
Err(e) => return Err(e),
|
||||
Ok(ref m) if !m.file_type().is_symlink() => break,
|
||||
Ok(..) => {
|
||||
followed += 1;
|
||||
match fs::read_link(&result) {
|
||||
Ok(path) => {
|
||||
result.pop();
|
||||
result.push(path);
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn canonicalize<P: AsRef<Path>>(original: P, can_mode: CanonicalizeMode) -> IOResult<PathBuf> {
|
||||
// Create an absolute path
|
||||
let original = original.as_ref();
|
||||
let original = if original.is_absolute() {
|
||||
original.to_path_buf()
|
||||
} else {
|
||||
env::current_dir().unwrap().join(original)
|
||||
};
|
||||
|
||||
let mut result = PathBuf::new();
|
||||
let mut parts = vec![];
|
||||
|
||||
// Split path by directory separator; add prefix (Windows-only) and root
|
||||
// directory to final path buffer; add remaining parts to temporary
|
||||
// vector for canonicalization.
|
||||
for part in original.components() {
|
||||
match part {
|
||||
Component::Prefix(_) | Component::RootDir => {
|
||||
result.push(part.as_os_str());
|
||||
}
|
||||
Component::CurDir => (),
|
||||
Component::ParentDir => {
|
||||
parts.pop();
|
||||
}
|
||||
Component::Normal(_) => {
|
||||
parts.push(part.as_os_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve the symlinks where possible
|
||||
if !parts.is_empty() {
|
||||
for part in parts[..parts.len() - 1].iter() {
|
||||
result.push(part);
|
||||
|
||||
if can_mode == CanonicalizeMode::None {
|
||||
continue;
|
||||
}
|
||||
|
||||
match resolve(&result) {
|
||||
Err(e) => match can_mode {
|
||||
CanonicalizeMode::Missing => continue,
|
||||
_ => return Err(e),
|
||||
},
|
||||
Ok(path) => {
|
||||
result.pop();
|
||||
result.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.push(parts.last().unwrap());
|
||||
|
||||
match resolve(&result) {
|
||||
Err(e) => {
|
||||
if can_mode == CanonicalizeMode::Existing {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
Ok(path) => {
|
||||
result.pop();
|
||||
result.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn is_stdin_interactive() -> bool {
|
||||
unsafe { libc::isatty(libc::STDIN_FILENO) == 1 }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn is_stdin_interactive() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
pub fn is_stdin_interactive() -> bool {
|
||||
termion::is_tty(&io::stdin())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn is_stdout_interactive() -> bool {
|
||||
unsafe { libc::isatty(libc::STDOUT_FILENO) == 1 }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn is_stdout_interactive() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
pub fn is_stdout_interactive() -> bool {
|
||||
termion::is_tty(&io::stdout())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn is_stderr_interactive() -> bool {
|
||||
unsafe { libc::isatty(libc::STDERR_FILENO) == 1 }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn is_stderr_interactive() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
pub fn is_stderr_interactive() -> bool {
|
||||
termion::is_tty(&io::stderr())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[allow(unused_variables)]
|
||||
pub fn display_permissions(metadata: &fs::Metadata) -> String {
|
||||
String::from("---------")
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn display_permissions(metadata: &fs::Metadata) -> String {
|
||||
let mode: mode_t = metadata.mode() as mode_t;
|
||||
display_permissions_unix(mode as u32)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn display_permissions_unix(mode: u32) -> String {
|
||||
let mut result = String::with_capacity(9);
|
||||
result.push(if has!(mode, S_IRUSR) { 'r' } else { '-' });
|
||||
result.push(if has!(mode, S_IWUSR) { 'w' } else { '-' });
|
||||
result.push(if has!(mode, S_ISUID) {
|
||||
if has!(mode, S_IXUSR) {
|
||||
's'
|
||||
} else {
|
||||
'S'
|
||||
}
|
||||
} else if has!(mode, S_IXUSR) {
|
||||
'x'
|
||||
} else {
|
||||
'-'
|
||||
});
|
||||
|
||||
result.push(if has!(mode, S_IRGRP) { 'r' } else { '-' });
|
||||
result.push(if has!(mode, S_IWGRP) { 'w' } else { '-' });
|
||||
result.push(if has!(mode, S_ISGID) {
|
||||
if has!(mode, S_IXGRP) {
|
||||
's'
|
||||
} else {
|
||||
'S'
|
||||
}
|
||||
} else if has!(mode, S_IXGRP) {
|
||||
'x'
|
||||
} else {
|
||||
'-'
|
||||
});
|
||||
|
||||
result.push(if has!(mode, S_IROTH) { 'r' } else { '-' });
|
||||
result.push(if has!(mode, S_IWOTH) { 'w' } else { '-' });
|
||||
result.push(if has!(mode, S_ISVTX) {
|
||||
if has!(mode, S_IXOTH) {
|
||||
't'
|
||||
} else {
|
||||
'T'
|
||||
}
|
||||
} else if has!(mode, S_IXOTH) {
|
||||
'x'
|
||||
} else {
|
||||
'-'
|
||||
});
|
||||
|
||||
result
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
extern crate wild;
|
||||
|
||||
pub fn args() -> impl Iterator<Item=String> {
|
||||
wild::args()
|
||||
}
|
||||
|
||||
#[cfg(feature = "libc")]
|
||||
pub extern crate libc;
|
||||
#[cfg(feature = "winapi")]
|
||||
pub extern crate winapi;
|
||||
#[cfg(feature = "failure")]
|
||||
extern crate failure;
|
||||
#[cfg(feature = "failure_derive")]
|
||||
#[macro_use]
|
||||
extern crate failure_derive;
|
||||
#[cfg(feature = "nix")]
|
||||
extern crate nix;
|
||||
#[cfg(all(feature = "lazy_static", target_os = "linux"))]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[cfg(feature = "platform-info")]
|
||||
extern crate platform_info;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
#[macro_use]
|
||||
pub mod coreopts;
|
||||
|
||||
pub mod panic;
|
||||
|
||||
#[cfg(feature = "fs")]
|
||||
pub mod fs;
|
||||
#[cfg(feature = "encoding")]
|
||||
pub mod encoding;
|
||||
#[cfg(feature = "parse_time")]
|
||||
pub mod parse_time;
|
||||
|
||||
#[cfg(all(not(windows), feature = "mode"))]
|
||||
pub mod mode;
|
||||
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))]
|
||||
pub mod utmpx;
|
||||
#[cfg(all(unix, feature = "entries"))]
|
||||
pub mod entries;
|
||||
#[cfg(all(unix, feature = "process"))]
|
||||
pub mod process;
|
||||
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
|
||||
pub mod signals;
|
||||
|
||||
#[cfg(feature = "zero-copy")]
|
||||
pub mod zero_copy;
|
||||
|
||||
#[cfg(all(windows, feature = "wide"))]
|
||||
pub mod wide;
|
|
@ -1,241 +0,0 @@
|
|||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Alex Lyon <arcterus@mail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! executable(
|
||||
() => ({
|
||||
let module = module_path!();
|
||||
let module = module.split("::").next().unwrap_or(module);
|
||||
if &module[0..3] == "uu_" {
|
||||
&module[3..]
|
||||
} else {
|
||||
module
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_error(
|
||||
($($args:tt)+) => ({
|
||||
eprint!("{}: error: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_warning(
|
||||
($($args:tt)+) => ({
|
||||
eprint!("{}: warning: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_info(
|
||||
($($args:tt)+) => ({
|
||||
eprint!("{}: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! disp_err(
|
||||
($($args:tt)+) => ({
|
||||
eprint!("{}: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
eprintln!("Try '{} --help' for more information.", executable!());
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! crash(
|
||||
($exitcode:expr, $($args:tt)+) => ({
|
||||
show_error!($($args)+);
|
||||
::std::process::exit($exitcode)
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! exit(
|
||||
($exitcode:expr) => ({
|
||||
::std::process::exit($exitcode)
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! crash_if_err(
|
||||
($exitcode:expr, $exp:expr) => (
|
||||
match $exp {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!($exitcode, "{}", f),
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! return_if_err(
|
||||
($exitcode:expr, $exp:expr) => (
|
||||
match $exp {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!("{}", f);
|
||||
return $exitcode;
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! safe_write(
|
||||
($fd:expr, $($args:tt)+) => (
|
||||
match write!($fd, $($args)+) {
|
||||
Ok(_) => {}
|
||||
Err(f) => panic!(f.to_string())
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! safe_writeln(
|
||||
($fd:expr, $($args:tt)+) => (
|
||||
match writeln!($fd, $($args)+) {
|
||||
Ok(_) => {}
|
||||
Err(f) => panic!(f.to_string())
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! safe_unwrap(
|
||||
($exp:expr) => (
|
||||
match $exp {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "{}", f.to_string())
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
//-- message templates
|
||||
|
||||
//-- message templates : general
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! snippet_list_join_oxford {
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr) => (
|
||||
format!("{}, {} {}", $valOne, $conjunction, $valTwo)
|
||||
);
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remainingVals:expr)*) => (
|
||||
format!("{}, {}", $valOne, snippet_list_join_inner!($conjunction, $valTwo $(, $remainingVals)*))
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! snippet_list_join_or {
|
||||
($valOne:expr, $valTwo:expr) => (
|
||||
format!("{} or {}", $valOne, $valTwo)
|
||||
);
|
||||
($valOne:expr, $valTwo:expr $(, $remainingVals:expr)*) => (
|
||||
format!("{}, {}", $valOne, snippet_list_join_oxford!("or", $valTwo $(, $remainingVals)*))
|
||||
);
|
||||
}
|
||||
|
||||
//-- message templates : invalid input
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_invalid_input { ($reason: expr) => (
|
||||
format!("invalid input: {}", $reason) ); }
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! snippet_no_file_at_path { ($path:expr) => (
|
||||
format!("nonexistent path {}", $path) ); }
|
||||
|
||||
// -- message templates : invalid input : flag
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_invalid_opt_use {
|
||||
($about:expr, $flag:expr) => (
|
||||
msg_invalid_input!(format!("The '{}' option {}", $flag, $about))
|
||||
);
|
||||
($about:expr, $longflag:expr, $shortflag:expr) => {
|
||||
msg_invalid_input!(format!("The '{}' ('{}') option {}", $longflag, $shortflag, $about))
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_opt_only_usable_if {
|
||||
($clause:expr, $flag:expr) => (
|
||||
msg_invalid_opt_use!(format!("only usable if {}", $clause), $flag)
|
||||
);
|
||||
($clause:expr, $longflag:expr, $shortflag:expr) => (
|
||||
msg_invalid_opt_use!(format!("only usable if {}", $clause), $longflag, $shortflag)
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_opt_invalid_should_be {
|
||||
($expects:expr, $received:expr, $flag:expr) => (
|
||||
msg_invalid_opt_use!(format!("expects {}, but was provided {}", $expects, $received), $flag)
|
||||
);
|
||||
($expects:expr, $received:expr, $longflag:expr, $shortflag:expr) => (
|
||||
msg_invalid_opt_use!(format!("expects {}, but was provided {}", $expects, $received), $longflag, $shortflag)
|
||||
);
|
||||
}
|
||||
|
||||
// -- message templates : invalid input : args
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_arg_invalid_value { ($expects:expr, $received:expr) => (
|
||||
msg_invalid_input!(format!("expects its argument to be {}, but was provided {}", $expects, $received)) ); }
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_args_invalid_value {
|
||||
($expects:expr, $received:expr) => (
|
||||
msg_invalid_input!(format!("expects its arguments to be {}, but was provided {}", $expects, $received))
|
||||
);
|
||||
($msg:expr) => (
|
||||
msg_invalid_input!($msg)
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_args_nonexistent_file { ($received:expr) => (
|
||||
msg_args_invalid_value!("paths to files", snippet_no_file_at_path!($received)));}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_wrong_number_of_arguments {
|
||||
() => (
|
||||
msg_args_invalid_value!("wrong number of arguments")
|
||||
);
|
||||
($min:expr, $max:expr) => (
|
||||
msg_args_invalid_value!(format!("expects {}-{} arguments", $min, $max))
|
||||
);
|
||||
($exact:expr) => (
|
||||
if $exact == 1 {
|
||||
msg_args_invalid_value!("expects 1 argument")
|
||||
} else {
|
||||
msg_args_invalid_value!(format!("expects {} arguments", $exact))
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// -- message templates : invalid input : input combinations
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_expects_one_of {
|
||||
($valOne:expr $(, $remainingVals:expr)*) => (
|
||||
msg_invalid_input!(format!("expects one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*)))
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_expects_no_more_than_one_of {
|
||||
($valOne:expr $(, $remainingVals:expr)*) => (
|
||||
msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*))) ;
|
||||
);
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Alex Lyon <arcterus@mail.com>
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
//
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
pub fn parse_numeric(fperm: u32, mut mode: &str) -> Result<u32, String> {
|
||||
let (op, pos) = parse_op(mode, Some('='))?;
|
||||
mode = mode[pos..].trim_start_matches('0');
|
||||
if mode.len() > 4 {
|
||||
Err(format!("mode is too large ({} > 7777)", mode))
|
||||
} else {
|
||||
match u32::from_str_radix(mode, 8) {
|
||||
Ok(change) => Ok(match op {
|
||||
'+' => fperm | change,
|
||||
'-' => fperm & !change,
|
||||
'=' => change,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
Err(err) => Err(err.description().to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_symbolic(
|
||||
mut fperm: u32,
|
||||
mut mode: &str,
|
||||
considering_dir: bool,
|
||||
) -> Result<u32, String> {
|
||||
#[cfg(unix)]
|
||||
use libc::umask;
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
unsafe fn umask(_mask: u32) -> u32 {
|
||||
// XXX Redox does not currently have umask
|
||||
0
|
||||
}
|
||||
|
||||
let (mask, pos) = parse_levels(mode);
|
||||
if pos == mode.len() {
|
||||
return Err(format!("invalid mode ({})", mode));
|
||||
}
|
||||
let respect_umask = pos == 0;
|
||||
let last_umask = unsafe { umask(0) };
|
||||
mode = &mode[pos..];
|
||||
while mode.len() > 0 {
|
||||
let (op, pos) = parse_op(mode, None)?;
|
||||
mode = &mode[pos..];
|
||||
let (mut srwx, pos) = parse_change(mode, fperm, considering_dir);
|
||||
if respect_umask {
|
||||
srwx &= !(last_umask as u32);
|
||||
}
|
||||
mode = &mode[pos..];
|
||||
match op {
|
||||
'+' => fperm |= srwx & mask,
|
||||
'-' => fperm &= !(srwx & mask),
|
||||
'=' => fperm = (fperm & !mask) | (srwx & mask),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
umask(last_umask);
|
||||
}
|
||||
Ok(fperm)
|
||||
}
|
||||
|
||||
fn parse_levels(mode: &str) -> (u32, usize) {
|
||||
let mut mask = 0;
|
||||
let mut pos = 0;
|
||||
for ch in mode.chars() {
|
||||
mask |= match ch {
|
||||
'u' => 0o7700,
|
||||
'g' => 0o7070,
|
||||
'o' => 0o7007,
|
||||
'a' => 0o7777,
|
||||
_ => break,
|
||||
};
|
||||
pos += 1;
|
||||
}
|
||||
if pos == 0 {
|
||||
mask = 0o7777; // default to 'a'
|
||||
}
|
||||
(mask, pos)
|
||||
}
|
||||
|
||||
fn parse_op(mode: &str, default: Option<char>) -> Result<(char, usize), String> {
|
||||
match mode.chars().next() {
|
||||
Some(ch) => match ch {
|
||||
'+' | '-' | '=' => Ok((ch, 1)),
|
||||
_ => match default {
|
||||
Some(ch) => Ok((ch, 0)),
|
||||
None => Err(format!(
|
||||
"invalid operator (expected +, -, or =, but found {})",
|
||||
ch
|
||||
)),
|
||||
},
|
||||
},
|
||||
None => Err("unexpected end of mode".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) {
|
||||
let mut srwx = fperm & 0o7000;
|
||||
let mut pos = 0;
|
||||
for ch in mode.chars() {
|
||||
match ch {
|
||||
'r' => srwx |= 0o444,
|
||||
'w' => srwx |= 0o222,
|
||||
'x' => srwx |= 0o111,
|
||||
'X' => {
|
||||
if considering_dir || (fperm & 0o0111) != 0 {
|
||||
srwx |= 0o111
|
||||
}
|
||||
}
|
||||
's' => srwx |= 0o4000 | 0o2000,
|
||||
't' => srwx |= 0o1000,
|
||||
'u' => srwx = (fperm & 0o700) | ((fperm >> 3) & 0o070) | ((fperm >> 6) & 0o007),
|
||||
'g' => srwx = ((fperm << 3) & 0o700) | (fperm & 0o070) | ((fperm >> 3) & 0o007),
|
||||
'o' => srwx = ((fperm << 6) & 0o700) | ((fperm << 3) & 0o070) | (fperm & 0o007),
|
||||
_ => break,
|
||||
};
|
||||
pos += 1;
|
||||
}
|
||||
if pos == 0 {
|
||||
srwx = 0;
|
||||
}
|
||||
(srwx, pos)
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue