Skip to content

Panic when using --full-path if current working directory is invalid or removed #1900

@dataCenter430

Description

@dataCenter430

Description

When --full-path (or -f) is used, fd builds absolute paths for each match. If the process’s current working directory becomes invalid during the search (e.g. it was deleted or permissions changed), the program can panic instead of reporting an error.

Location: src/walk.rs, in the worker closure that builds search_str for full-path matching (around lines 521–524).

Cause: filesystem::path_absolute_form(entry_path) can return an Err (for example when env::current_dir() fails). The code uses .expect("Retrieving absolute path succeeds"), which turns that error into a panic.

Reproduction (conceptually):

  1. Start fd with --full-path in a directory.
  2. From another process/shell, remove or make the current directory inaccessible (e.g. rmdir the CWD or revoke access) while the search is running.
  3. When fd tries to resolve a relative path, path_absolute_form fails and the process panics.

Suggested fix: Do not use .expect(). Either propagate the error (e.g. with ?) so the search can fail gracefully, or send a WorkerResult::Error and continue, so the user gets an error message and a non-zero exit code instead of a panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions