Skip to content

Commit

Permalink
Add missing error kinds.
Browse files Browse the repository at this point in the history
`ZeroMountPointsFound` and `CantOpenMountPointsFile` were added.
  • Loading branch information
ArturKovacs committed Nov 16, 2019
1 parent 6db249b commit 6c79f7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 8 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ pub enum ErrorKind {
/// obtained with `HRESULT_FROM_WIN32(GetLastError())`
PlatformApi { function_name: &'static str, code: Option<i32> },

/// This is a Linux specific Error that occures when neither '/proc/mounts' nor '/etc/mtab'
/// could be opened. This may happen during `remove`, `remove_all`, or `list`
CantOpenMountPointsFile,

/// This is a Linux specific Error that occurs when a mount points file could be opened
/// but the very first call to `getmntent` returned NULL.
ZeroMountPointsFound,

/// Error while canonicalizing path.
///
/// The `source()` function of the `Error` will return a reference to an `std::io::Error`.
Expand All @@ -107,18 +115,6 @@ pub enum ErrorKind {
original: PathBuf,
},

///
/// NOTE: THIS ERROR WAS REMOVED
/// The reason for this is that it provides vauge information of the circumstances
/// that caused the error. The user would've had to look into the source of the library
/// to understand when this error is produced.
///
/// Error while performing the remove operation.
/// `code` contains a raw os error code if accessible.
// Remove {
// code: Option<i32>,
// },

/// Error while converting an OsString to a String.
///
/// This error kind will not provide a `source()` but it directly corresponds to the error
Expand Down
10 changes: 5 additions & 5 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn list() -> Result<Vec<TrashItem>, Error> {
})?;
}
if trash_folders.len() == 0 {
// TODO make this a watning
// TODO make this a warning
return Err(home_error.unwrap());
}
// List all items from the set of trash folders
Expand Down Expand Up @@ -604,8 +604,7 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {
file = unsafe { libc::fopen(mtab_path.as_c_str().as_ptr(), read_arg.as_c_str().as_ptr()) };
}
if file == std::ptr::null_mut() {
// TODO ADD ERROR FOR WHEN NO MONTPOINTS FILE WAS FOUND
panic!();
return Err(Error::kind_only(ErrorKind::CantOpenMountPointsFile));
}
defer! {{ unsafe { libc::fclose(file); } }}
let mut result = Vec::new();
Expand All @@ -628,8 +627,9 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {
result.push(mount_point);
}
if result.len() == 0 {
// TODO add Error for when no mountpoints were found
panic!();
// If the mountpoints file could be opened but no mountpoints are found
// there possibly is a serious issue
return Err(Error::kind_only(ErrorKind::ZeroMountPointsFound));
}
Ok(result)
}

0 comments on commit 6c79f7d

Please sign in to comment.