Skip to content

Commit 79a8c27

Browse files
committed
Fix readdir
1 parent a908509 commit 79a8c27

File tree

1 file changed

+11
-7
lines changed
  • src/libstd/sys/redox

1 file changed

+11
-7
lines changed

src/libstd/sys/redox/fs.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,17 @@ impl Iterator for ReadDir {
146146
fn next(&mut self) -> Option<io::Result<DirEntry>> {
147147
loop {
148148
let start = self.i;
149-
while self.i < self.data.len() {
150-
let i = self.i;
149+
let mut i = self.i;
150+
while i < self.data.len() {
151151
self.i += 1;
152152
if self.data[i] == b'\n' {
153153
break;
154154
}
155+
i += 1;
155156
}
156157
if start < self.i {
157158
let ret = DirEntry {
158-
name: self.data[start .. self.i].to_owned().into_boxed_slice(),
159+
name: self.data[start .. i].to_owned().into_boxed_slice(),
159160
root: self.root.clone()
160161
};
161162
if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
@@ -182,7 +183,7 @@ impl DirEntry {
182183
}
183184

184185
pub fn file_type(&self) -> io::Result<FileType> {
185-
stat(&self.path()).map(|m| m.file_type())
186+
lstat(&self.path()).map(|m| m.file_type())
186187
}
187188

188189
fn name_bytes(&self) -> &[u8] {
@@ -367,7 +368,8 @@ impl fmt::Debug for File {
367368

368369
pub fn readdir(p: &Path) -> io::Result<ReadDir> {
369370
let root = Arc::new(p.to_path_buf());
370-
let options = OpenOptions::new();
371+
let mut options = OpenOptions::new();
372+
options.read(true);
371373
let fd = File::open(p, &options)?;
372374
let mut data = Vec::new();
373375
fd.read_to_end(&mut data)?;
@@ -431,7 +433,8 @@ pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
431433

432434
pub fn stat(p: &Path) -> io::Result<FileAttr> {
433435
let mut stat: stat = stat::default();
434-
let options = OpenOptions::new();
436+
let mut options = OpenOptions::new();
437+
options.read(true);
435438
let file = File::open(p, &options)?;
436439
cvt(fstat(file.0.raw(), &mut stat))?;
437440
Ok(FileAttr { stat: stat })
@@ -442,7 +445,8 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
442445
}
443446

444447
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
445-
let options = OpenOptions::new();
448+
let mut options = OpenOptions::new();
449+
options.read(true);
446450
let file = File::open(p, &options)?;
447451
file.path()
448452
}

0 commit comments

Comments
 (0)