Skip to content

Commit 1bd9143

Browse files
committed
std: Stabilize a number of new fs features
This commit stabilizes the following APIs, slating them all to be cherry-picked into the 1.1 release. * fs::FileType (and transitively the derived trait implementations) * fs::Metadata::file_type * fs::FileType::is_dir * fs::FileType::is_file * fs::FileType::is_symlink * fs::DirEntry::metadata * fs::DirEntry::file_type * fs::DirEntry::file_name * fs::set_permissions * fs::symlink_metadata * os::raw::{self, *} * os::{android, bitrig, linux, ...}::raw::{self, *} * os::{android, bitrig, linux, ...}::fs::MetadataExt * os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat * os::unix::fs::PermissionsExt * os::unix::fs::PermissionsExt::mode * os::unix::fs::PermissionsExt::set_mode * os::unix::fs::PermissionsExt::from_mode * os::unix::fs::OpenOptionsExt * os::unix::fs::OpenOptionsExt::mode * os::unix::fs::DirEntryExt * os::unix::fs::DirEntryExt::ino * os::windows::fs::MetadataExt * os::windows::fs::MetadataExt::file_attributes * os::windows::fs::MetadataExt::creation_time * os::windows::fs::MetadataExt::last_access_time * os::windows::fs::MetadataExt::last_write_time * os::windows::fs::MetadataExt::file_size The `os::unix::fs::Metadata` structure was also removed entirely, moving all of its associated methods into the `os::unix::fs::MetadataExt` trait instead. The methods are all marked as `#[stable]` still. As some minor cleanup, some deprecated and unstable fs apis were also removed: * File::path * Metadata::accessed * Metadata::modified Features that were explicitly left unstable include: * fs::WalkDir - the semantics of this were not considered in the recent fs expansion RFC. * fs::DirBuilder - it's still not 100% clear if the naming is right here and if the set of functionality exposed is appropriate. * fs::canonicalize - the implementation on Windows here is specifically in question as it always returns a verbatim path. Additionally the Unix implementation is susceptible to buffer overflows on long paths unfortunately. * fs::PathExt - as this is just a convenience trait, it is not stabilized at this time. * fs::set_file_times - this funciton is still waiting on a time abstraction.
1 parent efcc1d1 commit 1bd9143

File tree

26 files changed

+626
-262
lines changed

26 files changed

+626
-262
lines changed

src/librustc_trans/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#![feature(staged_api)]
3838
#![feature(unicode)]
3939
#![feature(path_ext)]
40-
#![feature(fs)]
4140
#![feature(path_relative_from)]
4241
#![feature(std_misc)]
4342

src/libstd/fs.rs

+31-55
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub struct OpenOptions(fs_imp::OpenOptions);
148148
pub struct Permissions(fs_imp::FilePermissions);
149149

150150
/// An structure representing a type of file with accessors for each file type.
151-
#[unstable(feature = "file_type", reason = "recently added API")]
151+
#[stable(feature = "file_type", since = "1.1.0")]
152152
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
153153
pub struct FileType(fs_imp::FileType);
154154

@@ -208,14 +208,6 @@ impl File {
208208
OpenOptions::new().write(true).create(true).truncate(true).open(path)
209209
}
210210

211-
/// Returns `None`.
212-
#[unstable(feature = "file_path",
213-
reason = "this abstraction was imposed by this library and was removed")]
214-
#[deprecated(since = "1.0.0", reason = "abstraction was removed")]
215-
pub fn path(&self) -> Option<&Path> {
216-
None
217-
}
218-
219211
/// Attempts to sync all OS-internal metadata to disk.
220212
///
221213
/// This function will attempt to ensure that all in-core data reaches the
@@ -501,7 +493,7 @@ impl AsInnerMut<fs_imp::OpenOptions> for OpenOptions {
501493

502494
impl Metadata {
503495
/// Returns the file type for this metadata.
504-
#[unstable(feature = "file_type", reason = "recently added API")]
496+
#[stable(feature = "file_type", since = "1.1.0")]
505497
pub fn file_type(&self) -> FileType {
506498
FileType(self.0.file_type())
507499
}
@@ -575,38 +567,6 @@ impl Metadata {
575567
pub fn permissions(&self) -> Permissions {
576568
Permissions(self.0.perm())
577569
}
578-
579-
/// Returns the most recent access time for a file.
580-
///
581-
/// The return value is in milliseconds since the epoch.
582-
#[unstable(feature = "fs_time",
583-
reason = "the return type of u64 is not quite appropriate for \
584-
this method and may change if the standard library \
585-
gains a type to represent a moment in time")]
586-
#[deprecated(since = "1.1.0",
587-
reason = "use os::platform::fs::MetadataExt extension traits")]
588-
pub fn accessed(&self) -> u64 {
589-
self.adjust_time(self.0.accessed())
590-
}
591-
592-
/// Returns the most recent modification time for a file.
593-
///
594-
/// The return value is in milliseconds since the epoch.
595-
#[unstable(feature = "fs_time",
596-
reason = "the return type of u64 is not quite appropriate for \
597-
this method and may change if the standard library \
598-
gains a type to represent a moment in time")]
599-
#[deprecated(since = "1.1.0",
600-
reason = "use os::platform::fs::MetadataExt extension traits")]
601-
pub fn modified(&self) -> u64 {
602-
self.adjust_time(self.0.modified())
603-
}
604-
605-
fn adjust_time(&self, val: u64) -> u64 {
606-
// FILETIME (what `val` represents) is in 100ns intervals and there are
607-
// 10000 intervals in a millisecond.
608-
if cfg!(windows) {val / 10000} else {val}
609-
}
610570
}
611571

612572
impl AsInner<fs_imp::FileAttr> for Metadata {
@@ -663,15 +623,17 @@ impl Permissions {
663623
}
664624
}
665625

666-
#[unstable(feature = "file_type", reason = "recently added API")]
667626
impl FileType {
668627
/// Test whether this file type represents a directory.
628+
#[stable(feature = "file_type", since = "1.1.0")]
669629
pub fn is_dir(&self) -> bool { self.0.is_dir() }
670630

671631
/// Test whether this file type represents a regular file.
632+
#[stable(feature = "file_type", since = "1.1.0")]
672633
pub fn is_file(&self) -> bool { self.0.is_file() }
673634

674635
/// Test whether this file type represents a symbolic link.
636+
#[stable(feature = "file_type", since = "1.1.0")]
675637
pub fn is_symlink(&self) -> bool { self.0.is_symlink() }
676638
}
677639

@@ -736,7 +698,7 @@ impl DirEntry {
736698
/// On Windows this function is cheap to call (no extra system calls
737699
/// needed), but on Unix platforms this function is the equivalent of
738700
/// calling `symlink_metadata` on the path.
739-
#[unstable(feature = "dir_entry_ext", reason = "recently added API")]
701+
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
740702
pub fn metadata(&self) -> io::Result<Metadata> {
741703
self.0.metadata().map(Metadata)
742704
}
@@ -751,14 +713,14 @@ impl DirEntry {
751713
/// On Windows and most Unix platforms this function is free (no extra
752714
/// system calls needed), but some Unix platforms may require the equivalent
753715
/// call to `symlink_metadata` to learn about the target file type.
754-
#[unstable(feature = "dir_entry_ext", reason = "recently added API")]
716+
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
755717
pub fn file_type(&self) -> io::Result<FileType> {
756718
self.0.file_type().map(FileType)
757719
}
758720

759721
/// Returns the bare file name of this directory entry without any other
760722
/// leading path component.
761-
#[unstable(feature = "dir_entry_ext", reason = "recently added API")]
723+
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
762724
pub fn file_name(&self) -> OsString {
763725
self.0.file_name()
764726
}
@@ -837,7 +799,7 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
837799
/// # Ok(())
838800
/// # }
839801
/// ```
840-
#[unstable(feature = "symlink_metadata", reason = "recently added API")]
802+
#[stable(feature = "symlink_metadata", since = "1.1.0")]
841803
pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
842804
fs_imp::lstat(path.as_ref()).map(Metadata)
843805
}
@@ -1284,14 +1246,13 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, accessed: u64,
12841246
/// This function will return an error if the provided `path` doesn't exist, if
12851247
/// the process lacks permissions to change the attributes of the file, or if
12861248
/// some other I/O error is encountered.
1287-
#[unstable(feature = "fs",
1288-
reason = "a more granual ability to set specific permissions may \
1289-
be exposed on the Permissions structure itself and this \
1290-
method may not always exist")]
1291-
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
1249+
#[stable(feature = "set_permissions", since = "1.1.0")]
1250+
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions)
1251+
-> io::Result<()> {
12921252
fs_imp::set_perm(path.as_ref(), perm.0)
12931253
}
12941254

1255+
#[unstable(feature = "dir_builder", reason = "recently added API")]
12951256
impl DirBuilder {
12961257
/// Creates a new set of options with default mode/security settings for all
12971258
/// platforms and also non-recursive.
@@ -2064,9 +2025,24 @@ mod tests {
20642025
// These numbers have to be bigger than the time in the day to account
20652026
// for timezones Windows in particular will fail in certain timezones
20662027
// with small enough values
2067-
check!(fs::set_file_times(&path, 100000, 200000));
2068-
assert_eq!(check!(path.metadata()).accessed(), 100000);
2069-
assert_eq!(check!(path.metadata()).modified(), 200000);
2028+
check!(fs::set_file_times(&path, 100_000, 200_000));
2029+
2030+
check(&check!(path.metadata()));
2031+
2032+
#[cfg(unix)]
2033+
fn check(metadata: &fs::Metadata) {
2034+
use os::unix::prelude::*;
2035+
assert_eq!(metadata.atime(), 100);
2036+
assert_eq!(metadata.atime_nsec(), 0);
2037+
assert_eq!(metadata.mtime(), 200);
2038+
assert_eq!(metadata.mtime_nsec(), 0);
2039+
}
2040+
#[cfg(windows)]
2041+
fn check(metadata: &fs::Metadata) {
2042+
use os::windows::prelude::*;
2043+
assert_eq!(metadata.last_access_time(), 100_000 * 10_000);
2044+
assert_eq!(metadata.last_write_time(), 200_000 * 10_000);
2045+
}
20702046
}
20712047

20722048
#[test]

src/libstd/os/android/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
//! Android-specific definitions
1212
13-
#![unstable(feature = "raw_ext", reason = "recently added API")]
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
1414

1515
pub mod raw;
1616

1717
pub mod fs {
18+
#![stable(feature = "raw_ext", since = "1.1.0")]
1819
pub use sys::fs::MetadataExt;
1920
}

src/libstd/os/android/raw.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,59 @@
1010

1111
//! Android-specific raw type definitions
1212
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
14+
1315
use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong};
1416
use os::unix::raw::{uid_t, gid_t};
1517

16-
pub type blkcnt_t = u32;
17-
pub type blksize_t = u32;
18-
pub type dev_t = u32;
19-
pub type ino_t = u32;
20-
pub type mode_t = u16;
21-
pub type nlink_t = u16;
22-
pub type off_t = i32;
23-
pub type time_t = i32;
18+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u32;
19+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32;
20+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u32;
21+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32;
22+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u16;
23+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u16;
24+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
2426

2527
#[repr(C)]
28+
#[stable(feature = "raw_ext", since = "1.1.0")]
2629
pub struct stat {
30+
#[stable(feature = "raw_ext", since = "1.1.0")]
2731
pub st_dev: c_ulonglong,
32+
#[stable(feature = "raw_ext", since = "1.1.0")]
2833
pub __pad0: [c_uchar; 4],
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
2935
pub __st_ino: ino_t,
36+
#[stable(feature = "raw_ext", since = "1.1.0")]
3037
pub st_mode: c_uint,
38+
#[stable(feature = "raw_ext", since = "1.1.0")]
3139
pub st_nlink: c_uint,
40+
#[stable(feature = "raw_ext", since = "1.1.0")]
3241
pub st_uid: uid_t,
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
3343
pub st_gid: gid_t,
44+
#[stable(feature = "raw_ext", since = "1.1.0")]
3445
pub st_rdev: c_ulonglong,
46+
#[stable(feature = "raw_ext", since = "1.1.0")]
3547
pub __pad3: [c_uchar; 4],
48+
#[stable(feature = "raw_ext", since = "1.1.0")]
3649
pub st_size: c_longlong,
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
3751
pub st_blksize: blksize_t,
52+
#[stable(feature = "raw_ext", since = "1.1.0")]
3853
pub st_blocks: c_ulonglong,
54+
#[stable(feature = "raw_ext", since = "1.1.0")]
3955
pub st_atime: time_t,
56+
#[stable(feature = "raw_ext", since = "1.1.0")]
4057
pub st_atime_nsec: c_ulong,
58+
#[stable(feature = "raw_ext", since = "1.1.0")]
4159
pub st_mtime: time_t,
60+
#[stable(feature = "raw_ext", since = "1.1.0")]
4261
pub st_mtime_nsec: c_ulong,
62+
#[stable(feature = "raw_ext", since = "1.1.0")]
4363
pub st_ctime: time_t,
64+
#[stable(feature = "raw_ext", since = "1.1.0")]
4465
pub st_ctime_nsec: c_ulong,
66+
#[stable(feature = "raw_ext", since = "1.1.0")]
4567
pub st_ino: c_ulonglong,
4668
}

src/libstd/os/bitrig/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
//! Bitrig-specific definitions
1212
13-
#![unstable(feature = "raw_ext", reason = "recently added API")]
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
1414

1515
pub mod raw;
1616

1717
pub mod fs {
18+
#![stable(feature = "raw_ext", since = "1.1.0")]
1819
pub use sys::fs::MetadataExt;
1920
}

src/libstd/os/bitrig/raw.rs

+32-9
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,62 @@
1010

1111
//! Bitrig-specific raw type definitions
1212
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
14+
1315
use os::raw::c_long;
1416
use os::unix::raw::{uid_t, gid_t};
1517

16-
pub type blkcnt_t = i64;
17-
pub type blksize_t = u32;
18-
pub type dev_t = i32;
19-
pub type fflags_t = u32; // type not declared, but struct stat have u_int32_t
20-
pub type ino_t = u64;
21-
pub type mode_t = u32;
22-
pub type nlink_t = u32;
23-
pub type off_t = i64;
24-
pub type time_t = i64;
18+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64;
19+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32;
20+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = i32;
21+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32;
22+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64;
23+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32;
24+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
26+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
2527

2628
#[repr(C)]
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
2730
pub struct stat {
31+
#[stable(feature = "raw_ext", since = "1.1.0")]
2832
pub st_mode: mode_t,
33+
#[stable(feature = "raw_ext", since = "1.1.0")]
2934
pub st_dev: dev_t,
35+
#[stable(feature = "raw_ext", since = "1.1.0")]
3036
pub st_ino: ino_t,
37+
#[stable(feature = "raw_ext", since = "1.1.0")]
3138
pub st_nlink: nlink_t,
39+
#[stable(feature = "raw_ext", since = "1.1.0")]
3240
pub st_uid: uid_t,
41+
#[stable(feature = "raw_ext", since = "1.1.0")]
3342
pub st_gid: gid_t,
43+
#[stable(feature = "raw_ext", since = "1.1.0")]
3444
pub st_rdev: dev_t,
45+
#[stable(feature = "raw_ext", since = "1.1.0")]
3546
pub st_atime: time_t,
47+
#[stable(feature = "raw_ext", since = "1.1.0")]
3648
pub st_atime_nsec: c_long,
49+
#[stable(feature = "raw_ext", since = "1.1.0")]
3750
pub st_mtime: time_t,
51+
#[stable(feature = "raw_ext", since = "1.1.0")]
3852
pub st_mtime_nsec: c_long,
53+
#[stable(feature = "raw_ext", since = "1.1.0")]
3954
pub st_ctime: time_t,
55+
#[stable(feature = "raw_ext", since = "1.1.0")]
4056
pub st_ctime_nsec: c_long,
57+
#[stable(feature = "raw_ext", since = "1.1.0")]
4158
pub st_size: off_t,
59+
#[stable(feature = "raw_ext", since = "1.1.0")]
4260
pub st_blocks: blkcnt_t,
61+
#[stable(feature = "raw_ext", since = "1.1.0")]
4362
pub st_blksize: blksize_t,
63+
#[stable(feature = "raw_ext", since = "1.1.0")]
4464
pub st_flags: fflags_t,
65+
#[stable(feature = "raw_ext", since = "1.1.0")]
4566
pub st_gen: u32,
67+
#[stable(feature = "raw_ext", since = "1.1.0")]
4668
pub st_birthtime: time_t,
69+
#[stable(feature = "raw_ext", since = "1.1.0")]
4770
pub st_birthtime_nsec: c_long,
4871
}

src/libstd/os/dragonfly/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
//! Dragonfly-specific definitions
1212
13-
#![unstable(feature = "raw_ext", reason = "recently added API")]
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
1414

1515
pub mod raw;
1616

1717
pub mod fs {
18+
#![stable(feature = "raw_ext", since = "1.1.0")]
1819
pub use sys::fs::MetadataExt;
1920
}

0 commit comments

Comments
 (0)