# Bug: `remove_file` in core-dump-agent called on non-existent file due to inverted logic

Open Beginner friendly
#187 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust
Domain
devops

Research direction

Start at the core-dump-agent's remove function and inspect the existence check immediately before fs::remove_file. Correct the condition so existing files are removed while missing files do not cause an error. Verify cleanup behavior for both an existing crictl executable and a missing one using the repository's available checks.

Written by the indexing model from the issue text.

Description

Bug: remove_file in core-dump-agent called on non-existent file due to inverted logic

Description

In the remove function, there is a logic error in the file existence check preceding fs::remove_file:

if !Path::new(&crictl_exe).exists() {
    fs::remove_file(crictl_exe)?;
}

The condition !Path::new(&crictl_exe).exists() evaluates to true when the file does not exist. Inside the if block, fs::remove_file(crictl_exe)? is then called, which attempts to delete a file that has just been confirmed as absent.

std::fs::remove_file on a non-existent path returns std::io::Error with ErrorKind::NotFound, which propagates up via the ? operator. This causes the function to fail in cases where the file is genuinely missing, potentially breaking cleanup or teardown workflows.

Expected behavior

  • If the file exists → remove it.
  • If the file does not exist → do nothing (or log a debug message), without returning an error.

Actual behavior

  • If the file does not exist → fs::remove_file returns ErrorKind::NotFound, which is propagated via ?, causing the function to fail.

Proposed fix

Option A — correct the logic:

if Path::new(&crictl_exe).exists() {
    fs::remove_file(crictl_exe)?;
}

Severity

Medium — the function fails when the file is missing, which can break teardown/cleanup flows.

Labels

bug, cleanup, io

Dominant language
Rust
Stars
160
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from IBM/core-dump-handler

All issues in IBM/core-dump-handler

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.