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.
|
|
|
|
|
|
|
|
|
|
//! Unix-specific extensions to primitives in the `std::fs` module.
|
|
|
|
|
|
|
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
|
|
|
|
|
use fs::{self, Permissions, OpenOptions};
|
|
|
|
|
use io;
|
2015-07-05 23:16:25 +02:00
|
|
|
use libc;
|
2015-04-15 23:21:13 -07:00
|
|
|
use os::raw::c_long;
|
|
|
|
|
use os::unix::raw;
|
|
|
|
|
use path::Path;
|
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
|
|
|
use sys::fs::MetadataExt as UnixMetadataExt;
|
2015-04-15 23:21:13 -07:00
|
|
|
use sys;
|
|
|
|
|
use sys_common::{FromInner, AsInner, AsInnerMut};
|
|
|
|
|
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const USER_READ: raw::mode_t = 0o400;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const USER_WRITE: raw::mode_t = 0o200;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const USER_EXECUTE: raw::mode_t = 0o100;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const USER_RWX: raw::mode_t = 0o700;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const GROUP_READ: raw::mode_t = 0o040;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const GROUP_WRITE: raw::mode_t = 0o020;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const GROUP_EXECUTE: raw::mode_t = 0o010;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const GROUP_RWX: raw::mode_t = 0o070;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const OTHER_READ: raw::mode_t = 0o004;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const OTHER_WRITE: raw::mode_t = 0o002;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const OTHER_EXECUTE: raw::mode_t = 0o001;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const OTHER_RWX: raw::mode_t = 0o007;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const ALL_READ: raw::mode_t = 0o444;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const ALL_WRITE: raw::mode_t = 0o222;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const ALL_EXECUTE: raw::mode_t = 0o111;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const ALL_RWX: raw::mode_t = 0o777;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const SETUID: raw::mode_t = 0o4000;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const SETGID: raw::mode_t = 0o2000;
|
2015-08-13 10:12:38 -07:00
|
|
|
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub const STICKY_BIT: raw::mode_t = 0o1000;
|
|
|
|
|
|
|
|
|
|
/// Unix-specific extensions to `Permissions`
|
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 = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub trait PermissionsExt {
|
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
|
|
|
/// Returns the underlying raw `mode_t` bits that are the standard Unix
|
|
|
|
|
/// permissions for this file.
|
|
|
|
|
#[stable(feature = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn mode(&self) -> raw::mode_t;
|
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
|
|
|
|
|
|
|
|
/// Sets the underlying raw `mode_t` bits for this set of permissions.
|
|
|
|
|
#[stable(feature = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn set_mode(&mut self, mode: raw::mode_t);
|
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
|
|
|
|
|
|
|
|
/// Creates a new instance of `Permissions` from the given set of Unix
|
|
|
|
|
/// permission bits.
|
|
|
|
|
#[stable(feature = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn from_mode(mode: raw::mode_t) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
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 = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
impl PermissionsExt for Permissions {
|
|
|
|
|
fn mode(&self) -> raw::mode_t { self.as_inner().mode() }
|
|
|
|
|
|
|
|
|
|
fn set_mode(&mut self, mode: raw::mode_t) {
|
|
|
|
|
*self = FromInner::from_inner(FromInner::from_inner(mode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_mode(mode: raw::mode_t) -> Permissions {
|
|
|
|
|
FromInner::from_inner(FromInner::from_inner(mode))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Unix-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
|
|
|
#[stable(feature = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub trait OpenOptionsExt {
|
|
|
|
|
/// Sets the mode bits that a new file will be created with.
|
|
|
|
|
///
|
|
|
|
|
/// If a new file is created as part of a `File::open_opts` call then this
|
|
|
|
|
/// specified `mode` will be used as the permission bits for the new file.
|
2016-01-13 18:08:08 +01:00
|
|
|
/// If no `mode` is set, the default of `0o666` will be used.
|
|
|
|
|
/// The operating system masks out bits with the systems `umask`, to produce
|
|
|
|
|
/// the final permissions.
|
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 = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn mode(&mut self, mode: raw::mode_t) -> &mut Self;
|
2016-01-13 21:47:46 +01:00
|
|
|
|
|
|
|
|
/// Pass custom flags to the `flags` agument of `open`.
|
|
|
|
|
///
|
|
|
|
|
/// The bits that define the access mode are masked out with `O_ACCMODE`, to ensure
|
|
|
|
|
/// they do not interfere with the access mode set by Rusts options.
|
|
|
|
|
///
|
|
|
|
|
/// Custom flags can only set flags, not remove flags set by Rusts options.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
2016-01-14 16:59:28 +01:00
|
|
|
/// ```rust,ignore
|
2016-01-13 21:47:46 +01:00
|
|
|
/// extern crate libc;
|
|
|
|
|
/// use std::fs::OpenOptions;
|
|
|
|
|
/// use std::os::unix::fs::OpenOptionsExt;
|
|
|
|
|
///
|
2016-01-14 16:59:28 +01:00
|
|
|
/// let mut options = OpenOptions::new();
|
|
|
|
|
/// options.write(true);
|
2016-01-13 21:47:46 +01:00
|
|
|
/// if cfg!(unix) { options.custom_flags(libc::O_NOFOLLOW); }
|
|
|
|
|
/// let file = options.open("foo.txt");
|
|
|
|
|
/// ```
|
|
|
|
|
#[unstable(feature = "expand_open_options",
|
|
|
|
|
reason = "recently added",
|
|
|
|
|
issue = "30014")]
|
|
|
|
|
fn custom_flags(&mut self, flags: i32) -> &mut Self;
|
2015-04-15 23:21:13 -07: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 = "fs_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
impl OpenOptionsExt for OpenOptions {
|
|
|
|
|
fn mode(&mut self, mode: raw::mode_t) -> &mut OpenOptions {
|
|
|
|
|
self.as_inner_mut().mode(mode); self
|
|
|
|
|
}
|
2016-01-13 21:47:46 +01:00
|
|
|
|
|
|
|
|
fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
|
|
|
|
|
self.as_inner_mut().custom_flags(flags); self
|
|
|
|
|
}
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hm, why are there casts here to the returned type, shouldn't the types always
|
|
|
|
|
// be the same? Right you are! Turns out, however, on android at least the types
|
|
|
|
|
// in the raw `stat` structure are not the same as the types being returned. Who
|
|
|
|
|
// knew!
|
|
|
|
|
//
|
|
|
|
|
// As a result to make sure this compiles for all platforms we do the manual
|
|
|
|
|
// casts and rely on manual lowering to `stat` if the raw type is desired.
|
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")]
|
|
|
|
|
pub trait MetadataExt {
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn dev(&self) -> raw::dev_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn ino(&self) -> raw::ino_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn mode(&self) -> raw::mode_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn nlink(&self) -> raw::nlink_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn uid(&self) -> raw::uid_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn gid(&self) -> raw::gid_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn rdev(&self) -> raw::dev_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn size(&self) -> raw::off_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn atime(&self) -> raw::time_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn atime_nsec(&self) -> c_long;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn mtime(&self) -> raw::time_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn mtime_nsec(&self) -> c_long;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn ctime(&self) -> raw::time_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn ctime_nsec(&self) -> c_long;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn blksize(&self) -> raw::blksize_t;
|
|
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
|
|
|
|
fn blocks(&self) -> raw::blkcnt_t;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 19:54:28 +03:00
|
|
|
#[stable(feature = "metadata_ext", since = "1.1.0")]
|
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
|
|
|
impl MetadataExt for fs::Metadata {
|
|
|
|
|
fn dev(&self) -> raw::dev_t { self.as_raw_stat().st_dev as raw::dev_t }
|
|
|
|
|
fn ino(&self) -> raw::ino_t { self.as_raw_stat().st_ino as raw::ino_t }
|
|
|
|
|
fn mode(&self) -> raw::mode_t { self.as_raw_stat().st_mode as raw::mode_t }
|
|
|
|
|
fn nlink(&self) -> raw::nlink_t { self.as_raw_stat().st_nlink as raw::nlink_t }
|
|
|
|
|
fn uid(&self) -> raw::uid_t { self.as_raw_stat().st_uid as raw::uid_t }
|
|
|
|
|
fn gid(&self) -> raw::gid_t { self.as_raw_stat().st_gid as raw::gid_t }
|
|
|
|
|
fn rdev(&self) -> raw::dev_t { self.as_raw_stat().st_rdev as raw::dev_t }
|
|
|
|
|
fn size(&self) -> raw::off_t { self.as_raw_stat().st_size as raw::off_t }
|
|
|
|
|
fn atime(&self) -> raw::time_t { self.as_raw_stat().st_atime }
|
|
|
|
|
fn atime_nsec(&self) -> c_long { self.as_raw_stat().st_atime_nsec as c_long }
|
|
|
|
|
fn mtime(&self) -> raw::time_t { self.as_raw_stat().st_mtime }
|
|
|
|
|
fn mtime_nsec(&self) -> c_long { self.as_raw_stat().st_mtime_nsec as c_long }
|
|
|
|
|
fn ctime(&self) -> raw::time_t { self.as_raw_stat().st_ctime }
|
|
|
|
|
fn ctime_nsec(&self) -> c_long { self.as_raw_stat().st_ctime_nsec as c_long }
|
|
|
|
|
|
|
|
|
|
fn blksize(&self) -> raw::blksize_t {
|
|
|
|
|
self.as_raw_stat().st_blksize as raw::blksize_t
|
2015-04-15 23:21:13 -07: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
|
|
|
fn blocks(&self) -> raw::blkcnt_t {
|
|
|
|
|
self.as_raw_stat().st_blocks as raw::blkcnt_t
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 23:16:25 +02:00
|
|
|
/// Add special unix types (block/char device, fifo and socket)
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
pub trait FileTypeExt {
|
|
|
|
|
/// Returns whether this file type is a block device.
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
fn is_block_device(&self) -> bool;
|
|
|
|
|
/// Returns whether this file type is a char device.
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
fn is_char_device(&self) -> bool;
|
|
|
|
|
/// Returns whether this file type is a fifo.
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
fn is_fifo(&self) -> bool;
|
|
|
|
|
/// Returns whether this file type is a socket.
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
fn is_socket(&self) -> bool;
|
|
|
|
|
}
|
|
|
|
|
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#[stable(feature = "file_type_ext", since = "1.5.0")]
|
2015-07-05 23:16:25 +02:00
|
|
|
impl FileTypeExt for fs::FileType {
|
|
|
|
|
fn is_block_device(&self) -> bool { self.as_inner().is(libc::S_IFBLK) }
|
|
|
|
|
fn is_char_device(&self) -> bool { self.as_inner().is(libc::S_IFCHR) }
|
|
|
|
|
fn is_fifo(&self) -> bool { self.as_inner().is(libc::S_IFIFO) }
|
|
|
|
|
fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) }
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Unix-specific extension methods for `fs::DirEntry`
|
|
|
|
|
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
pub trait DirEntryExt {
|
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
|
|
|
/// Returns the underlying `d_ino` field in the contained `dirent`
|
|
|
|
|
/// structure.
|
|
|
|
|
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
fn ino(&self) -> raw::ino_t;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 19:54:28 +03:00
|
|
|
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
|
2015-04-15 23:21:13 -07:00
|
|
|
impl DirEntryExt for fs::DirEntry {
|
|
|
|
|
fn ino(&self) -> raw::ino_t { self.as_inner().ino() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Creates a new symbolic link on the filesystem.
|
|
|
|
|
///
|
|
|
|
|
/// The `dst` path will be a symbolic link pointing to the `src` path.
|
|
|
|
|
///
|
|
|
|
|
/// # Note
|
|
|
|
|
///
|
|
|
|
|
/// On Windows, you must specify whether a symbolic link points to a file
|
|
|
|
|
/// or directory. Use `os::windows::fs::symlink_file` to create a
|
|
|
|
|
/// symbolic link to a file, or `os::windows::fs::symlink_dir` to create a
|
|
|
|
|
/// symbolic link to a directory. Additionally, the process must have
|
|
|
|
|
/// `SeCreateSymbolicLinkPrivilege` in order to be able to create a
|
|
|
|
|
/// symbolic link.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::os::unix::fs;
|
|
|
|
|
///
|
|
|
|
|
/// # fn foo() -> std::io::Result<()> {
|
|
|
|
|
/// try!(fs::symlink("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<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
|
|
|
|
|
{
|
2015-05-05 16:35:15 -07:00
|
|
|
sys::fs::symlink(src.as_ref(), dst.as_ref())
|
2015-04-15 23:21:13 -07:00
|
|
|
}
|
2015-04-27 17:29:35 -07:00
|
|
|
|
2015-12-02 17:31:49 -08:00
|
|
|
#[stable(feature = "dir_builder", since = "1.6.0")]
|
2015-04-27 17:29:35 -07:00
|
|
|
/// An extension trait for `fs::DirBuilder` for unix-specific options.
|
|
|
|
|
pub trait DirBuilderExt {
|
|
|
|
|
/// Sets the mode to create new directories with. This option defaults to
|
|
|
|
|
/// 0o777.
|
2015-12-02 17:31:49 -08:00
|
|
|
#[stable(feature = "dir_builder", since = "1.6.0")]
|
2015-04-27 17:29:35 -07:00
|
|
|
fn mode(&mut self, mode: raw::mode_t) -> &mut Self;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 17:31:49 -08:00
|
|
|
#[stable(feature = "dir_builder", since = "1.6.0")]
|
2015-04-27 17:29:35 -07:00
|
|
|
impl DirBuilderExt for fs::DirBuilder {
|
|
|
|
|
fn mode(&mut self, mode: raw::mode_t) -> &mut fs::DirBuilder {
|
|
|
|
|
self.as_inner_mut().set_mode(mode);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|