Skip to content

Validate FOC_DEVNET_BASEDIR is not empty before use#54

Closed
Copilot wants to merge 4 commits intofeat/redpanda/configurable-base-dirfrom
copilot/sub-pr-52-again
Closed

Validate FOC_DEVNET_BASEDIR is not empty before use#54
Copilot wants to merge 4 commits intofeat/redpanda/configurable-base-dirfrom
copilot/sub-pr-52-again

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

The FOC_DEVNET_BASEDIR environment variable was used without validating it's non-empty, causing paths to resolve relative to the current directory when set to "" or whitespace.

Changes:

  • Added trim().is_empty() check in foc_devnet_home() to fall back to default when env var is empty/whitespace
  • Extracted default path logic to closure to eliminate duplication
  • Added unit tests for empty string, whitespace, unset, valid path, and tilde expansion cases
  • Used serial_test to prevent race conditions in tests that modify global env state
pub fn foc_devnet_home() -> PathBuf {
    let default_path = || {
        dirs::home_dir()
            .unwrap_or_else(|| PathBuf::from("/tmp"))
            .join(".foc-devnet")
    };

    if let Ok(base_dir) = std::env::var("FOC_DEVNET_BASEDIR") {
        if !base_dir.trim().is_empty() {
            PathBuf::from(shellexpand::tilde(&base_dir).as_ref())
        } else {
            default_path()
        }
    } else {
        default_path()
    }
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: redpanda-f <181817029+redpanda-f@users.noreply.github.com>
@redpanda-f
Copy link
Collaborator

I do not like the fallback to /tmp/..., if it is not set, we should still use ~/.foc-devnet

Copilot AI and others added 2 commits January 30, 2026 06:55
Co-authored-by: redpanda-f <181817029+redpanda-f@users.noreply.github.com>
Co-authored-by: redpanda-f <181817029+redpanda-f@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP to address feedback on FOC_DEVNET_BASERDIR support Validate FOC_DEVNET_BASEDIR is not empty before use Jan 30, 2026
Copilot AI requested a review from redpanda-f January 30, 2026 07:03
@redpanda-f redpanda-f closed this Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants