Skip to content

Commit

Permalink
Merge pull request #1230 from stlankes/common
Browse files Browse the repository at this point in the history
remove unneeded unwraps
  • Loading branch information
stlankes authored May 26, 2024
2 parents 98a4f0c + 0ad6cd5 commit 5210ee6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,16 @@ pub unsafe fn create_file(

/// Removes an empty directory.
pub fn remove_dir(path: &str) -> Result<(), IoError> {
FILESYSTEM.get().unwrap().rmdir(path)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.rmdir(path)
}

pub fn unlink(path: &str) -> Result<(), IoError> {
FILESYSTEM.get().unwrap().unlink(path)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.unlink(path)
}

/// Creates a new, empty directory at the provided path
pub fn create_dir(path: &str, mode: AccessPermission) -> Result<(), IoError> {
FILESYSTEM.get().unwrap().mkdir(path, mode)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.mkdir(path, mode)
}

/// Returns an vector with all the entries within a directory.
Expand All @@ -392,11 +392,11 @@ pub fn readdir(name: &str) -> Result<Vec<DirectoryEntry>, IoError> {
}

pub fn read_stat(name: &str) -> Result<FileAttr, IoError> {
FILESYSTEM.get().unwrap().stat(name)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.stat(name)
}

pub fn read_lstat(name: &str) -> Result<FileAttr, IoError> {
FILESYSTEM.get().unwrap().lstat(name)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.lstat(name)
}

pub fn open(
Expand All @@ -410,7 +410,7 @@ pub fn open(

debug!("Open {}, {:?}, {:?}", name, flags, mode);

let fs = FILESYSTEM.get().unwrap();
let fs = FILESYSTEM.get().ok_or(IoError::EINVAL)?;
if let Ok(file) = fs.open(name, flags, mode) {
let fd = insert_object(file)?;
Ok(fd)
Expand All @@ -421,14 +421,14 @@ pub fn open(

/// Open a directory to read the directory entries
pub(crate) fn opendir(name: &str) -> Result<FileDescriptor, IoError> {
let obj = FILESYSTEM.get().unwrap().opendir(name)?;
let obj = FILESYSTEM.get().ok_or(IoError::EINVAL)?.opendir(name)?;
insert_object(obj)
}

use crate::fd::{self, FileDescriptor};

pub fn file_attributes(path: &str) -> Result<FileAttr, IoError> {
FILESYSTEM.get().unwrap().lstat(path)
FILESYSTEM.get().ok_or(IoError::EINVAL)?.lstat(path)
}

#[allow(clippy::len_without_is_empty)]
Expand Down

0 comments on commit 5210ee6

Please sign in to comment.