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.
|
|
|
|
|
2017-05-05 20:35:35 -05:00
|
|
|
//! Windows-specific extensions for the primitives in the `std::fs` module.
|
2015-04-15 23:21:13 -07:00
|
|
|
|
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
2016-08-16 01:11:33 +02:00
|
|
|
use fs::{self, OpenOptions, Metadata};
|
2015-04-15 23:21:13 -07:00
|
|
|
use io;
|
|
|
|
use path::Path;
|
|
|
|
use sys;
|
|
|
|
use sys_common::{AsInnerMut, AsInner};
|
|
|
|
|
2017-05-06 23:05:47 -05:00
|
|
|
/// Windows-specific extensions to [`File`].
|
|
|
|
///
|
|
|
|
/// [`File`]: ../../../fs/struct.File.html
|
2016-12-14 11:35:05 -08:00
|
|
|
#[stable(feature = "file_offset", since = "1.15.0")]
|
2016-08-16 01:11:33 +02:00
|
|
|
pub trait FileExt {
|
|
|
|
/// Seeks to a given position and reads a number of bytes.
|
|
|
|
///
|
|
|
|
/// Returns the number of bytes read.
|
|
|
|
///
|
|
|
|
/// The offset is relative to the start of the file and thus independent
|
|
|
|
/// from the current cursor. The current cursor **is** affected by this
|
|
|
|
/// function, it is set to the end of the read.
|
|
|
|
///
|
|
|
|
/// Reading beyond the end of the file will always return with a length of
|
|
|
|
/// 0.
|
|
|
|
///
|
|
|
|
/// Note that similar to `File::read`, it is not an error to return with a
|
|
|
|
/// short read. When returning from such a short read, the file pointer is
|
|
|
|
/// still updated.
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-05 20:35:35 -05:00
|
|
|
/// use std::io;
|
|
|
|
/// use std::fs::File;
|
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
|
|
|
/// let mut file = File::open("foo.txt")?;
|
|
|
|
/// let mut buffer = [0; 10];
|
|
|
|
///
|
|
|
|
/// // Read 10 bytes, starting 72 bytes from the
|
|
|
|
/// // start of the file.
|
|
|
|
/// file.seek_read(&mut buffer[..], 72)?;
|
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
2016-12-14 11:35:05 -08:00
|
|
|
#[stable(feature = "file_offset", since = "1.15.0")]
|
2016-08-16 01:11:33 +02:00
|
|
|
fn seek_read(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
|
|
|
|
|
|
|
|
/// Seeks to a given position and writes a number of bytes.
|
|
|
|
///
|
|
|
|
/// Returns the number of bytes written.
|
|
|
|
///
|
|
|
|
/// The offset is relative to the start of the file and thus independent
|
|
|
|
/// from the current cursor. The current cursor **is** affected by this
|
|
|
|
/// function, it is set to the end of the write.
|
|
|
|
///
|
2017-08-11 20:34:14 +02:00
|
|
|
/// When writing beyond the end of the file, the file is appropriately
|
2016-08-16 01:11:33 +02:00
|
|
|
/// extended and the intermediate bytes are left uninitialized.
|
|
|
|
///
|
|
|
|
/// Note that similar to `File::write`, it is not an error to return a
|
|
|
|
/// short write. When returning from such a short write, the file pointer
|
|
|
|
/// is still updated.
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-05 20:35:35 -05:00
|
|
|
/// use std::fs::File;
|
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
|
|
|
/// let mut buffer = File::create("foo.txt")?;
|
|
|
|
///
|
|
|
|
/// // Write a byte string starting 72 bytes from
|
|
|
|
/// // the start of the file.
|
2017-05-07 10:35:45 -05:00
|
|
|
/// buffer.seek_write(b"some bytes", 72)?;
|
2017-05-05 20:35:35 -05:00
|
|
|
/// # Ok(())
|
|
|
|
/// # }
|
|
|
|
/// ```
|
2016-12-14 11:35:05 -08:00
|
|
|
#[stable(feature = "file_offset", since = "1.15.0")]
|
2016-08-16 01:11:33 +02:00
|
|
|
fn seek_write(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
|
|
|
|
}
|
|
|
|
|
2016-12-14 11:35:05 -08:00
|
|
|
#[stable(feature = "file_offset", since = "1.15.0")]
|
2016-08-16 01:11:33 +02:00
|
|
|
impl FileExt for fs::File {
|
|
|
|
fn seek_read(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
|
|
|
|
self.as_inner().read_at(buf, offset)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn seek_write(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
|
|
|
|
self.as_inner().write_at(buf, offset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:05:47 -05:00
|
|
|
/// Windows-specific extensions to [`OpenOptions`].
|
|
|
|
///
|
|
|
|
/// [`OpenOptions`]: ../../../fs/struct.OpenOptions.html
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub trait OpenOptionsExt {
|
2017-05-05 20:35:35 -05:00
|
|
|
/// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`]
|
2015-04-15 23:21:13 -07:00
|
|
|
/// with the specified value.
|
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// This will override the `read`, `write`, and `append` flags on the
|
2016-01-15 19:04:53 +01:00
|
|
|
/// `OpenOptions` structure. This method provides fine-grained control over
|
|
|
|
/// the permissions to read, write and append data, attributes (like hidden
|
2017-05-05 20:35:35 -05:00
|
|
|
/// and system), and extended attributes.
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
|
|
|
/// # Examples
|
2015-04-15 23:21:13 -07:00
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// ```no_run
|
|
|
|
/// use std::fs::OpenOptions;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
2016-01-15 19:04:53 +01:00
|
|
|
/// // Open without read and write permission, for example if you only need
|
2017-05-18 21:10:15 -05:00
|
|
|
/// // to call `stat` on the file
|
2016-01-13 18:08:08 +01:00
|
|
|
/// let file = OpenOptions::new().access_mode(0).open("foo.txt");
|
|
|
|
/// ```
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
2016-01-13 18:08:08 +01:00
|
|
|
fn access_mode(&mut self, access: u32) -> &mut Self;
|
2015-04-15 23:21:13 -07:00
|
|
|
|
2017-05-05 20:35:35 -05:00
|
|
|
/// Overrides the `dwShareMode` argument to the call to [`CreateFile`] with
|
2015-04-15 23:21:13 -07:00
|
|
|
/// the specified value.
|
|
|
|
///
|
2016-01-15 19:04:53 +01:00
|
|
|
/// By default `share_mode` is set to
|
2017-05-05 20:35:35 -05:00
|
|
|
/// `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`. This allows
|
|
|
|
/// other processes to to read, write, and delete/rename the same file
|
|
|
|
/// while it is open. Removing any of the flags will prevent other
|
|
|
|
/// processes from performing the corresponding operation until the file
|
|
|
|
/// handle is closed.
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// use std::fs::OpenOptions;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
2016-01-15 19:04:53 +01:00
|
|
|
/// // Do not allow others to read or modify this file while we have it open
|
2017-05-05 20:35:35 -05:00
|
|
|
/// // for writing.
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let file = OpenOptions::new()
|
|
|
|
/// .write(true)
|
|
|
|
/// .share_mode(0)
|
|
|
|
/// .open("foo.txt");
|
2016-01-13 18:08:08 +01:00
|
|
|
/// ```
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
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
|
|
|
|
2016-01-15 19:04:53 +01:00
|
|
|
/// Sets extra flags for the `dwFileFlags` argument to the call to
|
2017-05-05 20:35:35 -05:00
|
|
|
/// [`CreateFile2`] to the specified value (or combines it with
|
|
|
|
/// `attributes` and `security_qos_flags` to set the `dwFlagsAndAttributes`
|
|
|
|
/// for [`CreateFile`]).
|
2016-01-13 21:47:46 +01:00
|
|
|
///
|
2017-05-05 20:35:35 -05:00
|
|
|
/// Custom flags can only set flags, not remove flags set by Rust's options.
|
|
|
|
/// This option overwrites any previously set custom flags.
|
2016-01-13 21:47:46 +01:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-06-20 15:15:16 +08:00
|
|
|
/// ```no_run
|
|
|
|
/// # #[cfg(for_demonstration_only)]
|
2016-01-13 21:47:46 +01:00
|
|
|
/// extern crate winapi;
|
2017-06-20 15:15:16 +08:00
|
|
|
/// # mod winapi { pub const FILE_FLAG_DELETE_ON_CLOSE: u32 = 0x04000000; }
|
2017-05-18 21:10:15 -05:00
|
|
|
///
|
2016-01-13 21:47:46 +01:00
|
|
|
/// use std::fs::OpenOptions;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
2016-01-13 21:47:46 +01:00
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let file = OpenOptions::new()
|
|
|
|
/// .create(true)
|
|
|
|
/// .write(true)
|
|
|
|
/// .custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE)
|
|
|
|
/// .open("foo.txt");
|
2016-01-13 21:47:46 +01:00
|
|
|
/// ```
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
|
|
|
|
/// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
2016-01-13 21:47:46 +01:00
|
|
|
fn custom_flags(&mut self, flags: u32) -> &mut Self;
|
|
|
|
|
2017-05-05 20:35:35 -05:00
|
|
|
/// Sets the `dwFileAttributes` argument to the call to [`CreateFile2`] to
|
2016-01-13 18:08:08 +01:00
|
|
|
/// the specified value (or combines it with `custom_flags` and
|
2016-01-15 19:04:53 +01:00
|
|
|
/// `security_qos_flags` to set the `dwFlagsAndAttributes` for
|
2017-05-05 20:35:35 -05:00
|
|
|
/// [`CreateFile`]).
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
2016-01-15 19:04:53 +01:00
|
|
|
/// If a _new_ file is created because it does not yet exist and
|
2017-04-06 12:57:40 +01:00
|
|
|
/// `.create(true)` or `.create_new(true)` are specified, the new file is
|
2016-01-15 19:04:53 +01:00
|
|
|
/// given the attributes declared with `.attributes()`.
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
|
|
|
/// If an _existing_ file is opened with `.create(true).truncate(true)`, its
|
2016-01-15 19:04:53 +01:00
|
|
|
/// existing attributes are preserved and combined with the ones declared
|
|
|
|
/// with `.attributes()`.
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
|
|
|
/// In all other cases the attributes get ignored.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-06-20 15:15:16 +08:00
|
|
|
/// ```no_run
|
|
|
|
/// # #[cfg(for_demonstration_only)]
|
2016-01-13 18:08:08 +01:00
|
|
|
/// extern crate winapi;
|
2017-06-20 15:15:16 +08:00
|
|
|
/// # mod winapi { pub const FILE_ATTRIBUTE_HIDDEN: u32 = 2; }
|
2017-05-18 21:10:15 -05:00
|
|
|
///
|
2016-01-13 18:08:08 +01:00
|
|
|
/// use std::fs::OpenOptions;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
2016-01-13 18:08:08 +01:00
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let file = OpenOptions::new()
|
|
|
|
/// .write(true)
|
|
|
|
/// .create(true)
|
|
|
|
/// .attributes(winapi::FILE_ATTRIBUTE_HIDDEN)
|
|
|
|
/// .open("foo.txt");
|
2016-01-13 18:08:08 +01:00
|
|
|
/// ```
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
|
|
|
/// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
|
|
|
|
/// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
2016-01-13 18:08:08 +01:00
|
|
|
fn attributes(&mut self, val: u32) -> &mut Self;
|
|
|
|
|
2017-05-05 20:35:35 -05:00
|
|
|
/// Sets the `dwSecurityQosFlags` argument to the call to [`CreateFile2`] to
|
2016-01-13 18:08:08 +01:00
|
|
|
/// the specified value (or combines it with `custom_flags` and `attributes`
|
2017-05-05 20:35:35 -05:00
|
|
|
/// to set the `dwFlagsAndAttributes` for [`CreateFile`]).
|
|
|
|
///
|
|
|
|
/// By default, `security_qos_flags` is set to `SECURITY_ANONYMOUS`. For
|
|
|
|
/// information about possible values, see [Impersonation Levels] on the
|
|
|
|
/// Windows Dev Center site.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-05 20:35:35 -05:00
|
|
|
/// use std::fs::OpenOptions;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let file = OpenOptions::new()
|
|
|
|
/// .write(true)
|
|
|
|
/// .create(true)
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// // Sets the flag value to `SecurityIdentification`.
|
2017-05-19 07:29:52 -05:00
|
|
|
/// .security_qos_flags(1)
|
2017-05-05 20:35:35 -05:00
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// .open("foo.txt");
|
2017-05-05 20:35:35 -05:00
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
|
|
|
|
/// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx
|
2017-05-09 21:20:56 -05:00
|
|
|
/// [Impersonation Levels]:
|
|
|
|
/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
2016-01-13 18:08:08 +01:00
|
|
|
fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions;
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
2016-05-17 11:57:07 -07:00
|
|
|
#[stable(feature = "open_options_ext", since = "1.10.0")]
|
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
|
|
|
|
2016-01-13 21:47:46 +01:00
|
|
|
fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions {
|
|
|
|
self.as_inner_mut().custom_flags(flags); self
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2017-05-06 23:05:47 -05:00
|
|
|
/// Extension methods for [`fs::Metadata`] to access the raw fields contained
|
2015-04-15 23:21:13 -07:00
|
|
|
/// within.
|
2017-05-06 23:05:47 -05:00
|
|
|
///
|
|
|
|
/// The data members that this trait exposes correspond to the members
|
|
|
|
/// of the [`BY_HANDLE_FILE_INFORMATION`] structure.
|
|
|
|
///
|
|
|
|
/// [`fs::Metadata`]: ../../../fs/struct.Metadata.html
|
2017-05-09 21:20:56 -05:00
|
|
|
/// [`BY_HANDLE_FILE_INFORMATION`]:
|
|
|
|
/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx
|
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
|
2017-05-06 23:05:47 -05:00
|
|
|
/// or directory. For possible values and their descriptions, see
|
|
|
|
/// [File Attribute Constants] in the Windows Dev Center.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::io;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::fs;
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let metadata = fs::metadata("foo.txt")?;
|
|
|
|
/// let attributes = metadata.file_attributes();
|
|
|
|
/// # Ok(())
|
2017-05-06 23:05:47 -05:00
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
///
|
2017-05-09 21:20:56 -05:00
|
|
|
/// [File Attribute Constants]:
|
|
|
|
/// https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx
|
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.
|
|
|
|
///
|
2017-05-06 23:05:47 -05:00
|
|
|
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
|
|
|
|
/// which represents the number of 100-nanosecond intervals since
|
|
|
|
/// January 1, 1601 (UTC). The struct is automatically
|
|
|
|
/// converted to a `u64` value, as that is the recommended way
|
|
|
|
/// to use it.
|
|
|
|
///
|
|
|
|
/// If the underlying filesystem does not support creation time, the
|
|
|
|
/// returned value is 0.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::io;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::fs;
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let metadata = fs::metadata("foo.txt")?;
|
|
|
|
/// let creation_time = metadata.creation_time();
|
|
|
|
/// # Ok(())
|
2017-05-06 23:05:47 -05:00
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
|
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.
|
|
|
|
///
|
2017-05-06 23:05:47 -05:00
|
|
|
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
|
|
|
|
/// which represents the number of 100-nanosecond intervals since
|
|
|
|
/// January 1, 1601 (UTC). The struct is automatically
|
|
|
|
/// converted to a `u64` value, as that is the recommended way
|
|
|
|
/// to use it.
|
|
|
|
///
|
|
|
|
/// For a file, the value specifies the last time that a file was read
|
|
|
|
/// from or written to. For a directory, the value specifies when
|
|
|
|
/// the directory was created. For both files and directories, the
|
|
|
|
/// specified date is correct, but the time of day is always set to
|
|
|
|
/// midnight.
|
|
|
|
///
|
|
|
|
/// If the underlying filesystem does not support last access time, the
|
|
|
|
/// returned value is 0.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::io;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::fs;
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let metadata = fs::metadata("foo.txt")?;
|
|
|
|
/// let last_access_time = metadata.last_access_time();
|
|
|
|
/// # Ok(())
|
2017-05-06 23:05:47 -05:00
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
|
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.
|
|
|
|
///
|
2017-05-06 23:05:47 -05:00
|
|
|
/// The returned 64-bit value is equivalent to a [`FILETIME`] struct,
|
|
|
|
/// which represents the number of 100-nanosecond intervals since
|
|
|
|
/// January 1, 1601 (UTC). The struct is automatically
|
|
|
|
/// converted to a `u64` value, as that is the recommended way
|
|
|
|
/// to use it.
|
|
|
|
///
|
|
|
|
/// For a file, the value specifies the last time that a file was written
|
|
|
|
/// to. For a directory, the structure specifies when the directory was
|
|
|
|
/// created.
|
|
|
|
///
|
2017-10-17 00:19:25 +02:00
|
|
|
/// If the underlying filesystem does not support the last write time,
|
|
|
|
/// the returned value is 0.
|
2017-05-06 23:05:47 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::io;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::fs;
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let metadata = fs::metadata("foo.txt")?;
|
|
|
|
/// let last_write_time = metadata.last_write_time();
|
|
|
|
/// # Ok(())
|
2017-05-06 23:05:47 -05:00
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
|
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.
|
2017-05-06 23:05:47 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::io;
|
2017-05-18 21:10:15 -05:00
|
|
|
/// use std::fs;
|
2017-05-06 23:05:47 -05:00
|
|
|
/// use std::os::windows::prelude::*;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> io::Result<()> {
|
2017-05-18 21:10:15 -05:00
|
|
|
/// let metadata = fs::metadata("foo.txt")?;
|
|
|
|
/// let file_size = metadata.file_size();
|
|
|
|
/// # Ok(())
|
2017-05-06 23:05:47 -05:00
|
|
|
/// # }
|
|
|
|
/// ```
|
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() }
|
2016-01-12 17:24:16 -08:00
|
|
|
fn creation_time(&self) -> u64 { self.as_inner().created_u64() }
|
|
|
|
fn last_access_time(&self) -> u64 { self.as_inner().accessed_u64() }
|
|
|
|
fn last_write_time(&self) -> u64 { self.as_inner().modified_u64() }
|
2015-04-15 23:21:13 -07:00
|
|
|
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
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2015-04-15 23:21:13 -07:00
|
|
|
/// use std::os::windows::fs;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
2016-12-28 14:32:35 +05:30
|
|
|
/// fs::symlink_file("a.txt", "b.txt")?;
|
2015-04-15 23:21:13 -07:00
|
|
|
/// # 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
|
|
|
|
///
|
2017-05-18 21:10:15 -05:00
|
|
|
/// ```no_run
|
2015-04-15 23:21:13 -07:00
|
|
|
/// use std::os::windows::fs;
|
|
|
|
///
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
2017-07-13 11:14:35 -07:00
|
|
|
/// fs::symlink_dir("a", "b")?;
|
2015-04-15 23:21:13 -07:00
|
|
|
/// # 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
|
|
|
}
|