Skip to content

Commit

Permalink
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions src/libnative/io/file_unix.rs
Expand Up @@ -154,7 +154,7 @@ impl rtio::RtioFileStream for FileDesc {

fn fstat(&mut self) -> IoResult<rtio::FileStat> {
let mut stat: libc::stat = unsafe { mem::zeroed() };
match retry(|| unsafe { libc::fstat(self.fd(), &mut stat) }) {
match unsafe { libc::fstat(self.fd(), &mut stat) } {
0 => Ok(mkstat(&stat)),
_ => Err(super::last_error()),
}
Expand Down Expand Up @@ -346,9 +346,7 @@ pub fn open(path: &CString, fm: rtio::FileMode, fa: rtio::FileAccess)
}

pub fn mkdir(p: &CString, mode: uint) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe {
libc::mkdir(p.as_ptr(), mode as libc::mode_t)
}))
super::mkerr_libc(unsafe { libc::mkdir(p.as_ptr(), mode as libc::mode_t) })
}

pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
Expand Down Expand Up @@ -393,13 +391,11 @@ pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
}

pub fn unlink(p: &CString) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe { libc::unlink(p.as_ptr()) }))
super::mkerr_libc(unsafe { libc::unlink(p.as_ptr()) })
}

pub fn rename(old: &CString, new: &CString) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe {
libc::rename(old.as_ptr(), new.as_ptr())
}))
super::mkerr_libc(unsafe { libc::rename(old.as_ptr(), new.as_ptr()) })
}

pub fn chmod(p: &CString, mode: uint) -> IoResult<()> {
Expand All @@ -409,9 +405,7 @@ pub fn chmod(p: &CString, mode: uint) -> IoResult<()> {
}

pub fn rmdir(p: &CString) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe {
libc::rmdir(p.as_ptr())
}))
super::mkerr_libc(unsafe { libc::rmdir(p.as_ptr()) })
}

pub fn chown(p: &CString, uid: int, gid: int) -> IoResult<()> {
Expand All @@ -428,10 +422,10 @@ pub fn readlink(p: &CString) -> IoResult<CString> {
len = 1024; // FIXME: read PATH_MAX from C ffi?
}
let mut buf: Vec<u8> = Vec::with_capacity(len as uint);
match retry(|| unsafe {
match unsafe {
libc::readlink(p, buf.as_ptr() as *mut libc::c_char,
len as libc::size_t) as libc::c_int
}) {
} {
-1 => Err(super::last_error()),
n => {
assert!(n > 0);
Expand All @@ -442,15 +436,11 @@ pub fn readlink(p: &CString) -> IoResult<CString> {
}

pub fn symlink(src: &CString, dst: &CString) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe {
libc::symlink(src.as_ptr(), dst.as_ptr())
}))
super::mkerr_libc(unsafe { libc::symlink(src.as_ptr(), dst.as_ptr()) })
}

pub fn link(src: &CString, dst: &CString) -> IoResult<()> {
super::mkerr_libc(retry(|| unsafe {
libc::link(src.as_ptr(), dst.as_ptr())
}))
super::mkerr_libc(unsafe { libc::link(src.as_ptr(), dst.as_ptr()) })
}

fn mkstat(stat: &libc::stat) -> rtio::FileStat {
Expand Down Expand Up @@ -489,15 +479,15 @@ fn mkstat(stat: &libc::stat) -> rtio::FileStat {

pub fn stat(p: &CString) -> IoResult<rtio::FileStat> {
let mut stat: libc::stat = unsafe { mem::zeroed() };
match retry(|| unsafe { libc::stat(p.as_ptr(), &mut stat) }) {
match unsafe { libc::stat(p.as_ptr(), &mut stat) } {
0 => Ok(mkstat(&stat)),
_ => Err(super::last_error()),
}
}

pub fn lstat(p: &CString) -> IoResult<rtio::FileStat> {
let mut stat: libc::stat = unsafe { mem::zeroed() };
match retry(|| unsafe { libc::lstat(p.as_ptr(), &mut stat) }) {
match unsafe { libc::lstat(p.as_ptr(), &mut stat) } {
0 => Ok(mkstat(&stat)),
_ => Err(super::last_error()),
}
Expand All @@ -508,9 +498,7 @@ pub fn utime(p: &CString, atime: u64, mtime: u64) -> IoResult<()> {
actime: (atime / 1000) as libc::time_t,
modtime: (mtime / 1000) as libc::time_t,
};
super::mkerr_libc(retry(|| unsafe {
libc::utime(p.as_ptr(), &buf)
}))
super::mkerr_libc(unsafe { libc::utime(p.as_ptr(), &buf) })
}

#[cfg(test)]
Expand Down

5 comments on commit d90921a

@bors
Copy link
Contributor

@bors bors commented on d90921a Sep 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at nodakai@d90921a

@bors
Copy link
Contributor

@bors bors commented on d90921a Sep 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nodakai/rust/libnative-superfluous-retry = d90921a into auto

@bors
Copy link
Contributor

@bors bors commented on d90921a Sep 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodakai/rust/libnative-superfluous-retry = d90921a merged ok, testing candidate = 85e2e5a

@bors
Copy link
Contributor

@bors bors commented on d90921a Sep 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 85e2e5a

Please sign in to comment.