Merge branch 'master' into expr-regex

This commit is contained in:
Ian Douglas Scott
2017-10-01 10:06:28 -07:00
100 changed files with 2193 additions and 814 deletions
Generated
+147 -106
View File
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -238,17 +238,17 @@ whoami = { optional=true, path="src/whoami" }
yes = { optional=true, path="src/yes" }
[dev-dependencies]
time = "*"
filetime = "*"
libc = "*"
regex="*"
rand="*"
tempdir="*"
unindent="*"
lazy_static = "*"
time = "0.1.38"
filetime = "0.1.10"
libc = "0.2.26"
regex = "0.2.2"
rand = "0.3.15"
tempdir = "0.3.5"
unindent = "0.1.0"
lazy_static = "0.2.2"
[target.'cfg(unix)'.dev-dependencies]
unix_socket = "*"
unix_socket = "0.5.0"
[[bin]]
name = "uutils"
+90 -103
View File
@@ -4,6 +4,7 @@ uutils coreutils
[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/uutils/coreutils/blob/master/LICENSE)
[![Build Status](https://api.travis-ci.org/uutils/coreutils.svg?branch=master)](https://travis-ci.org/uutils/coreutils)
[![Build status](https://ci.appveyor.com/api/projects/status/787ltcxgy86r20le?svg=true)](https://ci.appveyor.com/project/Arcterus/coreutils)
[![LOC](https://tokei.rs/b1/github/uutils/coreutils?category=code)](https://github.com/Aaronepower/tokei)
uutils is an attempt at writing universal (as in cross-platform) CLI
utils in [Rust](http://www.rust-lang.org). This repo is to aggregate the GNU
@@ -144,110 +145,96 @@ Contribute
To contribute to coreutils, please see [CONTRIBUTING](CONTRIBUTING.md).
To do
-----
Utilities
---------
* [x] arch
* [x] base32
* [x] base64
* [x] basename
* [x] cat
* [ ] chcon
* [x] chgrp
* [x] chmod
* [x] chown
* [x] chroot
* [x] cksum
* [x] comm
* [ ] cp (not much done)
* [ ] csplit
* [x] cut
* [ ] date
* [ ] dd
* [ ] df
* [x] dircolors
* [x] dirname
* [x] du
* [x] echo
* [x] env
* [x] expand
* [x] expr
* [x] factor
* [x] false
* [x] fmt
* [x] fold
* [x] groups
* [x] hashsum
* [x] head
* [x] hostid
* [x] hostname
* [x] id
* [ ] install (a couple of missing options)
* [ ] join
* [x] kill
* [x] link
* [x] ln
* [x] logname
* [ ] ls
* [x] ~~md5sum~~, ~~sha1sum~~, ~~sha224sum~~, ~~sha256sum~~, ~~sha384sum~~, ~~sha512sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs))
* [x] mkdir
* [x] mkfifo
* [x] mknod
* [x] mktemp
* [x] mv
* [ ] more (in progress, needs lots of work)
* [x] nice
* [x] nl
* [x] nohup
* [x] nproc
* [ ] numfmt
* [ ] od (almost complete, `--strings` and 128-bit datatypes are missing)
* [x] paste
* [x] pathchk
* [x] pinky
* [ ] pr
* [x] printenv
* [ ] printf
* [x] ptx
* [x] pwd
* [x] readlink
* [x] realpath
* [x] relpath
* [x] rm
* [x] rmdir
* [ ] runcon
* [x] seq
* [x] shred
* [x] shuf
* [x] sleep
* [ ] sort (a couple of options implemented)
* [ ] split (a couple of missing options)
* [x] stat
* [x] stdbuf
* [ ] stty
* [x] sum
* [x] sync
* [x] tac
* [ ] tail (not all features implemented)
* [x] tee
* [ ] test (not all features implemented)
* [x] timeout
* [x] touch
* [x] tr
* [x] true
* [x] truncate
* [x] tsort
* [x] tty
* [x] uname
* [x] unexpand
* [x] uniq
* [x] unlink
* [x] uptime
* [x] users
* [x] wc
* [x] who
* [x] whoami
* [x] yes
| Done | Semi-Done | To Do |
|-----------|-----------|--------|
| arch | cp | chcon |
| base32 | expr | csplit |
| base64 | install | dd |
| basename | ls | df |
| cat | more | join |
| chgrp | od (`--strings` and 128-bit data types missing) | numfmt |
| chmod | printf | pr |
| chown | sort | runcon |
| chroot | split | stty |
| cksum | tail | |
| comm | test | |
| cut | date | |
| dircolors | | |
| dirname | | |
| du | | |
| echo | | |
| env | | |
| expand | | |
| factor | | |
| false | | |
| fmt | | |
| fold | | |
| groups | | |
| hashsum | | |
| head | | |
| hostid | | |
| hostname | | |
| id | | |
| kill | | |
| link | | |
| ln | | |
| logname | | |
| ~~md5sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| ~~sha1sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| ~~sha224sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| ~~sha256sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| ~~sha384sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| ~~sha512sum~~ (replaced by [hashsum](https://github.com/uutils/coreutils/blob/master/src/hashsum/hashsum.rs)) | |
| mkdir | | |
| mkfifo | | |
| mknod | | |
| mktemp | | |
| mv | | |
| nice | | |
| nl | | |
| nohup | | |
| nproc | | |
| paste | | |
| pathchk | | |
| pinky | | |
| printenv | | |
| ptx | | |
| pwd | | |
| readlink | | |
| realpath | | |
| relpath | | |
| rm | | |
| rmdir | | |
| seq | | |
| shred | | |
| shuf | | |
| sleep | | |
| stat | | |
| stdbuf | | |
| sum | | |
| sync | | |
| tac | | |
| tee | | |
| timeout | | |
| touch | | |
| tr | | |
| true | | |
| truncate | | |
| tsort | | |
| tty | | |
| uname | | |
| unexpand | | |
| uniq | | |
| unlink | | |
| uptime | | |
| users | | |
| wc | | |
| who | | |
| whoami | | |
| yes | | |
License
-------
+1 -1
View File
@@ -11,7 +11,7 @@ path = "base32.rs"
uucore = { path="../uucore" }
[dependencies.clippy]
version = "*"
version = "0.0.143"
optional = true
[[bin]]
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_chgrp"
path = "chgrp.rs"
[dependencies]
walkdir = "*"
walkdir = "1.0.7"
[dependencies.uucore]
path = "../uucore"
+2 -2
View File
@@ -8,9 +8,9 @@ name = "uu_chmod"
path = "chmod.rs"
[dependencies]
libc = "*"
libc = "0.2.26"
uucore = { path="../uucore" }
walker = "*"
walker = "1.0.0"
[[bin]]
name = "chmod"
+46 -45
View File
@@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
#[cfg(unix)]
extern crate libc;
extern crate walker;
@@ -16,9 +17,9 @@ extern crate walker;
extern crate uucore;
use std::error::Error;
use std::ffi::CString;
use std::io::{self, Write};
use std::mem;
use std::fs;
use std::io::Write;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::Path;
use walker::Walker;
@@ -74,16 +75,10 @@ pub fn uumain(mut args: Vec<String>) -> i32 {
let verbose = matches.opt_present("verbose");
let preserve_root = matches.opt_present("preserve-root");
let recursive = matches.opt_present("recursive");
let fmode = matches.opt_str("reference").and_then(|fref| {
let s = CString::new(fref).unwrap_or_else( |_| {
crash!(1, "reference file name contains internal nul byte")
});
let mut stat : libc::stat = unsafe { mem::uninitialized() };
let statres = unsafe { libc::stat(s.as_ptr() as *const _, &mut stat as *mut libc::stat) };
if statres == 0 {
Some(stat.st_mode)
} else {
crash!(1, "cannot stat attribues of '{}': {}", matches.opt_str("reference").unwrap(), io::Error::last_os_error())
let fmode = matches.opt_str("reference").and_then(|ref fref| {
match fs::metadata(fref) {
Ok(meta) => Some(meta.mode()),
Err(err) => crash!(1, "cannot stat attribues of '{}': {}", fref, err)
}
});
let cmode =
@@ -108,7 +103,7 @@ pub fn uumain(mut args: Vec<String>) -> i32 {
0
}
fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), i32> {
fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option<u32>, cmode: Option<&String>) -> Result<(), i32> {
let mut r = Ok(());
for filename in &files {
@@ -157,28 +152,25 @@ fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve
}
#[cfg(windows)]
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), i32> {
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<u32>, cmode: Option<&String>) -> Result<(), i32> {
// chmod is useless on Windows
// it doesn't set any permissions at all
// instead it just sets the readonly attribute on the file
Err(0)
}
#[cfg(unix)]
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), i32> {
let path = CString::new(name).unwrap_or_else(|e| panic!("{}", e));
let mut stat: libc::stat = unsafe { mem::uninitialized() };
let statres = unsafe { libc::stat(path.as_ptr(), &mut stat as *mut libc::stat) };
let mut fperm =
if statres == 0 {
stat.st_mode & 0o7777
} else {
#[cfg(any(unix, target_os = "redox"))]
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<u32>, cmode: Option<&String>) -> Result<(), i32> {
let mut fperm = match fs::metadata(name) {
Ok(meta) => meta.mode() & 0o7777,
Err(err) => {
if !quiet {
show_error!("{}", io::Error::last_os_error());
show_error!("{}", err);
}
return Err(1);
};
}
};
match fmode {
Some(mode) => try!(change_file(fperm, mode, file, &path, verbose, changes, quiet)),
Some(mode) => try!(change_file(fperm, mode, file, name, verbose, changes, quiet)),
None => {
for mode in cmode.unwrap().split(',') { // cmode is guaranteed to be Some in this case
let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
@@ -190,7 +182,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
};
match result {
Ok(mode) => {
try!(change_file(fperm, mode, file, &path, verbose, changes, quiet));
try!(change_file(fperm, mode, file, name, verbose, changes, quiet));
fperm = mode;
}
Err(f) => {
@@ -207,13 +199,13 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
Ok(())
}
fn parse_numeric(fperm: libc::mode_t, mut mode: &str) -> Result<libc::mode_t, String> {
fn parse_numeric(fperm: u32, mut mode: &str) -> Result<u32, String> {
let (op, pos) = try!(parse_op(mode, Some('=')));
mode = mode[pos..].trim_left_matches('0');
if mode.len() > 4 {
Err(format!("mode is too large ({} > 7777)", mode))
} else {
match libc::mode_t::from_str_radix(mode, 8) {
match u32::from_str_radix(mode, 8) {
Ok(change) => {
Ok(match op {
'+' => fperm | change,
@@ -227,14 +219,23 @@ fn parse_numeric(fperm: libc::mode_t, mut mode: &str) -> Result<libc::mode_t, St
}
}
fn parse_symbolic(mut fperm: libc::mode_t, mut mode: &str, file: &Path) -> Result<libc::mode_t, String> {
fn parse_symbolic(mut fperm: u32, mut mode: &str, file: &Path) -> 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 {
libc::umask(0)
umask(0)
};
mode = &mode[pos..];
while mode.len() > 0 {
@@ -242,7 +243,7 @@ fn parse_symbolic(mut fperm: libc::mode_t, mut mode: &str, file: &Path) -> Resul
mode = &mode[pos..];
let (mut srwx, pos) = parse_change(mode, fperm, file);
if respect_umask {
srwx &= !last_umask;
srwx &= !(last_umask as u32);
}
mode = &mode[pos..];
match op {
@@ -253,12 +254,12 @@ fn parse_symbolic(mut fperm: libc::mode_t, mut mode: &str, file: &Path) -> Resul
}
}
unsafe {
libc::umask(last_umask);
umask(last_umask);
}
Ok(fperm)
}
fn parse_levels(mode: &str) -> (libc::mode_t, usize) {
fn parse_levels(mode: &str) -> (u32, usize) {
let mut mask = 0;
let mut pos = 0;
for ch in mode.chars() {
@@ -290,7 +291,7 @@ fn parse_op(mode: &str, default: Option<char>) -> Result<(char, usize), String>
}
}
fn parse_change(mode: &str, fperm: libc::mode_t, file: &Path) -> (libc::mode_t, usize) {
fn parse_change(mode: &str, fperm: u32, file: &Path) -> (u32, usize) {
let mut srwx = fperm & 0o7000;
let mut pos = 0;
for ch in mode.chars() {
@@ -318,24 +319,24 @@ fn parse_change(mode: &str, fperm: libc::mode_t, file: &Path) -> (libc::mode_t,
(srwx, pos)
}
fn change_file(fperm: libc::mode_t, mode: libc::mode_t, file: &Path, path: &CString, verbose: bool, changes: bool, quiet: bool) -> Result<(), i32> {
fn change_file(fperm: u32, mode: u32, file: &Path, path: &str, verbose: bool, changes: bool, quiet: bool) -> Result<(), i32> {
if fperm == mode {
if verbose && !changes {
show_info!("mode of '{}' retained as {:o}", file.display(), fperm);
}
Ok(())
} else if unsafe { libc::chmod(path.as_ptr(), mode) } == 0 {
if verbose || changes {
show_info!("mode of '{}' changed from {:o} to {:o}", file.display(), fperm, mode);
}
Ok(())
} else {
} else if let Err(err) = fs::set_permissions(Path::new(path), fs::Permissions::from_mode(mode)) {
if !quiet {
show_error!("{}", io::Error::last_os_error());
show_error!("{}", err);
}
if verbose {
show_info!("failed to change mode of file '{}' from {:o} to {:o}", file.display(), fperm, mode);
}
return Err(1);
Err(1)
} else {
if verbose || changes {
show_info!("mode of '{}' changed from {:o} to {:o}", file.display(), fperm, mode);
}
Ok(())
}
}
+2 -2
View File
@@ -8,7 +8,7 @@ name = "uu_chown"
path = "chown.rs"
[dependencies]
glob = "*"
glob = "0.2.11"
walkdir = "0.1"
[dependencies.uucore]
@@ -17,7 +17,7 @@ default-features = false
features = ["entries", "fs"]
[dependencies.clippy]
version = "*"
version = "0.0.143"
optional = true
[[bin]]
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_chroot"
path = "chroot.rs"
[dependencies]
getopts = "*"
getopts = "0.2.14"
[dependencies.uucore]
path = "../uucore"
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_cksum"
path = "cksum.rs"
[dependencies]
libc = "*"
libc = "0.2.26"
uucore = { path="../uucore" }
[[bin]]
+2 -2
View File
@@ -8,8 +8,8 @@ name = "uu_comm"
path = "comm.rs"
[dependencies]
libc = "*"
getopts = "*"
libc = "0.2.26"
getopts = "0.2.14"
uucore = { path="../uucore" }
[[bin]]
+20 -3
View File
@@ -1,16 +1,33 @@
[package]
name = "cp"
version = "0.0.1"
authors = []
authors = [
"Jordy Dickinson <jordy.dickinson@gmail.com>",
"Joshua S. Miller <jsmiller@uchicago.edu>",
]
[lib]
name = "uu_cp"
path = "cp.rs"
[dependencies]
getopts = "*"
libc = "*"
getopts = "0.2.14"
libc = "0.2.26"
walkdir = "1.0.7"
clap = "2.20.0"
quick-error = "1.1.0"
uucore = { path="../uucore" }
filetime = "0.1"
[target.'cfg(target_os = "linux")'.dependencies]
ioctl-sys = "0.5.2"
[target.'cfg(target_os = "windows")'.dependencies]
kernel32-sys = "*"
winapi = "*"
[target.'cfg(unix)'.dependencies]
xattr="0.2.1"
[[bin]]
name = "cp"
+38
View File
@@ -0,0 +1,38 @@
## Feature list
### To Do
- [ ] archive
- [ ] attributes-only
- [ ] copy-contents
- [ ] no-dereference-preserve-linkgs
- [ ] dereference
- [ ] no-dereference
- [ ] preserve-default-attributes
- [ ] preserve
- [ ] no-preserve
- [ ] parents
- [ ] reflink
- [ ] sparse
- [ ] strip-trailing-slashes
- [ ] update
- [ ] one-file-system
- [ ] context
- [ ] cli-symbolic-links
### Completed
- [x] backup
- [x] force (Not implemented on Windows)
- [x] interactive
- [x] link
- [x] no-clobber
- [x] no-target-directory
- [x] paths
- [x] recursive
- [x] remove-destination (On Windows, current only works for writeable files)
- [x] suffix
- [x] symbolic-link
- [x] target-directory
- [x] verbose
- [x] version
+1082 -135
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -8,8 +8,8 @@ name = "uu_date"
path = "date.rs"
[dependencies]
chrono = "0.4"
clap = "2.25"
chrono = "0.4.0"
clap = "2.24.1"
uucore = { path="../uucore" }
[[bin]]
+1 -1
View File
@@ -1,4 +1,4 @@
extern crate uu_echo;
extern crate uu_date;
fn main() {
std::process::exit(uu_date::uumain(std::env::args().collect()));
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_dircolors"
path = "dircolors.rs"
[dependencies]
glob = "*"
glob = "0.2.11"
uucore = { path="../uucore" }
[[bin]]
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_dirname"
path = "dirname.rs"
[dependencies]
libc = "*"
libc = "0.2.26"
uucore = { path="../uucore" }
[[bin]]
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_du"
path = "du.rs"
[dependencies]
time = "*"
time = "0.1.38"
uucore = { path="../uucore" }
[[bin]]
+1 -1
View File
@@ -8,7 +8,7 @@ name = "uu_env"
path = "env.rs"
[dependencies]
libc = "*"
libc = "0.2.26"
uucore = { path="../uucore" }
[[bin]]

Some files were not shown because too many files have changed in this diff Show More