1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

Merge pull request #668 from jbcrail/stabilize

Backport and/or replace unstable features.
This commit is contained in:
Michael Gehring 2015-07-31 22:47:18 +02:00
commit 9fcd6e617b
20 changed files with 218 additions and 137 deletions

1
deps/Cargo.toml vendored
View file

@ -20,3 +20,4 @@ unicode-width = "0.1.1"
winapi = "0.2" winapi = "0.2"
advapi32-sys = "0.1" advapi32-sys = "0.1"
kernel32-sys = "0.1" kernel32-sys = "0.1"
walker = "^1.0.0"

View file

@ -1,5 +1,4 @@
#![crate_name = "chmod"] #![crate_name = "chmod"]
#![feature(fs_walk, path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -18,19 +17,25 @@ extern crate libc;
extern crate memchr; extern crate memchr;
extern crate regex; extern crate regex;
extern crate regex_syntax; extern crate regex_syntax;
extern crate walker;
use getopts::Options; use getopts::Options;
use regex::Regex; use regex::Regex;
use std::ffi::CString; use std::ffi::CString;
use std::fs::{self, PathExt};
use std::io::{Error, Write}; use std::io::{Error, Write};
use std::mem; use std::mem;
use std::path::Path; use std::path::Path;
use walker::Walker;
#[path = "../common/util.rs"] #[path = "../common/util.rs"]
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
const NAME: &'static str = "chmod"; const NAME: &'static str = "chmod";
const VERSION: &'static str = "1.0.0"; const VERSION: &'static str = "1.0.0";
@ -149,11 +154,11 @@ fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve
for filename in files.iter() { for filename in files.iter() {
let filename = &filename[..]; let filename = &filename[..];
let file = Path::new(filename); let file = Path::new(filename);
if file.exists() { if file.uu_exists() {
if file.is_dir() { if file.uu_is_dir() {
if !preserve_root || filename != "/" { if !preserve_root || filename != "/" {
if recursive { if recursive {
let walk_dir = match fs::walk_dir(&file) { let walk_dir = match Walker::new(&file) {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
crash!(1, "{}", f.to_string()); crash!(1, "{}", f.to_string());
@ -273,7 +278,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
'w' => rwx |= 0o002, 'w' => rwx |= 0o002,
'x' => rwx |= 0o001, 'x' => rwx |= 0o001,
'X' => { 'X' => {
if file.is_dir() || (fperm & 0o0111) != 0 { if file.uu_is_dir() || (fperm & 0o0111) != 0 {
rwx |= 0o001; rwx |= 0o001;
} }
} }

View file

@ -1 +1 @@
DEPLIBS += aho-corasick memchr regex regex-syntax DEPLIBS += aho-corasick memchr regex regex-syntax walker

View file

@ -1,5 +1,4 @@
#![crate_name = "chroot"] #![crate_name = "chroot"]
#![feature(path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -17,7 +16,6 @@ use c_types::{get_pw_from_args, get_group};
use getopts::Options; use getopts::Options;
use libc::funcs::posix88::unistd::{setgid, setuid}; use libc::funcs::posix88::unistd::{setgid, setuid};
use std::ffi::CString; use std::ffi::CString;
use std::fs::PathExt;
use std::io::{Error, Write}; use std::io::{Error, Write};
use std::iter::FromIterator; use std::iter::FromIterator;
use std::path::Path; use std::path::Path;
@ -25,6 +23,9 @@ use std::process::Command;
#[path = "../common/util.rs"] #[macro_use] mod util; #[path = "../common/util.rs"] #[macro_use] mod util;
#[path = "../common/c_types.rs"] mod c_types; #[path = "../common/c_types.rs"] mod c_types;
#[path = "../common/filesystem.rs"] mod filesystem;
use filesystem::UUPathExt;
extern { extern {
fn chroot(path: *const libc::c_char) -> libc::c_int; fn chroot(path: *const libc::c_char) -> libc::c_int;
@ -78,7 +79,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
let user_shell = std::env::var("SHELL"); let user_shell = std::env::var("SHELL");
let newroot = Path::new(&matches.free[0][..]); let newroot = Path::new(&matches.free[0][..]);
if !newroot.is_dir() { if !newroot.uu_is_dir() {
crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display()); crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display());
} }

42
src/common/filesystem.rs Normal file
View file

@ -0,0 +1,42 @@
/*
* This file is part of the uutils coreutils package.
*
* (c) Joseph Crail <jbcrail@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Based on the pattern using by Cargo, I created a shim over the
// standard PathExt trait, so that the unstable path methods could
// be backported to stable (<= 1.1). This will likely be dropped
// when the path trait stabilizes.
use std::fs;
use std::io;
use std::path::Path;
pub trait UUPathExt {
fn uu_exists(&self) -> bool;
fn uu_is_file(&self) -> bool;
fn uu_is_dir(&self) -> bool;
fn uu_metadata(&self) -> io::Result<fs::Metadata>;
}
impl UUPathExt for Path {
fn uu_exists(&self) -> bool {
fs::metadata(self).is_ok()
}
fn uu_is_file(&self) -> bool {
fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)
}
fn uu_is_dir(&self) -> bool {
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
}
fn uu_metadata(&self) -> io::Result<fs::Metadata> {
fs::metadata(self)
}
}

View file

@ -1,5 +1,5 @@
#![crate_name = "cp"] #![crate_name = "cp"]
#![feature(path_ext)] #![feature(fs_canonicalize)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -13,7 +13,7 @@
extern crate getopts; extern crate getopts;
use getopts::Options; use getopts::Options;
use std::fs::{self, PathExt}; use std::fs;
use std::io::{ErrorKind, Result, Write}; use std::io::{ErrorKind, Result, Write};
use std::path::Path; use std::path::Path;
@ -21,6 +21,11 @@ use std::path::Path;
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
pub enum Mode { pub enum Mode {
Copy, Copy,
@ -119,7 +124,7 @@ fn copy(matches: getopts::Matches) {
panic!(); panic!();
} }
} else { } else {
if !fs::metadata(dest).unwrap().is_dir() { if !dest.uu_is_dir() {
show_error!("TARGET must be a directory"); show_error!("TARGET must be a directory");
panic!(); panic!();
} }
@ -127,7 +132,7 @@ fn copy(matches: getopts::Matches) {
for src in sources.iter() { for src in sources.iter() {
let source = Path::new(&src); let source = Path::new(&src);
if !fs::metadata(source).unwrap().is_file() { if !source.uu_is_file() {
show_error!("\"{}\" is not a file", source.display()); show_error!("\"{}\" is not a file", source.display());
continue; continue;
} }
@ -150,8 +155,8 @@ fn copy(matches: getopts::Matches) {
pub fn paths_refer_to_same_file(p1: &Path, p2: &Path) -> Result<bool> { pub fn paths_refer_to_same_file(p1: &Path, p2: &Path) -> Result<bool> {
// We have to take symlinks and relative paths into account. // We have to take symlinks and relative paths into account.
let pathbuf1 = try!(p1.canonicalize()); let pathbuf1 = try!(fs::canonicalize(p1));
let pathbuf2 = try!(p2.canonicalize()); let pathbuf2 = try!(fs::canonicalize(p2));
Ok(pathbuf1 == pathbuf2) Ok(pathbuf1 == pathbuf2)
} }

View file

@ -1,5 +1,4 @@
#![crate_name = "cut"] #![crate_name = "cut"]
#![feature(path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -13,7 +12,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::fs::{File, PathExt}; use std::fs::File;
use std::io::{stdout, stdin, BufRead, BufReader, Read, Stdout, Write}; use std::io::{stdout, stdin, BufRead, BufReader, Read, Stdout, Write};
use std::path::Path; use std::path::Path;
@ -23,6 +22,12 @@ use searcher::Searcher;
#[path = "../common/util.rs"] #[path = "../common/util.rs"]
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
mod buffer; mod buffer;
mod ranges; mod ranges;
mod searcher; mod searcher;
@ -379,7 +384,7 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> i32 {
} else { } else {
let path = Path::new(&filename[..]); let path = Path::new(&filename[..]);
if ! path.exists() { if !path.uu_exists() {
show_error!("{}: No such file or directory", filename); show_error!("{}: No such file or directory", filename);
continue continue
} }

View file

@ -11,7 +11,6 @@
*/ */
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![allow(deprecated)]
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;

View file

@ -1,5 +1,5 @@
#![crate_name = "ln"] #![crate_name = "ln"]
#![feature(path_ext, slice_patterns, str_char)] #![feature(slice_patterns, str_char)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -12,7 +12,7 @@
extern crate getopts; extern crate getopts;
use std::fs::{self, PathExt}; use std::fs;
use std::io::{BufRead, BufReader, Result, stdin, Write}; use std::io::{BufRead, BufReader, Result, stdin, Write};
#[cfg(unix)] use std::os::unix::fs::symlink as symlink_file; #[cfg(unix)] use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)] use std::os::windows::fs::symlink_file; #[cfg(windows)] use std::os::windows::fs::symlink_file;
@ -22,6 +22,11 @@ use std::path::{Path, PathBuf};
#[macro_use] #[macro_use]
mod util; mod util;
#[path="../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "ln"; static NAME: &'static str = "ln";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
@ -201,7 +206,7 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 {
} }
fn link_files_in_dir(files: &[PathBuf], target_dir: &PathBuf, settings: &Settings) -> i32 { fn link_files_in_dir(files: &[PathBuf], target_dir: &PathBuf, settings: &Settings) -> i32 {
if !target_dir.is_dir() { if !target_dir.uu_is_dir() {
show_error!("target '{}' is not a directory", target_dir.display()); show_error!("target '{}' is not a directory", target_dir.display());
return 1; return 1;
} }
@ -233,13 +238,13 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &PathBuf, settings: &Setting
fn link(src: &PathBuf, dst: &PathBuf, settings: &Settings) -> Result<()> { fn link(src: &PathBuf, dst: &PathBuf, settings: &Settings) -> Result<()> {
let mut backup_path = None; let mut backup_path = None;
if dst.is_dir() { if dst.uu_is_dir() {
if settings.no_target_dir { if settings.no_target_dir {
try!(fs::remove_dir(dst)); try!(fs::remove_dir(dst));
} }
} }
if is_symlink(dst) || dst.exists() { if is_symlink(dst) || dst.uu_exists() {
match settings.overwrite { match settings.overwrite {
OverwriteMode::NoClobber => {}, OverwriteMode::NoClobber => {},
OverwriteMode::Interactive => { OverwriteMode::Interactive => {
@ -302,7 +307,7 @@ fn numbered_backup_path(path: &PathBuf) -> PathBuf {
let mut i: u64 = 1; let mut i: u64 = 1;
loop { loop {
let new_path = simple_backup_path(path, &format!(".~{}~", i)); let new_path = simple_backup_path(path, &format!(".~{}~", i));
if !new_path.exists() { if !new_path.uu_exists() {
return new_path; return new_path;
} }
i += 1; i += 1;
@ -311,7 +316,7 @@ fn numbered_backup_path(path: &PathBuf) -> PathBuf {
fn existing_backup_path(path: &PathBuf, suffix: &String) -> PathBuf { fn existing_backup_path(path: &PathBuf, suffix: &String) -> PathBuf {
let test_path = simple_backup_path(path, &".~1~".to_string()); let test_path = simple_backup_path(path, &".~1~".to_string());
if test_path.exists() { if test_path.uu_exists() {
return numbered_backup_path(path); return numbered_backup_path(path);
} }
simple_backup_path(path, suffix) simple_backup_path(path, suffix)

View file

@ -1,5 +1,4 @@
#![crate_name = "mkdir"] #![crate_name = "mkdir"]
#![feature(path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -14,7 +13,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::CString; use std::ffi::CString;
use std::fs::{self, PathExt}; use std::fs;
use std::io::{Error, Write}; use std::io::{Error, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -22,6 +21,11 @@ use std::path::{Path, PathBuf};
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "mkdir"; static NAME: &'static str = "mkdir";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
@ -102,7 +106,7 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
} else { } else {
match path.parent() { match path.parent() {
Some(parent) => { Some(parent) => {
if parent != empty && !parent.exists() { if parent != empty && !parent.uu_exists() {
show_info!("cannot create directory '{}': No such file or directory", path.display()); show_info!("cannot create directory '{}': No such file or directory", path.display());
status = 1; status = 1;
} else { } else {
@ -122,7 +126,7 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
* Wrapper to catch errors, return 1 if failed * Wrapper to catch errors, return 1 if failed
*/ */
fn mkdir(path: &Path, mode: u16, verbose: bool) -> i32 { fn mkdir(path: &Path, mode: u16, verbose: bool) -> i32 {
if path.exists() { if path.uu_exists() {
show_info!("cannot create directory '{}': File exists", path.display()); show_info!("cannot create directory '{}': File exists", path.display());
return 1; return 1;
} }

View file

@ -1,6 +1,5 @@
#![crate_name = "mv"] #![crate_name = "mv"]
#![feature(path_ext, slice_extras, slice_patterns, str_char)] #![feature(slice_patterns, str_char)]
#![allow(deprecated)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -15,7 +14,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::fs::{self, PathExt}; use std::fs;
use std::io::{BufRead, BufReader, Result, stdin, Write}; use std::io::{BufRead, BufReader, Result, stdin, Write};
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -24,6 +23,11 @@ use std::path::{Path, PathBuf};
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "mv"; static NAME: &'static str = "mv";
static VERSION: &'static str = "0.0.1"; static VERSION: &'static str = "0.0.1";
@ -195,14 +199,14 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 {
return 1; return 1;
}, },
[ref source, ref target] => { [ref source, ref target] => {
if !source.exists() { if !source.uu_exists() {
show_error!("cannot stat {}: No such file or directory", source.display()); show_error!("cannot stat {}: No such file or directory", source.display());
return 1; return 1;
} }
if target.is_dir() { if target.uu_is_dir() {
if b.no_target_dir { if b.no_target_dir {
if !source.is_dir() { if !source.uu_is_dir() {
show_error!("cannot overwrite directory {} with non-directory", show_error!("cannot overwrite directory {} with non-directory",
target.display()); target.display());
return 1; return 1;
@ -235,14 +239,14 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 {
return 1; return 1;
} }
let target_dir = fs.last().unwrap(); let target_dir = fs.last().unwrap();
move_files_into_dir(fs.init(), target_dir, &b); move_files_into_dir(&fs[0..fs.len()-1], target_dir, &b);
} }
} }
0 0
} }
fn move_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behaviour) -> i32 { fn move_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behaviour) -> i32 {
if !target_dir.is_dir() { if !target_dir.uu_is_dir() {
show_error!("target {} is not a directory", target_dir.display()); show_error!("target {} is not a directory", target_dir.display());
return 1; return 1;
} }
@ -275,7 +279,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behaviour) -
fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> { fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> {
let mut backup_path = None; let mut backup_path = None;
if to.exists() { if to.uu_exists() {
match b.overwrite { match b.overwrite {
OverwriteMode::NoClobber => return Ok(()), OverwriteMode::NoClobber => return Ok(()),
OverwriteMode::Interactive => { OverwriteMode::Interactive => {
@ -337,7 +341,7 @@ fn numbered_backup_path(path: &PathBuf) -> PathBuf {
let mut i: u64 = 1; let mut i: u64 = 1;
loop { loop {
let new_path = simple_backup_path(path, &format!(".~{}~", i)); let new_path = simple_backup_path(path, &format!(".~{}~", i));
if !new_path.exists() { if !new_path.uu_exists() {
return new_path; return new_path;
} }
i = i + 1; i = i + 1;
@ -346,7 +350,7 @@ fn numbered_backup_path(path: &PathBuf) -> PathBuf {
fn existing_backup_path(path: &PathBuf, suffix: &String) -> PathBuf { fn existing_backup_path(path: &PathBuf, suffix: &String) -> PathBuf {
let test_path = simple_backup_path(path, &".~1~".to_string()); let test_path = simple_backup_path(path, &".~1~".to_string());
if test_path.exists() { if test_path.uu_exists() {
return numbered_backup_path(path); return numbered_backup_path(path);
} }
simple_backup_path(path, suffix) simple_backup_path(path, suffix)

View file

@ -1,5 +1,5 @@
#![crate_name= "realpath"] #![crate_name= "realpath"]
#![feature(path_ext)] #![feature(fs_canonicalize)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -13,7 +13,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::fs::PathExt; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -63,7 +63,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool { fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
let p = Path::new(path).to_path_buf(); let p = Path::new(path).to_path_buf();
let abs = p.canonicalize().unwrap(); let abs = fs::canonicalize(p).unwrap();
if strip { if strip {
if zero { if zero {
@ -84,12 +84,12 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
if !quiet { show_error!("Too many symbolic links: {}", path) }; if !quiet { show_error!("Too many symbolic links: {}", path) };
return false return false
} }
match result.as_path().metadata() { match fs::metadata(result.as_path()) {
Err(_) => break, Err(_) => break,
Ok(ref m) if !m.file_type().is_symlink() => break, Ok(ref m) if !m.file_type().is_symlink() => break,
Ok(_) => { Ok(_) => {
links_left -= 1; links_left -= 1;
match result.as_path().read_link() { match fs::read_link(result.as_path()) {
Ok(x) => { Ok(x) => {
result.pop(); result.pop();
result.push(x.as_path()); result.push(x.as_path());

View file

@ -1,5 +1,5 @@
#![crate_name = "relpath"] #![crate_name = "relpath"]
#![feature(path_ext)] #![feature(fs_canonicalize)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -14,7 +14,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::env; use std::env;
use std::fs::PathExt; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -54,12 +54,12 @@ pub fn uumain(args: Vec<String>) -> i32 {
} else { } else {
env::current_dir().unwrap() env::current_dir().unwrap()
}; };
let absto = to.canonicalize().unwrap(); let absto = fs::canonicalize(to).unwrap();
let absfrom = from.canonicalize().unwrap(); let absfrom = fs::canonicalize(from).unwrap();
if matches.opt_present("d") { if matches.opt_present("d") {
let base = Path::new(&matches.opt_str("d").unwrap()).to_path_buf(); let base = Path::new(&matches.opt_str("d").unwrap()).to_path_buf();
let absbase = base.canonicalize().unwrap(); let absbase = fs::canonicalize(base).unwrap();
if !absto.as_path().starts_with(absbase.as_path()) || !absfrom.as_path().starts_with(absbase.as_path()) { if !absto.as_path().starts_with(absbase.as_path()) || !absfrom.as_path().starts_with(absbase.as_path()) {
println!("{}", absto.display()); println!("{}", absto.display());
return 0 return 0

View file

@ -1,5 +1,4 @@
#![crate_name = "rm"] #![crate_name = "rm"]
#![feature(path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -14,7 +13,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fs::{self, PathExt}; use std::fs;
use std::io::{stdin, stderr, BufRead, Write}; use std::io::{stdin, stderr, BufRead, Write};
use std::ops::BitOr; use std::ops::BitOr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -23,6 +22,11 @@ use std::path::{Path, PathBuf};
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
#[derive(Eq, PartialEq, Clone, Copy)] #[derive(Eq, PartialEq, Clone, Copy)]
enum InteractiveMode { enum InteractiveMode {
InteractiveNone, InteractiveNone,
@ -131,8 +135,8 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
for filename in files.iter() { for filename in files.iter() {
let filename = &filename[..]; let filename = &filename[..];
let file = Path::new(filename); let file = Path::new(filename);
if file.exists() { if file.uu_exists() {
if file.is_dir() { if file.uu_is_dir() {
if recursive && (filename != "/" || !preserve_root) { if recursive && (filename != "/" || !preserve_root) {
if interactive != InteractiveMode::InteractiveAlways { if interactive != InteractiveMode::InteractiveAlways {
match fs::remove_dir_all(file) { match fs::remove_dir_all(file) {

View file

@ -1,5 +1,5 @@
#![crate_name = "stdbuf"] #![crate_name = "stdbuf"]
#![feature(negate_unsigned, path_ext)] #![feature(fs_canonicalize, negate_unsigned)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -15,7 +15,7 @@ extern crate libc;
use getopts::{Matches, Options}; use getopts::{Matches, Options};
use std::env; use std::env;
use std::fs::PathExt; use std::fs;
use std::io::{self, Write}; use std::io::{self, Write};
use std::os::unix::process::ExitStatusExt; use std::os::unix::process::ExitStatusExt;
use std::path::PathBuf; use std::path::PathBuf;
@ -25,6 +25,11 @@ use std::process::Command;
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "stdbuf"; static NAME: &'static str = "stdbuf";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
static LIBSTDBUF: &'static str = "libstdbuf"; static LIBSTDBUF: &'static str = "libstdbuf";
@ -190,7 +195,7 @@ fn set_command_env(command: &mut Command, buffer_name: &str, buffer_type: Buffer
fn exe_path() -> io::Result<PathBuf> { fn exe_path() -> io::Result<PathBuf> {
let exe_path = try!(env::current_exe()); let exe_path = try!(env::current_exe());
let absolute_path = try!(exe_path.as_path().canonicalize()); let absolute_path = try!(fs::canonicalize(exe_path.as_path()));
Ok(match absolute_path.parent() { Ok(match absolute_path.parent() {
Some(p) => p.to_path_buf(), Some(p) => p.to_path_buf(),
None => absolute_path.clone() None => absolute_path.clone()
@ -204,7 +209,7 @@ fn get_preload_env() -> (String, String) {
// First search for library in directory of executable. // First search for library in directory of executable.
let mut path = exe_path().unwrap_or_else(|_| crash!(1, "Impossible to fetch the path of this executable.")); let mut path = exe_path().unwrap_or_else(|_| crash!(1, "Impossible to fetch the path of this executable."));
path.push(libstdbuf.clone()); path.push(libstdbuf.clone());
if path.exists() { if path.uu_exists() {
match path.as_os_str().to_str() { match path.as_os_str().to_str() {
Some(s) => { return (preload.to_string(), s.to_string()); }, Some(s) => { return (preload.to_string(), s.to_string()); },
None => crash!(1, "Error while converting path.") None => crash!(1, "Error while converting path.")

View file

@ -1,5 +1,5 @@
#![crate_name = "touch"] #![crate_name = "touch"]
#![feature(fs_time, path_ext)] #![feature(fs_time)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -18,7 +18,7 @@ use libc::types::os::arch::c95::c_char;
use libc::types::os::arch::posix01::stat as stat_t; use libc::types::os::arch::posix01::stat as stat_t;
use libc::funcs::posix88::stat_::stat as c_stat; use libc::funcs::posix88::stat_::stat as c_stat;
use libc::funcs::posix01::stat_::lstat as c_lstat; use libc::funcs::posix01::stat_::lstat as c_lstat;
use std::fs::{set_file_times, File, PathExt}; use std::fs::{set_file_times, File};
use std::io::{Error, Write}; use std::io::{Error, Write};
use std::mem::uninitialized; use std::mem::uninitialized;
use std::path::Path; use std::path::Path;
@ -27,6 +27,11 @@ use std::path::Path;
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "touch"; static NAME: &'static str = "touch";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
@ -95,7 +100,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
for filename in matches.free.iter() { for filename in matches.free.iter() {
let path = &filename[..]; let path = &filename[..];
if ! Path::new(path).exists() { if !Path::new(path).uu_exists() {
// no-dereference included here for compatibility // no-dereference included here for compatibility
if matches.opts_present(&["no-create".to_string(), "no-dereference".to_string()]) { if matches.opts_present(&["no-create".to_string(), "no-dereference".to_string()]) {
continue; continue;

View file

@ -1,5 +1,4 @@
#![crate_name = "wc"] #![crate_name = "wc"]
#![feature(path_ext)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -15,7 +14,7 @@ extern crate libc;
use getopts::{Matches, Options}; use getopts::{Matches, Options};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::fs::{File, PathExt}; use std::fs::File;
use std::io::{stdin, BufRead, BufReader, Read, Write}; use std::io::{stdin, BufRead, BufReader, Read, Write};
use std::path::Path; use std::path::Path;
use std::result::Result as StdResult; use std::result::Result as StdResult;
@ -25,6 +24,11 @@ use std::str::from_utf8;
#[macro_use] #[macro_use]
mod util; mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
struct Settings { struct Settings {
show_bytes: bool, show_bytes: bool,
show_chars: bool, show_chars: bool,
@ -264,7 +268,7 @@ fn open(path: &str) -> StdResult<BufReader<Box<Read+'static>>, i32> {
} }
let fpath = Path::new(path); let fpath = Path::new(path);
if fpath.is_dir() { if fpath.uu_is_dir() {
show_info!("{}: is a directory", path); show_info!("{}: is a directory", path);
} }
match File::open(&fpath) { match File::open(&fpath) {

View file

@ -1,9 +1,9 @@
#![feature(fs_time, path_ext)] #![feature(fs_time)]
extern crate libc; extern crate libc;
extern crate time; extern crate time;
use std::fs::{self, PathExt}; use std::fs;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use util::*; use util::*;
@ -25,7 +25,7 @@ fn test_mv_rename_dir() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(dir2).is_dir()); assert!(dir_exists(dir2));
} }
#[test] #[test]
@ -39,7 +39,7 @@ fn test_mv_rename_file() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(file2).is_file()); assert!(file_exists(file2));
} }
#[test] #[test]
@ -54,7 +54,7 @@ fn test_mv_move_file_into_dir() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(&format!("{}/{}", dir, file)).is_file()); assert!(file_exists(&format!("{}/{}", dir, file)));
} }
#[test] #[test]
@ -70,13 +70,13 @@ fn test_mv_strip_slashes() {
let result = run(Command::new(PROGNAME).arg(&source).arg(dir)); let result = run(Command::new(PROGNAME).arg(&source).arg(dir));
assert!(!result.success); assert!(!result.success);
assert!(!Path::new(&format!("{}/{}", dir, file)).is_file()); assert!(!file_exists(&format!("{}/{}", dir, file)));
let result = run(Command::new(PROGNAME).arg("--strip-trailing-slashes").arg(source).arg(dir)); let result = run(Command::new(PROGNAME).arg("--strip-trailing-slashes").arg(source).arg(dir));
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(&format!("{}/{}", dir, file)).is_file()); assert!(file_exists(&format!("{}/{}", dir, file)));
} }
#[test] #[test]
@ -93,8 +93,8 @@ fn test_mv_multiple_files() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(&format!("{}/{}", target_dir, file_a)).is_file()); assert!(file_exists(&format!("{}/{}", target_dir, file_a)));
assert!(Path::new(&format!("{}/{}", target_dir, file_b)).is_file()); assert!(file_exists(&format!("{}/{}", target_dir, file_b)));
} }
#[test] #[test]
@ -111,8 +111,8 @@ fn test_mv_multiple_folders() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(&format!("{}/{}", target_dir, dir_a)).is_dir()); assert!(dir_exists(&format!("{}/{}", target_dir, dir_a)));
assert!(Path::new(&format!("{}/{}", target_dir, dir_b)).is_dir()); assert!(dir_exists(&format!("{}/{}", target_dir, dir_b)));
} }
#[test] #[test]
@ -129,8 +129,8 @@ fn test_mv_interactive() {
assert_empty_stderr!(result1); assert_empty_stderr!(result1);
assert!(result1.success); assert!(result1.success);
assert!(Path::new(file_a).is_file()); assert!(file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
let result2 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"Yesh"); let result2 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"Yesh");
@ -138,8 +138,8 @@ fn test_mv_interactive() {
assert_empty_stderr!(result2); assert_empty_stderr!(result2);
assert!(result2.success); assert!(result2.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
} }
#[test] #[test]
@ -154,8 +154,8 @@ fn test_mv_no_clobber() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(Path::new(file_a).is_file()); assert!(file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
} }
#[test] #[test]
@ -170,8 +170,8 @@ fn test_mv_replace_file() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
} }
#[test] #[test]
@ -186,8 +186,8 @@ fn test_mv_force_replace_file() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
} }
#[test] #[test]
@ -202,9 +202,9 @@ fn test_mv_simple_backup() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
assert!(Path::new(&format!("{}~", file_b)).is_file()); assert!(file_exists(&format!("{}~", file_b)));
} }
#[test] #[test]
@ -222,9 +222,9 @@ fn test_mv_custom_backup_suffix() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
assert!(Path::new(&format!("{}{}", file_b, suffix)).is_file()); assert!(file_exists(&format!("{}{}", file_b, suffix)));
} }
#[test] #[test]
@ -239,9 +239,9 @@ fn test_mv_backup_numbering() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
assert!(Path::new(&format!("{}.~1~", file_b)).is_file()); assert!(file_exists(&format!("{}.~1~", file_b)));
} }
#[test] #[test]
@ -259,10 +259,10 @@ fn test_mv_existing_backup() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
assert!(Path::new(file_b_backup).is_file()); assert!(file_exists(file_b_backup));
assert!(Path::new(resulting_backup).is_file()); assert!(file_exists(resulting_backup));
} }
#[test] #[test]
@ -281,16 +281,16 @@ fn test_mv_update_option() {
assert_empty_stderr!(result1); assert_empty_stderr!(result1);
assert!(result1.success); assert!(result1.success);
assert!(Path::new(file_a).is_file()); assert!(file_exists(file_a));
assert!(Path::new(file_b).is_file()); assert!(file_exists(file_b));
let result2 = run(Command::new(PROGNAME).arg("--update").arg(file_b).arg(file_a)); let result2 = run(Command::new(PROGNAME).arg("--update").arg(file_b).arg(file_a));
assert_empty_stderr!(result2); assert_empty_stderr!(result2);
assert!(result2.success); assert!(result2.success);
assert!(Path::new(file_a).is_file()); assert!(file_exists(file_a));
assert!(!Path::new(file_b).is_file()); assert!(!file_exists(file_b));
} }
#[test] #[test]
@ -307,10 +307,10 @@ fn test_mv_target_dir() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).is_file()); assert!(!file_exists(file_a));
assert!(!Path::new(file_b).is_file()); assert!(!file_exists(file_b));
assert!(Path::new(&format!("{}/{}", dir, file_a)).is_file()); assert!(file_exists(&format!("{}/{}", dir, file_a)));
assert!(Path::new(&format!("{}/{}", dir, file_b)).is_file()); assert!(file_exists(&format!("{}/{}", dir, file_b)));
} }
#[test] #[test]
@ -325,8 +325,8 @@ fn test_mv_overwrite_dir() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(dir_a).is_dir()); assert!(!dir_exists(dir_a));
assert!(Path::new(dir_b).is_dir()); assert!(dir_exists(dir_b));
} }
#[test] #[test]
@ -350,8 +350,8 @@ fn test_mv_overwrite_nonempty_dir() {
assert!(result.stdout.len() == 0); assert!(result.stdout.len() == 0);
assert!(!result.success); assert!(!result.success);
assert!(Path::new(dir_a).is_dir()); assert!(dir_exists(dir_a));
assert!(Path::new(dir_b).is_dir()); assert!(dir_exists(dir_b));
} }
#[test] #[test]
@ -368,9 +368,9 @@ fn test_mv_backup_dir() {
format!("{} -> {} (backup: {}~)\n", dir_a, dir_b, dir_b)); format!("{} -> {} (backup: {}~)\n", dir_a, dir_b, dir_b));
assert!(result.success); assert!(result.success);
assert!(!Path::new(dir_a).is_dir()); assert!(!dir_exists(dir_a));
assert!(Path::new(dir_b).is_dir()); assert!(dir_exists(dir_b));
assert!(Path::new(&format!("{}~", dir_b)).is_dir()); assert!(dir_exists(&format!("{}~", dir_b)));
} }
#[test] #[test]

View file

@ -1,9 +1,5 @@
#![feature(path_ext)]
extern crate libc; extern crate libc;
use std::fs::PathExt;
use std::path::Path;
use std::process::Command; use std::process::Command;
use util::*; use util::*;
@ -23,7 +19,7 @@ fn test_rm_one_file() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file).exists()); assert!(!file_exists(file));
} }
#[test] #[test]
@ -38,8 +34,8 @@ fn test_rm_multiple_files() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).exists()); assert!(!file_exists(file_a));
assert!(!Path::new(file_b).exists()); assert!(!file_exists(file_b));
} }
#[test] #[test]
@ -54,15 +50,15 @@ fn test_rm_interactive() {
assert!(result1.success); assert!(result1.success);
assert!(Path::new(file_a).exists()); assert!(file_exists(file_a));
assert!(Path::new(file_b).exists()); assert!(file_exists(file_b));
let result2 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"Yesh"); let result2 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"Yesh");
assert!(result2.success); assert!(result2.success);
assert!(!Path::new(file_a).exists()); assert!(!file_exists(file_a));
assert!(Path::new(file_b).exists()); assert!(file_exists(file_b));
} }
#[test] #[test]
@ -74,8 +70,8 @@ fn test_rm_force() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file_a).exists()); assert!(!file_exists(file_a));
assert!(!Path::new(file_b).exists()); assert!(!file_exists(file_b));
} }
#[test] #[test]
@ -88,7 +84,7 @@ fn test_rm_empty_directory() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(dir).exists()); assert!(!dir_exists(dir));
} }
#[test] #[test]
@ -105,9 +101,9 @@ fn test_rm_recursive() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(dir).exists()); assert!(!dir_exists(dir));
assert!(!Path::new(file_a).exists()); assert!(!file_exists(file_a));
assert!(!Path::new(file_b).exists()); assert!(!file_exists(file_b));
} }
#[test] #[test]

View file

@ -1,9 +1,5 @@
#![feature(path_ext)]
extern crate libc; extern crate libc;
use std::fs::PathExt;
use std::path::Path;
use std::process::Command; use std::process::Command;
use util::*; use util::*;
@ -23,7 +19,7 @@ fn test_unlink_file() {
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert!(!Path::new(file).exists()); assert!(!file_exists(file));
} }
#[test] #[test]