Skip to content

Commit

Permalink
revert to for-loops in get_x_by_id and change doc for File::close() t…
Browse files Browse the repository at this point in the history
…o reflect behavior Drop impl.
  • Loading branch information
peterkrull committed Mar 28, 2024
1 parent 283e5f6 commit e9d0fbf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
5 changes: 2 additions & 3 deletions src/filesystem/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ where

/// Consume the `File` handle and close it. The behavior of this is similar
/// to using [`core::mem::drop`] or letting the `File` go out of scope,
/// except if the file fails to close properly, this returns an error,
/// whereas the automatic drop will panic. This method is therefore hihgly
/// recommended for closing files over just dropping them.
/// except this lets the user handle any errors that may occur in the process,
/// whereas when using drop, any errors will be discarded silently.
pub fn close(self) -> Result<(), Error<D::Error>> {
self.volume_mgr.close_file(self.raw_file)
}
Expand Down
36 changes: 18 additions & 18 deletions src/volume_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,30 +1015,30 @@ where
}

fn get_volume_by_id(&self, volume: RawVolume) -> Result<usize, Error<D::Error>> {
self.open_volumes
.iter()
.enumerate()
.find(|(_, v)| v.volume_id == volume)
.ok_or(Error::BadHandle)
.map(|(idx, _)| idx)
for (idx, v) in self.open_volumes.iter().enumerate() {
if v.volume_id == volume {
return Ok(idx);
}
}
Err(Error::BadHandle)
}

fn get_dir_by_id(&self, directory: RawDirectory) -> Result<usize, Error<D::Error>> {
self.open_dirs
.iter()
.enumerate()
.find(|(_, d)| d.directory_id == directory)
.ok_or(Error::BadHandle)
.map(|(idx, _)| idx)
for (idx, d) in self.open_dirs.iter().enumerate() {
if d.directory_id == directory {
return Ok(idx);
}
}
Err(Error::BadHandle)
}

fn get_file_by_id(&self, file: RawFile) -> Result<usize, Error<D::Error>> {
self.open_files
.iter()
.enumerate()
.find(|(_, f)| f.file_id == file)
.ok_or(Error::BadHandle)
.map(|(idx, _)| idx)
for (idx, f) in self.open_files.iter().enumerate() {
if f.file_id == file {
return Ok(idx);
}
}
Err(Error::BadHandle)
}

/// This function turns `desired_offset` into an appropriate block to be
Expand Down

0 comments on commit e9d0fbf

Please sign in to comment.