]> git.lizzy.rs Git - rust.git/commitdiff
Fix readdir
authorJeremy Soller <jackpot51@gmail.com>
Fri, 11 Nov 2016 02:58:19 +0000 (19:58 -0700)
committerJeremy Soller <jackpot51@gmail.com>
Fri, 11 Nov 2016 02:58:19 +0000 (19:58 -0700)
src/libstd/sys/redox/fs.rs

index 3779c4c66775eaaef89899aa71b9703d1ed4f0e4..1a96ac2f2eabd591fefacd7b0f4d082c2369a41e 100644 (file)
@@ -146,16 +146,17 @@ impl Iterator for ReadDir {
     fn next(&mut self) -> Option<io::Result<DirEntry>> {
         loop {
             let start = self.i;
-            while self.i < self.data.len() {
-                let i = self.i;
+            let mut i = self.i;
+            while i < self.data.len() {
                 self.i += 1;
                 if self.data[i] == b'\n' {
                     break;
                 }
+                i += 1;
             }
             if start < self.i {
                 let ret = DirEntry {
-                    name: self.data[start .. self.i].to_owned().into_boxed_slice(),
+                    name: self.data[start .. i].to_owned().into_boxed_slice(),
                     root: self.root.clone()
                 };
                 if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
@@ -182,7 +183,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
     }
 
     pub fn file_type(&self) -> io::Result<FileType> {
-        stat(&self.path()).map(|m| m.file_type())
+        lstat(&self.path()).map(|m| m.file_type())
     }
 
     fn name_bytes(&self) -> &[u8] {
@@ -367,7 +368,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 pub fn readdir(p: &Path) -> io::Result<ReadDir> {
     let root = Arc::new(p.to_path_buf());
-    let options = OpenOptions::new();
+    let mut options = OpenOptions::new();
+    options.read(true);
     let fd = File::open(p, &options)?;
     let mut data = Vec::new();
     fd.read_to_end(&mut data)?;
@@ -431,7 +433,8 @@ pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
 
 pub fn stat(p: &Path) -> io::Result<FileAttr> {
     let mut stat: stat = stat::default();
-    let options = OpenOptions::new();
+    let mut options = OpenOptions::new();
+    options.read(true);
     let file = File::open(p, &options)?;
     cvt(fstat(file.0.raw(), &mut stat))?;
     Ok(FileAttr { stat: stat })
@@ -442,7 +445,8 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
 }
 
 pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
-    let options = OpenOptions::new();
+    let mut options = OpenOptions::new();
+    options.read(true);
     let file = File::open(p, &options)?;
     file.path()
 }