Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,27 @@ mod tests {
check!(fs::remove_file(&filename));
}

#[test]
#[cfg(unix)]
fn set_get_unix_permissions() {
use os::unix::fs::PermissionsExt;

let tmpdir = tmpdir();
let filename = &tmpdir.join("set_get_unix_permissions");
check!(fs::create_dir(filename));
let mask = 0o7777;

check!(fs::set_permissions(filename,
fs::Permissions::from_mode(0)));
let metadata0 = check!(fs::metadata(filename));
assert_eq!(mask & metadata0.permissions().mode(), 0);

check!(fs::set_permissions(filename,
fs::Permissions::from_mode(0o1777)));
let metadata1 = check!(fs::metadata(filename));
assert_eq!(mask & metadata1.permissions().mode(), 0o1777);
}

#[test]
#[cfg(windows)]
fn file_test_io_seek_read_write() {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl FileExt for fs::File {
/// Unix-specific extensions to `Permissions`
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait PermissionsExt {
/// Returns the underlying raw `mode_t` bits that are the standard Unix
/// permissions for this file.
/// Returns the underlying raw `st_mode` bits that contain the standard
/// Unix permissions for this file.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct DirBuilder { mode: mode_t }
impl FileAttr {
pub fn size(&self) -> u64 { self.stat.st_size as u64 }
pub fn perm(&self) -> FilePermissions {
FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 }
FilePermissions { mode: (self.stat.st_mode as mode_t) }
}

pub fn file_type(&self) -> FileType {
Expand Down