Replace unstable fs_mode by internal constants

This commit is contained in:
Florian Gilcher 2015-11-04 09:51:34 +01:00
parent 679b9e18b2
commit b3e3825417
2 changed files with 45 additions and 12 deletions

View File

@ -4,7 +4,7 @@ use std::ascii::AsciiExt;
use std::env::current_dir;
use std::fs;
use std::io;
use std::os::unix;
use std::os::unix::raw;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::{Component, Path, PathBuf};
@ -15,6 +15,39 @@ use options::TimeType;
use self::fields as f;
// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259
// which is currently unstable and lacks vision for stabilization,
// see https://github.com/rust-lang/rust/issues/27712
const USER_READ: raw::mode_t = 0o400;
const USER_WRITE: raw::mode_t = 0o200;
const USER_EXECUTE: raw::mode_t = 0o100;
#[allow(dead_code)]
const USER_RWX: raw::mode_t = 0o700;
const GROUP_READ: raw::mode_t = 0o040;
const GROUP_WRITE: raw::mode_t = 0o020;
const GROUP_EXECUTE: raw::mode_t = 0o010;
#[allow(dead_code)]
const GROUP_RWX: raw::mode_t = 0o070;
const OTHER_READ: raw::mode_t = 0o004;
const OTHER_WRITE: raw::mode_t = 0o002;
const OTHER_EXECUTE: raw::mode_t = 0o001;
#[allow(dead_code)]
const OTHER_RWX: raw::mode_t = 0o007;
#[allow(dead_code)]
const ALL_READ: raw::mode_t = 0o444;
#[allow(dead_code)]
const ALL_WRITE: raw::mode_t = 0o222;
#[allow(dead_code)]
const ALL_EXECUTE: raw::mode_t = 0o111;
#[allow(dead_code)]
const ALL_RWX: raw::mode_t = 0o777;
#[allow(dead_code)]
const SETUID: raw::mode_t = 0o4000;
#[allow(dead_code)]
const SETGID: raw::mode_t = 0o2000;
#[allow(dead_code)]
const STICKY_BIT: raw::mode_t = 0o1000;
/// A **File** is a wrapper around one of Rust's Path objects, along with
/// associated data about the file.
@ -104,7 +137,7 @@ impl<'dir> File<'dir> {
/// current user. Executable files have different semantics than
/// executable directories, and so should be highlighted differently.
pub fn is_executable_file(&self) -> bool {
let bit = unix::fs::USER_EXECUTE;
let bit = USER_EXECUTE;
self.is_file() && (self.metadata.permissions().mode() & bit) == bit
}
@ -299,15 +332,15 @@ impl<'dir> File<'dir> {
f::Permissions {
file_type: self.type_char(),
user_read: has_bit(unix::fs::USER_READ),
user_write: has_bit(unix::fs::USER_WRITE),
user_execute: has_bit(unix::fs::USER_EXECUTE),
group_read: has_bit(unix::fs::GROUP_READ),
group_write: has_bit(unix::fs::GROUP_WRITE),
group_execute: has_bit(unix::fs::GROUP_EXECUTE),
other_read: has_bit(unix::fs::OTHER_READ),
other_write: has_bit(unix::fs::OTHER_WRITE),
other_execute: has_bit(unix::fs::OTHER_EXECUTE),
user_read: has_bit(USER_READ),
user_write: has_bit(USER_WRITE),
user_execute: has_bit(USER_EXECUTE),
group_read: has_bit(GROUP_READ),
group_write: has_bit(GROUP_WRITE),
group_execute: has_bit(GROUP_EXECUTE),
other_read: has_bit(OTHER_READ),
other_write: has_bit(OTHER_WRITE),
other_execute: has_bit(OTHER_EXECUTE),
}
}

View File

@ -1,4 +1,4 @@
#![feature(convert, fs_mode)]
#![feature(convert)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused_extern_crates, unused_qualifications)]