use clone::Clone;
use io::standard_error;
-use io::{FilePermission, Write, Open, FileAccess, FileMode};
+use io::{FilePermission, Write, Open, FileAccess, FileMode, FileType};
use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
use io::{Read, Truncate, ReadWrite, Append};
use io::UpdateIoError;
match result {
Err(mkdir_err) => {
// already exists ?
- if try!(stat(&curpath)).kind != io::TypeDirectory {
+ if try!(stat(&curpath)).kind != FileType::Directory {
return Err(mkdir_err);
}
}
false => try!(update_err(lstat(&child), path))
};
- if child_type.kind == io::TypeDirectory {
+ if child_type.kind == FileType::Directory {
rm_stack.push(child);
has_child_dir = true;
} else {
}
fn is_file(&self) -> bool {
match self.stat() {
- Ok(s) => s.kind == io::TypeFile,
+ Ok(s) => s.kind == FileType::RegularFile,
Err(..) => false
}
}
fn is_dir(&self) -> bool {
match self.stat() {
- Ok(s) => s.kind == io::TypeDirectory,
+ Ok(s) => s.kind == FileType::Directory,
Err(..) => false
}
}
#[allow(unused_mut)]
mod test {
use prelude::*;
- use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite};
+ use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType};
use io;
use str;
use io::fs::*;
fs.write(msg.as_bytes()).unwrap();
let fstat_res = check!(fs.stat());
- assert_eq!(fstat_res.kind, io::TypeFile);
+ assert_eq!(fstat_res.kind, FileType::RegularFile);
}
let stat_res_fn = check!(stat(filename));
- assert_eq!(stat_res_fn.kind, io::TypeFile);
+ assert_eq!(stat_res_fn.kind, FileType::RegularFile);
let stat_res_meth = check!(filename.stat());
- assert_eq!(stat_res_meth.kind, io::TypeFile);
+ assert_eq!(stat_res_meth.kind, FileType::RegularFile);
check!(unlink(filename));
}
let filename = &tmpdir.join("file_stat_correct_on_is_dir");
check!(mkdir(filename, io::USER_RWX));
let stat_res_fn = check!(stat(filename));
- assert!(stat_res_fn.kind == io::TypeDirectory);
+ assert!(stat_res_fn.kind == FileType::Directory);
let stat_res_meth = check!(filename.stat());
- assert!(stat_res_meth.kind == io::TypeDirectory);
+ assert!(stat_res_meth.kind == FileType::Directory);
check!(rmdir(filename));
}
check!(File::create(&input).write("foobar".as_bytes()));
check!(symlink(&input, &out));
if cfg!(not(windows)) {
- assert_eq!(check!(lstat(&out)).kind, io::TypeSymlink);
- assert_eq!(check!(out.lstat()).kind, io::TypeSymlink);
+ assert_eq!(check!(lstat(&out)).kind, FileType::Symlink);
+ assert_eq!(check!(out.lstat()).kind, FileType::Symlink);
}
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
assert_eq!(check!(File::open(&out).read_to_end()),
check!(File::create(&input).write("foobar".as_bytes()));
check!(link(&input, &out));
if cfg!(not(windows)) {
- assert_eq!(check!(lstat(&out)).kind, io::TypeFile);
- assert_eq!(check!(out.lstat()).kind, io::TypeFile);
+ assert_eq!(check!(lstat(&out)).kind, FileType::RegularFile);
+ assert_eq!(check!(out.lstat()).kind, FileType::RegularFile);
assert_eq!(check!(stat(&out)).unstable.nlink, 2);
assert_eq!(check!(out.stat()).unstable.nlink, 2);
}
pub use self::SeekStyle::*;
pub use self::FileMode::*;
pub use self::FileAccess::*;
-pub use self::FileType::*;
pub use self::IoErrorKind::*;
use char::Char;
#[deriving(PartialEq, Show, Hash, Clone)]
pub enum FileType {
/// This is a normal file, corresponding to `S_IFREG`
- TypeFile,
+ RegularFile,
/// This file is a directory, corresponding to `S_IFDIR`
- TypeDirectory,
+ Directory,
/// This file is a named pipe, corresponding to `S_IFIFO`
- TypeNamedPipe,
+ NamedPipe,
/// This file is a block device, corresponding to `S_IFBLK`
- TypeBlockSpecial,
+ BlockSpecial,
/// This file is a symbolic link to another file, corresponding to `S_IFLNK`
- TypeSymlink,
+ Symlink,
/// The type of this file is not recognized as one of the other categories
- TypeUnknown,
+ Unknown,
}
/// A structure used to describe metadata information about a file. This
FileStat {
size: stat.st_size as u64,
kind: match (stat.st_mode as libc::mode_t) & libc::S_IFMT {
- libc::S_IFREG => io::TypeFile,
- libc::S_IFDIR => io::TypeDirectory,
- libc::S_IFIFO => io::TypeNamedPipe,
- libc::S_IFBLK => io::TypeBlockSpecial,
- libc::S_IFLNK => io::TypeSymlink,
- _ => io::TypeUnknown,
+ libc::S_IFREG => io::FileType::RegularFile,
+ libc::S_IFDIR => io::FileType::Directory,
+ libc::S_IFIFO => io::FileType::NamedPipe,
+ libc::S_IFBLK => io::FileType::BlockSpecial,
+ libc::S_IFLNK => io::FileType::Symlink,
+ _ => io::FileType::Unknown,
},
perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64),
FileStat {
size: stat.st_size as u64,
kind: match (stat.st_mode as libc::c_int) & libc::S_IFMT {
- libc::S_IFREG => io::TypeFile,
- libc::S_IFDIR => io::TypeDirectory,
- libc::S_IFIFO => io::TypeNamedPipe,
- libc::S_IFBLK => io::TypeBlockSpecial,
- libc::S_IFLNK => io::TypeSymlink,
- _ => io::TypeUnknown,
+ libc::S_IFREG => io::FileType::RegularFile,
+ libc::S_IFDIR => io::FileType::Directory,
+ libc::S_IFIFO => io::FileType::NamedPipe,
+ libc::S_IFBLK => io::FileType::BlockSpecial,
+ libc::S_IFLNK => io::FileType::Symlink,
+ _ => io::FileType::Unknown,
},
perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
created: stat.st_ctime as u64,