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

Stabilize several PathExt methods.

This commit is contained in:
Joseph Crail 2015-07-31 13:59:05 -04:00
parent 8f6503383c
commit f03b22a65c
16 changed files with 200 additions and 118 deletions

View file

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

View file

@ -1,5 +1,4 @@
#![crate_name = "chroot"]
#![feature(path_ext)]
/*
* 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 libc::funcs::posix88::unistd::{setgid, setuid};
use std::ffi::CString;
use std::fs::PathExt;
use std::io::{Error, Write};
use std::iter::FromIterator;
use std::path::Path;
@ -25,6 +23,9 @@ use std::process::Command;
#[path = "../common/util.rs"] #[macro_use] mod util;
#[path = "../common/c_types.rs"] mod c_types;
#[path = "../common/filesystem.rs"] mod filesystem;
use filesystem::UUPathExt;
extern {
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 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());
}

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

@ -13,7 +13,7 @@
extern crate getopts;
use getopts::Options;
use std::fs::{self, PathExt};
use std::fs;
use std::io::{ErrorKind, Result, Write};
use std::path::Path;
@ -21,6 +21,11 @@ use std::path::Path;
#[macro_use]
mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
#[derive(Clone, Eq, PartialEq)]
pub enum Mode {
Copy,
@ -119,7 +124,7 @@ fn copy(matches: getopts::Matches) {
panic!();
}
} else {
if !fs::metadata(dest).unwrap().is_dir() {
if !dest.uu_is_dir() {
show_error!("TARGET must be a directory");
panic!();
}
@ -127,7 +132,7 @@ fn copy(matches: getopts::Matches) {
for src in sources.iter() {
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());
continue;
}

View file

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

View file

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

View file

@ -1,5 +1,4 @@
#![crate_name = "mkdir"]
#![feature(path_ext)]
/*
* This file is part of the uutils coreutils package.
@ -14,7 +13,7 @@ extern crate getopts;
extern crate libc;
use std::ffi::CString;
use std::fs::{self, PathExt};
use std::fs;
use std::io::{Error, Write};
use std::path::{Path, PathBuf};
@ -22,6 +21,11 @@ use std::path::{Path, PathBuf};
#[macro_use]
mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "mkdir";
static VERSION: &'static str = "1.0.0";
@ -102,7 +106,7 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
} else {
match path.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());
status = 1;
} 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
*/
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());
return 1;
}

View file

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

View file

@ -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) };
return false
}
match result.as_path().metadata() {
match fs::metadata(result.as_path()) {
Err(_) => break,
Ok(ref m) if !m.file_type().is_symlink() => break,
Ok(_) => {
links_left -= 1;
match result.as_path().read_link() {
match fs::read_link(result.as_path()) {
Ok(x) => {
result.pop();
result.push(x.as_path());

View file

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

View file

@ -25,6 +25,11 @@ use std::process::Command;
#[macro_use]
mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "stdbuf";
static VERSION: &'static str = "1.0.0";
static LIBSTDBUF: &'static str = "libstdbuf";
@ -204,7 +209,7 @@ fn get_preload_env() -> (String, String) {
// 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."));
path.push(libstdbuf.clone());
if path.exists() {
if path.uu_exists() {
match path.as_os_str().to_str() {
Some(s) => { return (preload.to_string(), s.to_string()); },
None => crash!(1, "Error while converting path.")

View file

@ -1,5 +1,5 @@
#![crate_name = "touch"]
#![feature(fs_time, path_ext)]
#![feature(fs_time)]
/*
* 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::funcs::posix88::stat_::stat as c_stat;
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::mem::uninitialized;
use std::path::Path;
@ -27,6 +27,11 @@ use std::path::Path;
#[macro_use]
mod util;
#[path = "../common/filesystem.rs"]
mod filesystem;
use filesystem::UUPathExt;
static NAME: &'static str = "touch";
static VERSION: &'static str = "1.0.0";
@ -95,7 +100,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
for filename in matches.free.iter() {
let path = &filename[..];
if ! Path::new(path).exists() {
if !Path::new(path).uu_exists() {
// no-dereference included here for compatibility
if matches.opts_present(&["no-create".to_string(), "no-dereference".to_string()]) {
continue;

View file

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

View file

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

View file

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

View file

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