Skip to content

Commit 6d8b5c9

Browse files
committedSep 4, 2014
auto merge of #16976 : treeman/rust/issue-16943, r=kballard
Closes #16943.
2 parents 85e2e5a + 38bf999 commit 6d8b5c9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
 

‎src/libstd/io/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ mod test {
12741274

12751275
error!(result, "couldn't recursively mkdir");
12761276
error!(result, "couldn't create directory");
1277-
error!(result, "mode=FilePermission { bits: 448 }");
1277+
error!(result, "mode=0700");
12781278
error!(result, format!("path={}", file.display()));
12791279
})
12801280

‎src/libstd/io/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,6 @@ pub struct UnstableFileStat {
17971797
bitflags!(
17981798
#[doc="A set of permissions for a file or directory is represented
17991799
by a set of flags which are or'd together."]
1800-
#[deriving(Show)]
18011800
flags FilePermission: u32 {
18021801
static UserRead = 0o400,
18031802
static UserWrite = 0o200,
@@ -1836,6 +1835,14 @@ impl Default for FilePermission {
18361835
fn default() -> FilePermission { FilePermission::empty() }
18371836
}
18381837

1838+
impl fmt::Show for FilePermission {
1839+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1840+
formatter.fill = '0';
1841+
formatter.width = Some(4);
1842+
(&self.bits as &fmt::Octal).fmt(formatter)
1843+
}
1844+
}
1845+
18391846
#[cfg(test)]
18401847
mod tests {
18411848
use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput};
@@ -1937,4 +1944,18 @@ mod tests {
19371944
let mut r = MemReader::new(Vec::from_slice(b"hello, world!"));
19381945
assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput);
19391946
}
1947+
1948+
#[test]
1949+
fn test_show() {
1950+
use super::*;
1951+
1952+
assert_eq!(format!("{}", UserRead), "0400".to_string());
1953+
assert_eq!(format!("{}", UserFile), "0644".to_string());
1954+
assert_eq!(format!("{}", UserExec), "0755".to_string());
1955+
assert_eq!(format!("{}", UserRWX), "0700".to_string());
1956+
assert_eq!(format!("{}", GroupRWX), "0070".to_string());
1957+
assert_eq!(format!("{}", OtherRWX), "0007".to_string());
1958+
assert_eq!(format!("{}", AllPermissions), "0777".to_string());
1959+
assert_eq!(format!("{}", UserRead | UserWrite | OtherWrite), "0602".to_string());
1960+
}
19401961
}

0 commit comments

Comments
 (0)