Skip to content

Commit

Permalink
Better error message for fs::read_dir
Browse files Browse the repository at this point in the history
Added FlakeError for this condition. Related to Issue #9
  • Loading branch information
schaefi committed Aug 29, 2023
1 parent 14d222f commit 61500b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ pub enum FlakeError {
#[error("Failed to run {}", .0)]
CommandError(#[from] CommandError),

#[error("IOError: {kind:?} {message:?}")]
IOError {
kind: String,
message: String
},

/// IO operation pass through
#[error(transparent)]
IO(#[from] std::io::Error),
#[cfg(feature = "json")]

/// MalformedJson pass through
#[cfg(feature = "json")]
#[error(transparent)]
MalformedJson(#[from] serde_json::Error),

Expand Down
17 changes: 14 additions & 3 deletions podman-pilot/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ pub fn gc_cid_file(container_cid_file: &String, user: User) -> Result<bool, Flak
let mut exists = user.run("podman");
exists.arg("container").arg("exists").arg(&cid);


if !exists.status()?.success() {
fs::remove_file(container_cid_file)?;
Ok(false)
Expand All @@ -570,13 +569,25 @@ pub fn gc_cid_file(container_cid_file: &String, user: User) -> Result<bool, Flak
}
}

pub fn gc(user: User) -> Result<(), std::io::Error> {
pub fn gc(user: User) -> Result<(), FlakeError> {
/*!
Garbage collect CID files for which no container exists anymore
!*/
let mut cid_file_names: Vec<String> = Vec::new();
let mut cid_file_count: i32 = 0;
let paths = fs::read_dir(defaults::CONTAINER_CID_DIR)?;
let paths;
match fs::read_dir(defaults::CONTAINER_CID_DIR) {
Ok(result) => { paths = result },
Err(error) => {
return Err(FlakeError::IOError {
kind: format!("{:?}", error.kind()),
message: format!("fs::read_dir failed on {}: {}",
defaults::CONTAINER_CID_DIR,
error.to_string()
)
})
}
};
for path in paths {
cid_file_names.push(format!("{}", path?.path().display()));
cid_file_count += 1;
Expand Down

0 comments on commit 61500b3

Please sign in to comment.