diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 5f91d173ed2ac..ef530a124214e 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -97,7 +97,7 @@ pub struct OpenOptions(fs_imp::OpenOptions); /// functionality, such as mode bits, is available through the /// `os::unix::PermissionsExt` trait. #[derive(Clone, PartialEq, Eq, Debug)] -pub struct Permissions(fs_imp::FilePermissions); +pub struct Permissions(fs_imp::Permissions); impl File { /// Attempts to open a file in read-only mode. @@ -319,8 +319,8 @@ impl Permissions { } } -impl FromInner for Permissions { - fn from_inner(f: fs_imp::FilePermissions) -> Permissions { +impl FromInner for Permissions { + fn from_inner(f: fs_imp::Permissions) -> Permissions { Permissions(f) } } @@ -521,7 +521,15 @@ pub fn read_link(path: &P) -> io::Result { /// This function will return an error if the user lacks permissions to make a /// new directory at the provided `path`, or if the directory already exists. pub fn create_dir(path: &P) -> io::Result<()> { - fs_imp::mkdir(path.as_path()) + #[cfg(windows)] + fn mkdir(path: &Path) -> io::Result<()> { + fs_imp::mkdir(path) + } + #[cfg(unix)] + fn mkdir(path: &Path) -> io::Result<()> { + fs_imp::mkdir(path, FromInner::from_inner(0o777)) + } + mkdir(path.as_path()) } /// Recursively create a directory and all of its parent components if they diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index e5904b074bcb9..b847aa9c63e98 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -50,7 +50,7 @@ pub struct OpenOptions { } #[derive(Clone, PartialEq, Eq, Debug)] -pub struct FilePermissions { mode: mode_t } +pub struct Permissions { mode: mode_t } impl FileAttr { pub fn is_dir(&self) -> bool { @@ -60,8 +60,8 @@ impl FileAttr { (self.stat.st_mode as mode_t) & libc::S_IFMT == libc::S_IFREG } 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 } + pub fn perm(&self) -> Permissions { + Permissions { mode: (self.stat.st_mode as mode_t) & 0o777 } } pub fn accessed(&self) -> u64 { @@ -77,7 +77,7 @@ impl FileAttr { } } -impl FilePermissions { +impl Permissions { pub fn readonly(&self) -> bool { self.mode & 0o222 == 0 } pub fn set_readonly(&mut self, readonly: bool) { if readonly { @@ -88,9 +88,9 @@ impl FilePermissions { } } -impl FromInner for FilePermissions { - fn from_inner(mode: i32) -> FilePermissions { - FilePermissions { mode: mode as mode_t } +impl FromInner for Permissions { + fn from_inner(mode: i32) -> Permissions { + Permissions { mode: mode as mode_t } } } @@ -272,9 +272,9 @@ fn cstr(path: &Path) -> CString { CString::from_slice(path.as_os_str().as_bytes()) } -pub fn mkdir(p: &Path) -> io::Result<()> { +pub fn mkdir(p: &Path, perms: Permissions) -> io::Result<()> { let p = cstr(p); - try!(cvt(unsafe { libc::mkdir(p.as_ptr(), 0o777) })); + try!(cvt(unsafe { libc::mkdir(p.as_ptr(), perms.mode) })); Ok(()) } @@ -304,7 +304,7 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> { Ok(()) } -pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { +pub fn set_perm(p: &Path, perm: Permissions) -> io::Result<()> { let p = cstr(p); try!(cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) })); Ok(()) diff --git a/src/libstd/sys/windows/fs2.rs b/src/libstd/sys/windows/fs2.rs index 8abcd90efe857..86112e0ac8dc1 100644 --- a/src/libstd/sys/windows/fs2.rs +++ b/src/libstd/sys/windows/fs2.rs @@ -48,7 +48,7 @@ pub struct OpenOptions { } #[derive(Clone, PartialEq, Eq, Debug)] -pub struct FilePermissions { attrs: libc::DWORD } +pub struct Permissions { attrs: libc::DWORD } impl Iterator for ReadDir { type Item = io::Result; @@ -266,8 +266,8 @@ impl FileAttr { pub fn size(&self) -> u64 { ((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64) } - pub fn perm(&self) -> FilePermissions { - FilePermissions { attrs: self.data.dwFileAttributes } + pub fn perm(&self) -> Permissions { + Permissions { attrs: self.data.dwFileAttributes } } pub fn accessed(&self) -> u64 { self.to_ms(&self.data.ftLastAccessTime) } @@ -281,7 +281,7 @@ impl FileAttr { } } -impl FilePermissions { +impl Permissions { pub fn readonly(&self) -> bool { self.attrs & c::FILE_ATTRIBUTE_READONLY != 0 } @@ -390,7 +390,7 @@ pub fn stat(p: &Path) -> io::Result { } } -pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { +pub fn set_perm(p: &Path, perm: Permissions) -> io::Result<()> { let p = to_utf16(p); unsafe { try!(cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs)));