Skip to content

Commit 50ab23d

Browse files
committed
Auto merge of #25844 - alexcrichton:stabilize-fs-features, r=aturon
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.
2 parents 85b5338 + ec68c4a commit 50ab23d

File tree

27 files changed

+672
-257
lines changed

27 files changed

+672
-257
lines changed

RELEASES.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
Version 1.1.0 (July 2015)
2+
========================
3+
4+
* NNNN changes, numerous bugfixes
5+
6+
Libraries
7+
---------
8+
9+
* The [`std::fs` module has been expanded][fs-expand] to expand the set of
10+
functionality exposed:
11+
* `DirEntry` now supports optimizations like `file_type` and `metadata` which
12+
don't incur a syscall on some platforms.
13+
* A `symlink_metadata` function has been added.
14+
* The `fs::Metadata` structure now lowers to its OS counterpart, providing
15+
access to all underlying information.
16+
17+
[fs-expand]: https://github.com/rust-lang/rust/pull/25844
18+
119
Version 1.0.0 (May 2015)
220
========================
321

src/librustc_trans/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#![feature(staged_api)]
3939
#![feature(unicode)]
4040
#![feature(path_ext)]
41-
#![feature(fs)]
4241
#![feature(path_relative_from)]
4342
#![feature(std_misc)]
4443

src/libstd/fs.rs

+31-57
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
}
@@ -828,7 +790,6 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
828790
/// # Examples
829791
///
830792
/// ```rust
831-
/// #![feature(symlink_metadata)]
832793
/// # fn foo() -> std::io::Result<()> {
833794
/// use std::fs;
834795
///
@@ -837,7 +798,7 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
837798
/// # Ok(())
838799
/// # }
839800
/// ```
840-
#[unstable(feature = "symlink_metadata", reason = "recently added API")]
801+
#[stable(feature = "symlink_metadata", since = "1.1.0")]
841802
pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
842803
fs_imp::lstat(path.as_ref()).map(Metadata)
843804
}
@@ -1270,7 +1231,6 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, accessed: u64,
12701231
/// # Examples
12711232
///
12721233
/// ```
1273-
/// # #![feature(fs)]
12741234
/// # fn foo() -> std::io::Result<()> {
12751235
/// use std::fs;
12761236
///
@@ -1286,14 +1246,13 @@ pub fn set_file_times<P: AsRef<Path>>(path: P, accessed: u64,
12861246
/// This function will return an error if the provided `path` doesn't exist, if
12871247
/// the process lacks permissions to change the attributes of the file, or if
12881248
/// some other I/O error is encountered.
1289-
#[unstable(feature = "fs",
1290-
reason = "a more granual ability to set specific permissions may \
1291-
be exposed on the Permissions structure itself and this \
1292-
method may not always exist")]
1293-
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<()> {
12941252
fs_imp::set_perm(path.as_ref(), perm.0)
12951253
}
12961254

1255+
#[unstable(feature = "dir_builder", reason = "recently added API")]
12971256
impl DirBuilder {
12981257
/// Creates a new set of options with default mode/security settings for all
12991258
/// platforms and also non-recursive.
@@ -2066,9 +2025,24 @@ mod tests {
20662025
// These numbers have to be bigger than the time in the day to account
20672026
// for timezones Windows in particular will fail in certain timezones
20682027
// with small enough values
2069-
check!(fs::set_file_times(&path, 100000, 200000));
2070-
assert_eq!(check!(path.metadata()).accessed(), 100000);
2071-
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+
}
20722046
}
20732047

20742048
#[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

+58-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Android-specific raw type definitions
1212
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
14+
1315
#[doc(inline)]
1416
pub use self::arch::{dev_t, mode_t, blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
1517

@@ -18,36 +20,64 @@ mod arch {
1820
use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong};
1921
use os::unix::raw::{uid_t, gid_t};
2022

23+
#[stable(feature = "raw_ext", since = "1.1.0")]
2124
pub type dev_t = u32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")]
2226
pub type mode_t = u16;
2327

28+
#[stable(feature = "raw_ext", since = "1.1.0")]
2429
pub type blkcnt_t = u32;
30+
#[stable(feature = "raw_ext", since = "1.1.0")]
2531
pub type blksize_t = u32;
32+
#[stable(feature = "raw_ext", since = "1.1.0")]
2633
pub type ino_t = u32;
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
2735
pub type nlink_t = u16;
36+
#[stable(feature = "raw_ext", since = "1.1.0")]
2837
pub type off_t = i32;
38+
#[stable(feature = "raw_ext", since = "1.1.0")]
2939
pub type time_t = i32;
3040

3141
#[repr(C)]
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
3243
pub struct stat {
44+
#[stable(feature = "raw_ext", since = "1.1.0")]
3345
pub st_dev: c_ulonglong,
46+
#[stable(feature = "raw_ext", since = "1.1.0")]
3447
pub __pad0: [c_uchar; 4],
48+
#[stable(feature = "raw_ext", since = "1.1.0")]
3549
pub __st_ino: ino_t,
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
3651
pub st_mode: c_uint,
52+
#[stable(feature = "raw_ext", since = "1.1.0")]
3753
pub st_nlink: c_uint,
54+
#[stable(feature = "raw_ext", since = "1.1.0")]
3855
pub st_uid: uid_t,
56+
#[stable(feature = "raw_ext", since = "1.1.0")]
3957
pub st_gid: gid_t,
58+
#[stable(feature = "raw_ext", since = "1.1.0")]
4059
pub st_rdev: c_ulonglong,
60+
#[stable(feature = "raw_ext", since = "1.1.0")]
4161
pub __pad3: [c_uchar; 4],
62+
#[stable(feature = "raw_ext", since = "1.1.0")]
4263
pub st_size: c_longlong,
64+
#[stable(feature = "raw_ext", since = "1.1.0")]
4365
pub st_blksize: blksize_t,
66+
#[stable(feature = "raw_ext", since = "1.1.0")]
4467
pub st_blocks: c_ulonglong,
68+
#[stable(feature = "raw_ext", since = "1.1.0")]
4569
pub st_atime: time_t,
70+
#[stable(feature = "raw_ext", since = "1.1.0")]
4671
pub st_atime_nsec: c_ulong,
72+
#[stable(feature = "raw_ext", since = "1.1.0")]
4773
pub st_mtime: time_t,
74+
#[stable(feature = "raw_ext", since = "1.1.0")]
4875
pub st_mtime_nsec: c_ulong,
76+
#[stable(feature = "raw_ext", since = "1.1.0")]
4977
pub st_ctime: time_t,
78+
#[stable(feature = "raw_ext", since = "1.1.0")]
5079
pub st_ctime_nsec: c_ulong,
80+
#[stable(feature = "raw_ext", since = "1.1.0")]
5181
pub st_ino: c_ulonglong,
5282
}
5383

@@ -59,37 +89,64 @@ mod arch {
5989
use os::raw::{c_uchar, c_ulong};
6090
use os::unix::raw::{uid_t, gid_t};
6191

92+
#[stable(feature = "raw_ext", since = "1.1.0")]
6293
pub type dev_t = u64;
94+
#[stable(feature = "raw_ext", since = "1.1.0")]
6395
pub type mode_t = u32;
6496

97+
#[stable(feature = "raw_ext", since = "1.1.0")]
6598
pub type blkcnt_t = u64;
99+
#[stable(feature = "raw_ext", since = "1.1.0")]
66100
pub type blksize_t = u32;
101+
#[stable(feature = "raw_ext", since = "1.1.0")]
67102
pub type ino_t = u64;
103+
#[stable(feature = "raw_ext", since = "1.1.0")]
68104
pub type nlink_t = u32;
105+
#[stable(feature = "raw_ext", since = "1.1.0")]
69106
pub type off_t = i64;
107+
#[stable(feature = "raw_ext", since = "1.1.0")]
70108
pub type time_t = i64;
71109

72110
#[repr(C)]
111+
#[stable(feature = "raw_ext", since = "1.1.0")]
73112
pub struct stat {
113+
#[stable(feature = "raw_ext", since = "1.1.0")]
74114
pub st_dev: dev_t,
115+
#[stable(feature = "raw_ext", since = "1.1.0")]
75116
pub __pad0: [c_uchar; 4],
117+
#[stable(feature = "raw_ext", since = "1.1.0")]
76118
pub __st_ino: ino_t,
119+
#[stable(feature = "raw_ext", since = "1.1.0")]
77120
pub st_mode: mode_t,
121+
#[stable(feature = "raw_ext", since = "1.1.0")]
78122
pub st_nlink: nlink_t,
123+
#[stable(feature = "raw_ext", since = "1.1.0")]
79124
pub st_uid: uid_t,
125+
#[stable(feature = "raw_ext", since = "1.1.0")]
80126
pub st_gid: gid_t,
127+
#[stable(feature = "raw_ext", since = "1.1.0")]
81128
pub st_rdev: dev_t,
129+
#[stable(feature = "raw_ext", since = "1.1.0")]
82130
pub __pad3: [c_uchar; 4],
131+
#[stable(feature = "raw_ext", since = "1.1.0")]
83132
pub st_size: off_t,
133+
#[stable(feature = "raw_ext", since = "1.1.0")]
84134
pub st_blksize: blksize_t,
135+
#[stable(feature = "raw_ext", since = "1.1.0")]
85136
pub st_blocks: blkcnt_t,
137+
#[stable(feature = "raw_ext", since = "1.1.0")]
86138
pub st_atime: time_t,
139+
#[stable(feature = "raw_ext", since = "1.1.0")]
87140
pub st_atime_nsec: c_ulong,
141+
#[stable(feature = "raw_ext", since = "1.1.0")]
88142
pub st_mtime: time_t,
143+
#[stable(feature = "raw_ext", since = "1.1.0")]
89144
pub st_mtime_nsec: c_ulong,
145+
#[stable(feature = "raw_ext", since = "1.1.0")]
90146
pub st_ctime: time_t,
147+
#[stable(feature = "raw_ext", since = "1.1.0")]
91148
pub st_ctime_nsec: c_ulong,
149+
#[stable(feature = "raw_ext", since = "1.1.0")]
92150
pub st_ino: ino_t,
93151
}
94-
95152
}

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
}

0 commit comments

Comments
 (0)