]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #25844 - alexcrichton:stabilize-fs-features, r=aturon
authorbors <bors@rust-lang.org>
Fri, 12 Jun 2015 21:31:37 +0000 (21:31 +0000)
committerbors <bors@rust-lang.org>
Fri, 12 Jun 2015 21:31:37 +0000 (21:31 +0000)
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  2 
src/libstd/sys/unix/fs.rs
src/libstd/sys/windows/ext/fs.rs

index 58e205a01cae018a254e44ba4aacb20ed5558f1a,1355408ac9717b11af13deb1917dd6dc781c0b98..128284834ab01362944242581aa25349352eeb96
@@@ -69,42 -69,33 +69,33 @@@ impl FileAttr 
          FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 }
      }
  
-     pub fn accessed(&self) -> u64 {
-         self.mktime(self.stat.st_atime as u64, self.stat.st_atime_nsec as u64)
-     }
-     pub fn modified(&self) -> u64 {
-         self.mktime(self.stat.st_mtime as u64, self.stat.st_mtime_nsec as u64)
-     }
      pub fn file_type(&self) -> FileType {
          FileType { mode: self.stat.st_mode as mode_t }
      }
-     pub fn raw(&self) -> &raw::stat { &self.stat }
-     // times are in milliseconds (currently)
-     fn mktime(&self, secs: u64, nsecs: u64) -> u64 {
-         secs * 1000 + nsecs / 1000000
-     }
  }
  
  impl AsInner<raw::stat> for FileAttr {
      fn as_inner(&self) -> &raw::stat { &self.stat }
  }
  
- #[unstable(feature = "metadata_ext", reason = "recently added API")]
+ /// OS-specific extension methods for `fs::Metadata`
+ #[stable(feature = "metadata_ext", since = "1.1.0")]
  pub trait MetadataExt {
+     /// Gain a reference to the underlying `stat` structure which contains the
+     /// raw information returned by the OS.
+     ///
+     /// The contents of the returned `stat` are **not** consistent across Unix
+     /// platforms. The `os::unix::fs::MetadataExt` trait contains the cross-Unix
+     /// abstractions contained within the raw stat.
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn as_raw_stat(&self) -> &raw::stat;
  }
  
+ #[stable(feature = "metadata_ext", since = "1.1.0")]
  impl MetadataExt for ::fs::Metadata {
      fn as_raw_stat(&self) -> &raw::stat { &self.as_inner().stat }
  }
  
- impl MetadataExt for ::os::unix::fs::Metadata {
-     fn as_raw_stat(&self) -> &raw::stat { self.as_inner() }
- }
  impl FilePermissions {
      pub fn readonly(&self) -> bool { self.mode & 0o222 == 0 }
      pub fn set_readonly(&mut self, readonly: bool) {
@@@ -283,6 -274,8 +274,6 @@@ impl File 
          Ok(File(fd))
      }
  
 -    pub fn into_fd(self) -> FileDesc { self.0 }
 -
      pub fn file_attr(&self) -> io::Result<FileAttr> {
          let mut stat: raw::stat = unsafe { mem::zeroed() };
          try!(cvt(unsafe {
index 28d9b3e047633fd53c83d0a2b78d529a200cbc37,cad92d33fbcd8e020ca1725836bbc324d374a366..f629e983ce542aeaa438406ca607b73fb709af22
@@@ -21,84 -21,91 +21,91 @@@ use sys
  use sys_common::{AsInnerMut, AsInner};
  
  /// Windows-specific extensions to `OpenOptions`
- #[unstable(feature = "fs_ext", reason = "may require more thought/methods")]
+ #[unstable(feature = "open_options_ext",
+            reason = "may require more thought/methods")]
  pub trait OpenOptionsExt {
      /// Overrides the `dwDesiredAccess` argument to the call to `CreateFile`
      /// with the specified value.
 -    fn desired_access(&mut self, access: i32) -> &mut Self;
 +    fn desired_access(&mut self, access: u32) -> &mut Self;
  
      /// Overrides the `dwCreationDisposition` argument to the call to
      /// `CreateFile` with the specified value.
      ///
      /// This will override any values of the standard `create` flags, for
      /// example.
 -    fn creation_disposition(&mut self, val: i32) -> &mut Self;
 +    fn creation_disposition(&mut self, val: u32) -> &mut Self;
  
      /// Overrides the `dwFlagsAndAttributes` argument to the call to
      /// `CreateFile` with the specified value.
      ///
      /// This will override any values of the standard flags on the
      /// `OpenOptions` structure.
 -    fn flags_and_attributes(&mut self, val: i32) -> &mut Self;
 +    fn flags_and_attributes(&mut self, val: u32) -> &mut Self;
  
      /// Overrides the `dwShareMode` argument to the call to `CreateFile` with
      /// the specified value.
      ///
      /// This will override any values of the standard flags on the
      /// `OpenOptions` structure.
 -    fn share_mode(&mut self, val: i32) -> &mut Self;
 +    fn share_mode(&mut self, val: u32) -> &mut Self;
  }
  
  impl OpenOptionsExt for OpenOptions {
 -    fn desired_access(&mut self, access: i32) -> &mut OpenOptions {
 +    fn desired_access(&mut self, access: u32) -> &mut OpenOptions {
          self.as_inner_mut().desired_access(access); self
      }
 -    fn creation_disposition(&mut self, access: i32) -> &mut OpenOptions {
 +    fn creation_disposition(&mut self, access: u32) -> &mut OpenOptions {
          self.as_inner_mut().creation_disposition(access); self
      }
 -    fn flags_and_attributes(&mut self, access: i32) -> &mut OpenOptions {
 +    fn flags_and_attributes(&mut self, access: u32) -> &mut OpenOptions {
          self.as_inner_mut().flags_and_attributes(access); self
      }
 -    fn share_mode(&mut self, access: i32) -> &mut OpenOptions {
 +    fn share_mode(&mut self, access: u32) -> &mut OpenOptions {
          self.as_inner_mut().share_mode(access); self
      }
  }
  
  /// Extension methods for `fs::Metadata` to access the raw fields contained
  /// within.
- #[unstable(feature = "metadata_ext", reason = "recently added API")]
+ #[stable(feature = "metadata_ext", since = "1.1.0")]
  pub trait MetadataExt {
      /// Returns the value of the `dwFileAttributes` field of this metadata.
      ///
      /// This field contains the file system attribute information for a file
      /// or directory.
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn file_attributes(&self) -> u32;
  
      /// Returns the value of the `ftCreationTime` field of this metadata.
      ///
      /// The returned 64-bit value represents the number of 100-nanosecond
      /// intervals since January 1, 1601 (UTC).
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn creation_time(&self) -> u64;
  
      /// Returns the value of the `ftLastAccessTime` field of this metadata.
      ///
      /// The returned 64-bit value represents the number of 100-nanosecond
      /// intervals since January 1, 1601 (UTC).
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn last_access_time(&self) -> u64;
  
      /// Returns the value of the `ftLastWriteTime` field of this metadata.
      ///
      /// The returned 64-bit value represents the number of 100-nanosecond
      /// intervals since January 1, 1601 (UTC).
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn last_write_time(&self) -> u64;
  
      /// Returns the value of the `nFileSize{High,Low}` fields of this
      /// metadata.
      ///
      /// The returned value does not have meaning for directories.
+     #[stable(feature = "metadata_ext", since = "1.1.0")]
      fn file_size(&self) -> u64;
  }
  
+ #[stable(feature = "metadata_ext", since = "1.1.0")]
  impl MetadataExt for Metadata {
      fn file_attributes(&self) -> u32 { self.as_inner().attrs() }
      fn creation_time(&self) -> u64 { self.as_inner().created() }