Skip to content

Commit 3649c2a

Browse files
committed
rollup merge of rust-lang#19273: ogham/rename-file-types
All of the enum components had a redundant 'Type' specifier: TypeSymlink, TypeDirectory, TypeFile. This change removes them, replacing them with a namespace: FileType::Symlink, FileType::Directory, and FileType::RegularFile. RegularFile is used instead of just File, as File by itself could be mistakenly thought of as referring to the struct. Part of rust-lang#19253.
2 parents 52d4526 + 3b9dfd6 commit 3649c2a

File tree

6 files changed

+35
-36
lines changed

6 files changed

+35
-36
lines changed

src/librustc_back/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn realpath(original: &Path) -> io::IoResult<Path> {
3737

3838
match fs::lstat(&result) {
3939
Err(..) => break,
40-
Ok(ref stat) if stat.kind != io::TypeSymlink => break,
40+
Ok(ref stat) if stat.kind != io::FileType::Symlink => break,
4141
Ok(..) => {
4242
followed += 1;
4343
let path = try!(fs::readlink(&result));

src/libstd/io/fs.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fs::unlink(&path);
5454

5555
use clone::Clone;
5656
use io::standard_error;
57-
use io::{FilePermission, Write, Open, FileAccess, FileMode};
57+
use io::{FilePermission, Write, Open, FileAccess, FileMode, FileType};
5858
use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
5959
use io::{Read, Truncate, ReadWrite, Append};
6060
use io::UpdateIoError;
@@ -592,7 +592,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> {
592592
match result {
593593
Err(mkdir_err) => {
594594
// already exists ?
595-
if try!(stat(&curpath)).kind != io::TypeDirectory {
595+
if try!(stat(&curpath)).kind != FileType::Directory {
596596
return Err(mkdir_err);
597597
}
598598
}
@@ -638,7 +638,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> {
638638
false => try!(update_err(lstat(&child), path))
639639
};
640640

641-
if child_type.kind == io::TypeDirectory {
641+
if child_type.kind == FileType::Directory {
642642
rm_stack.push(child);
643643
has_child_dir = true;
644644
} else {
@@ -772,13 +772,13 @@ impl PathExtensions for path::Path {
772772
}
773773
fn is_file(&self) -> bool {
774774
match self.stat() {
775-
Ok(s) => s.kind == io::TypeFile,
775+
Ok(s) => s.kind == FileType::RegularFile,
776776
Err(..) => false
777777
}
778778
}
779779
fn is_dir(&self) -> bool {
780780
match self.stat() {
781-
Ok(s) => s.kind == io::TypeDirectory,
781+
Ok(s) => s.kind == FileType::Directory,
782782
Err(..) => false
783783
}
784784
}
@@ -806,7 +806,7 @@ fn access_string(access: FileAccess) -> &'static str {
806806
#[allow(unused_mut)]
807807
mod test {
808808
use prelude::*;
809-
use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite};
809+
use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType};
810810
use io;
811811
use str;
812812
use io::fs::*;
@@ -1028,12 +1028,12 @@ mod test {
10281028
fs.write(msg.as_bytes()).unwrap();
10291029

10301030
let fstat_res = check!(fs.stat());
1031-
assert_eq!(fstat_res.kind, io::TypeFile);
1031+
assert_eq!(fstat_res.kind, FileType::RegularFile);
10321032
}
10331033
let stat_res_fn = check!(stat(filename));
1034-
assert_eq!(stat_res_fn.kind, io::TypeFile);
1034+
assert_eq!(stat_res_fn.kind, FileType::RegularFile);
10351035
let stat_res_meth = check!(filename.stat());
1036-
assert_eq!(stat_res_meth.kind, io::TypeFile);
1036+
assert_eq!(stat_res_meth.kind, FileType::RegularFile);
10371037
check!(unlink(filename));
10381038
}
10391039

@@ -1043,9 +1043,9 @@ mod test {
10431043
let filename = &tmpdir.join("file_stat_correct_on_is_dir");
10441044
check!(mkdir(filename, io::USER_RWX));
10451045
let stat_res_fn = check!(stat(filename));
1046-
assert!(stat_res_fn.kind == io::TypeDirectory);
1046+
assert!(stat_res_fn.kind == FileType::Directory);
10471047
let stat_res_meth = check!(filename.stat());
1048-
assert!(stat_res_meth.kind == io::TypeDirectory);
1048+
assert!(stat_res_meth.kind == FileType::Directory);
10491049
check!(rmdir(filename));
10501050
}
10511051

@@ -1315,8 +1315,8 @@ mod test {
13151315
check!(File::create(&input).write("foobar".as_bytes()));
13161316
check!(symlink(&input, &out));
13171317
if cfg!(not(windows)) {
1318-
assert_eq!(check!(lstat(&out)).kind, io::TypeSymlink);
1319-
assert_eq!(check!(out.lstat()).kind, io::TypeSymlink);
1318+
assert_eq!(check!(lstat(&out)).kind, FileType::Symlink);
1319+
assert_eq!(check!(out.lstat()).kind, FileType::Symlink);
13201320
}
13211321
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
13221322
assert_eq!(check!(File::open(&out).read_to_end()),
@@ -1350,8 +1350,8 @@ mod test {
13501350
check!(File::create(&input).write("foobar".as_bytes()));
13511351
check!(link(&input, &out));
13521352
if cfg!(not(windows)) {
1353-
assert_eq!(check!(lstat(&out)).kind, io::TypeFile);
1354-
assert_eq!(check!(out.lstat()).kind, io::TypeFile);
1353+
assert_eq!(check!(lstat(&out)).kind, FileType::RegularFile);
1354+
assert_eq!(check!(out.lstat()).kind, FileType::RegularFile);
13551355
assert_eq!(check!(stat(&out)).unstable.nlink, 2);
13561356
assert_eq!(check!(out.stat()).unstable.nlink, 2);
13571357
}

src/libstd/io/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ responding to errors that may occur while attempting to read the numbers.
224224
pub use self::SeekStyle::*;
225225
pub use self::FileMode::*;
226226
pub use self::FileAccess::*;
227-
pub use self::FileType::*;
228227
pub use self::IoErrorKind::*;
229228

230229
use char::Char;
@@ -1698,22 +1697,22 @@ pub enum FileAccess {
16981697
#[deriving(PartialEq, Show, Hash, Clone)]
16991698
pub enum FileType {
17001699
/// This is a normal file, corresponding to `S_IFREG`
1701-
TypeFile,
1700+
RegularFile,
17021701

17031702
/// This file is a directory, corresponding to `S_IFDIR`
1704-
TypeDirectory,
1703+
Directory,
17051704

17061705
/// This file is a named pipe, corresponding to `S_IFIFO`
1707-
TypeNamedPipe,
1706+
NamedPipe,
17081707

17091708
/// This file is a block device, corresponding to `S_IFBLK`
1710-
TypeBlockSpecial,
1709+
BlockSpecial,
17111710

17121711
/// This file is a symbolic link to another file, corresponding to `S_IFLNK`
1713-
TypeSymlink,
1712+
Symlink,
17141713

17151714
/// The type of this file is not recognized as one of the other categories
1716-
TypeUnknown,
1715+
Unknown,
17171716
}
17181717

17191718
/// A structure used to describe metadata information about a file. This

src/libstd/sys/unix/fs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ fn mkstat(stat: &libc::stat) -> FileStat {
305305
FileStat {
306306
size: stat.st_size as u64,
307307
kind: match (stat.st_mode as libc::mode_t) & libc::S_IFMT {
308-
libc::S_IFREG => io::TypeFile,
309-
libc::S_IFDIR => io::TypeDirectory,
310-
libc::S_IFIFO => io::TypeNamedPipe,
311-
libc::S_IFBLK => io::TypeBlockSpecial,
312-
libc::S_IFLNK => io::TypeSymlink,
313-
_ => io::TypeUnknown,
308+
libc::S_IFREG => io::FileType::RegularFile,
309+
libc::S_IFDIR => io::FileType::Directory,
310+
libc::S_IFIFO => io::FileType::NamedPipe,
311+
libc::S_IFBLK => io::FileType::BlockSpecial,
312+
libc::S_IFLNK => io::FileType::Symlink,
313+
_ => io::FileType::Unknown,
314314
},
315315
perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
316316
created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64),

src/libstd/sys/windows/fs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ fn mkstat(stat: &libc::stat) -> FileStat {
407407
FileStat {
408408
size: stat.st_size as u64,
409409
kind: match (stat.st_mode as libc::c_int) & libc::S_IFMT {
410-
libc::S_IFREG => io::TypeFile,
411-
libc::S_IFDIR => io::TypeDirectory,
412-
libc::S_IFIFO => io::TypeNamedPipe,
413-
libc::S_IFBLK => io::TypeBlockSpecial,
414-
libc::S_IFLNK => io::TypeSymlink,
415-
_ => io::TypeUnknown,
410+
libc::S_IFREG => io::FileType::RegularFile,
411+
libc::S_IFDIR => io::FileType::Directory,
412+
libc::S_IFIFO => io::FileType::NamedPipe,
413+
libc::S_IFBLK => io::FileType::BlockSpecial,
414+
libc::S_IFLNK => io::FileType::Symlink,
415+
_ => io::FileType::Unknown,
416416
},
417417
perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
418418
created: stat.st_ctime as u64,

src/test/run-pass/issue-18619.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
use std::io::FileType;
1212

1313
pub fn main() {
14-
let _ = FileType::TypeFile.clone();
14+
let _ = FileType::RegularFile.clone();
1515
}

0 commit comments

Comments
 (0)