Repository: openai/codex
File: codex-rs/core/src/config_loader/mod.rs (Rust)

Code before:
                return Err(io::Error::new(
                    e.kind(),
                    format!(
                        "Failed to read requirements file {}: {e}",
                        requirements_toml_file.as_ref().display(),
                    ),
                ));
            }
        }
    }

    Ok(())
}

fn system_requirements_toml_file() -> Option<PathBuf> {
    #[cfg(unix)]
    {
        Some(PathBuf::from("/etc/codex/requirements.toml"))
    }

    #[cfg(windows)]
    {
        Some(windows_system_requirements_toml_file())
    }

    #[cfg(not(any(unix, windows)))]
    {
        None
    }
}

fn system_config_toml_file() -> Option<PathBuf> {
    if cfg!(unix) {
        Some(PathBuf::from(SYSTEM_CONFIG_TOML_FILE_UNIX))
    } else {
        None
    }
}

#[cfg(windows)]
fn windows_system_requirements_toml_file() -> PathBuf {
    let base = windows_program_data_dir_from_known_folder().unwrap_or_else(|err| {
        tracing::warn!(
            error = %err,
            "Failed to resolve ProgramData known folder; using default path"
        );
        PathBuf::from(DEFAULT_PROGRAM_DATA_DIR_WINDOWS)
    });
    base.join("OpenAI\\Codex\\requirements.toml")
}


Review comment (bug):
I would remove this bit and change the signature of this function to be:

```rust
fn system_requirements_toml_file() -> std::io::Result<AbsolutePathBuf>
```

which means pushing the `AbsolutePathBuf::try_from` into this function.

If someone tries to compile Codex CLI on something that is neither UNIX nor Windows, then we'll get a compilation error here, which I think is fine for now. (Incidentally, UNIX covers Android, which some of our users target.)

Code after:
}

#[cfg(unix)]
fn system_requirements_toml_file() -> io::Result<AbsolutePathBuf> {
    AbsolutePathBuf::from_absolute_path(Path::new("/etc/codex/requirements.toml"))
}

#[cfg(windows)]
fn system_requirements_toml_file() -> io::Result<AbsolutePathBuf> {
    windows_system_requirements_toml_file()
}

#[cfg(unix)]
fn system_config_toml_file() -> io::Result<AbsolutePathBuf> {
    AbsolutePathBuf::from_absolute_path(Path::new(SYSTEM_CONFIG_TOML_FILE_UNIX))
}

#[cfg(windows)]
fn system_config_toml_file() -> io::Result<AbsolutePathBuf> {
    windows_system_config_toml_file()
}

#[cfg(windows)]
fn windows_codex_system_dir() -> PathBuf {
    let program_data = windows_program_data_dir_from_known_folder().unwrap_or_else(|err| {
        tracing::warn!(
            error = %err,
            "Failed to resolve ProgramData known folder; using default path"
        );
        PathBuf::from(DEFAULT_PROGRAM_DATA_DIR_WINDOWS)
    });
    program_data.join("OpenAI").join("Codex")
}

#[cfg(windows)]
fn windows_system_requirements_toml_file() -> io::Result<AbsolutePathBuf> {
    let requirements_toml_file = windows_codex_system_dir().join("requirements.toml");
    AbsolutePathBuf::try_from(requirements_toml_file)
}

#[cfg(windows)]
fn windows_system_config_toml_file() -> io::Result<AbsolutePathBuf> {
    let config_toml_file = windows_codex_system_dir().join("config.toml");
    AbsolutePathBuf::try_from(config_toml_file)
}

#[cfg(windows)]
fn windows_program_data_dir_from_known_folder() -> io::Result<PathBuf> {
    use std::ffi::OsString;
    use std::os::windows::ffi::OsStringExt;
    use windows_sys::Win32::System::Com::CoTaskMemFree;