2015-04-15 23:21:13 -07:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Windows-specific extensions for the primitives in `std::fs`
|
|
|
|
|
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
|
|
|
use fs::{OpenOptions, Metadata};
|
|
|
|
use io;
|
|
|
|
use path::Path;
|
|
|
|
use sys;
|
|
|
|
use sys_common::{AsInnerMut, AsInner};
|
|
|
|
|
|
|
|
/// Windows-specific extensions to `OpenOptions`
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[unstable(feature = "open_options_ext",
|
2015-08-13 13:06:25 -07:00
|
|
|
reason = "may require more thought/methods",
|
|
|
|
issue = "27720")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub trait OpenOptionsExt {
|
|
|
|
/// Overrides the `dwDesiredAccess` argument to the call to `CreateFile`
|
|
|
|
/// with the specified value.
|
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// This will override the `read`, `write`, and `append` flags on the
|
|
|
|
/// `OpenOptions` structure. This method provides fine-grained control
|
|
|
|
/// over the permissions to read, write and append data, attributes
|
|
|
|
/// (like hidden and system) and extended attributes.
|
|
|
|
///
|
|
|
|
/// # Examples
|
2015-04-15 23:21:13 -07:00
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// ```no_run
|
|
|
|
/// #![feature(open_options_ext)]
|
|
|
|
/// use std::fs::OpenOptions;
|
|
|
|
/// use std::os::windows::fs::OpenOptionsExt;
|
|
|
|
///
|
|
|
|
/// // Open without read and write permission, for example if you only need to call `stat()`
|
|
|
|
/// // on the file
|
|
|
|
/// let file = OpenOptions::new().access_mode(0).open("foo.txt");
|
|
|
|
/// ```
|
|
|
|
fn access_mode(&mut self, access: u32) -> &mut Self;
|
2015-04-15 23:21:13 -07:00
|
|
|
|
|
|
|
/// Overrides the `dwShareMode` argument to the call to `CreateFile` with
|
|
|
|
/// the specified value.
|
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// By default `share_mode` is set to `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`.
|
|
|
|
/// Specifying less permissions denies others to read from, write to and/or
|
|
|
|
/// delete the file while it is open.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// #![feature(open_options_ext)]
|
|
|
|
/// use std::fs::OpenOptions;
|
|
|
|
/// use std::os::windows::fs::OpenOptionsExt;
|
|
|
|
///
|
|
|
|
/// let file = OpenOptions::new().write(true)
|
|
|
|
/// .share_mode(0) // Do not allow others to read or modify
|
|
|
|
/// .open("foo.txt");
|
|
|
|
/// ```
|
2015-06-08 14:04:22 -04:00
|
|
|
fn share_mode(&mut self, val: u32) -> &mut Self;
|
2016-01-13 18:08:08 +01:00
|
|
|
|
|
|
|
/// Sets the `dwFileAttributes` argument to the call to `CreateFile2` to
|
|
|
|
/// the specified value (or combines it with `custom_flags` and
|
|
|
|
/// `security_qos_flags` to set the `dwFlagsAndAttributes` for `CreateFile`).
|
|
|
|
///
|
|
|
|
/// If a _new_ file is created because it does not yet exist and `.create(true)` or
|
|
|
|
/// `.create_new(true)` are specified, the new file is given the attributes declared
|
|
|
|
/// with `.attributes()`.
|
|
|
|
///
|
|
|
|
/// If an _existing_ file is opened with `.create(true).truncate(true)`, its
|
|
|
|
/// existing attributes are preserved and combined with the ones declared with
|
|
|
|
/// `.attributes()`.
|
|
|
|
///
|
|
|
|
/// In all other cases the attributes get ignored.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```rust,ignore
|
|
|
|
/// #![feature(open_options_ext)]
|
|
|
|
/// extern crate winapi;
|
|
|
|
/// use std::fs::OpenOptions;
|
|
|
|
/// use std::os::windows::fs::OpenOptionsExt;
|
|
|
|
///
|
|
|
|
/// let file = OpenOptions::new().write(true).create(true)
|
|
|
|
/// .attributes(winapi::FILE_ATTRIBUTE_HIDDEN)
|
|
|
|
/// .open("foo.txt");
|
|
|
|
/// ```
|
|
|
|
fn attributes(&mut self, val: u32) -> &mut Self;
|
|
|
|
|
|
|
|
/// Sets the `dwSecurityQosFlags` argument to the call to `CreateFile2` to
|
|
|
|
/// the specified value (or combines it with `custom_flags` and `attributes`
|
|
|
|
/// to set the `dwFlagsAndAttributes` for `CreateFile`).
|
|
|
|
fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions;
|
|
|
|
|
|
|
|
/// Sets the `lpSecurityAttributes` argument to the call to `CreateFile` to
|
|
|
|
/// the specified value.
|
|
|
|
fn security_attributes(&mut self, attrs: sys::c::LPSECURITY_ATTRIBUTES) -> &mut OpenOptions;
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2015-11-16 19:54:28 +03:00
|
|
|
#[unstable(feature = "open_options_ext",
|
|
|
|
reason = "may require more thought/methods",
|
|
|
|
issue = "27720")]
|
2015-04-15 23:21:13 -07:00
|
|
|
impl OpenOptionsExt for OpenOptions {
|
2016-01-13 18:08:08 +01:00
|
|
|
fn access_mode(&mut self, access: u32) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().access_mode(access); self
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
2016-01-13 18:08:08 +01:00
|
|
|
|
|
|
|
fn share_mode(&mut self, share: u32) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().share_mode(share); self
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
2016-01-13 18:08:08 +01:00
|
|
|
|
|
|
|
fn attributes(&mut self, attributes: u32) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().attributes(attributes); self
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
2016-01-13 18:08:08 +01:00
|
|
|
|
|
|
|
fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().security_qos_flags(flags); self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn security_attributes(&mut self, attrs: sys::c::LPSECURITY_ATTRIBUTES) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().security_attributes(attrs); self
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Extension methods for `fs::Metadata` to access the raw fields contained
|
|
|
|
/// within.
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
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.
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
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).
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
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).
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
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).
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
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.
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn file_size(&self) -> u64;
|
|
|
|
}
|
|
|
|
|
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.
2015-05-27 16:29:55 -07:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
impl MetadataExt for Metadata {
|
|
|
|
fn file_attributes(&self) -> u32 { self.as_inner().attrs() }
|
|
|
|
fn creation_time(&self) -> u64 { self.as_inner().created() }
|
|
|
|
fn last_access_time(&self) -> u64 { self.as_inner().accessed() }
|
|
|
|
fn last_write_time(&self) -> u64 { self.as_inner().modified() }
|
|
|
|
fn file_size(&self) -> u64 { self.as_inner().size() }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new file symbolic link on the filesystem.
|
|
|
|
///
|
|
|
|
/// The `dst` path will be a file symbolic link pointing to the `src`
|
|
|
|
/// path.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// use std::os::windows::fs;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
|
|
|
/// try!(fs::symlink_file("a.txt", "b.txt"));
|
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
2015-05-20 21:50:18 -04:00
|
|
|
#[stable(feature = "symlink", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
|
|
|
|
-> io::Result<()> {
|
2015-05-05 16:35:15 -07:00
|
|
|
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false)
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new directory symlink on the filesystem.
|
|
|
|
///
|
|
|
|
/// The `dst` path will be a directory symbolic link pointing to the `src`
|
|
|
|
/// path.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// use std::os::windows::fs;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
|
|
|
/// try!(fs::symlink_file("a", "b"));
|
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
2015-05-20 21:50:18 -04:00
|
|
|
#[stable(feature = "symlink", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
|
|
|
|
-> io::Result<()> {
|
2015-05-05 16:35:15 -07:00
|
|
|
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true)
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|