akiomik / akiomik/nostui

A blank NOSTUI_CONFIG is taken as an answer, not as an omission

Đang mở
#580 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Rust
Star
71
Fork
5
Merge trung bình
4 giờ 2 phút
Pull request đã merge (30 ngày)
31

Mô tả

Found while reviewing [#576](https://github.com/akiomik/nostui/pull/576), which works around the symptom rather than this.

## What happens

```rust
pub static CONFIG_FOLDER: LazyLock> = LazyLock::new(|| {
env::var(format!("{}_CONFIG", *PROJECT_NAME))
.ok()
.map(PathBuf::from)
});
```

`env::var` answers `Ok("")` for a variable that is set and empty, so `NOSTUI_CONFIG=` yields `Some(PathBuf::from(""))` and `get_config_dir` returns it in preference to the platform directory. The loader then joins each name onto nothing and probes the working directory:

```console
$ cd /tmp && NOSTUI_CONFIG= nostui
No configuration file found in /private/tmp
```

`DATA_FOLDER` reads `NOSTUI_DATA` the same way, so a blank one puts the log in the working directory too.

This is not an exotic way to end up with a blank variable. `NOSTUI_CONFIG="$SOMETHING_UNSET"` produces one, as does a compose file or unit that declares the key without a value, and `export NOSTUI_CONFIG=` is a plausible way to try to *clear* an override — which is exactly the intent this reading inverts.

## What #576 does and does not do

It makes the message name the working directory rather than print an empty path, so a user is at least told where nostui looked. It does not change where that is. Someone who blanked the variable meaning "never mind" still gets the working directory rather than the platform one.

## Shape

`.ok().filter(|value| !value.is_empty())` in both statics, so a blank variable reads as an omission. That is a behaviour change rather than a message change — `--version` prints these directories too — which is why it is not in #576.

## Acceptance

- `NOSTUI_CONFIG=` and `NOSTUI_DATA=` behave as if unset, for the loader and for `--version`.
- A variable set to a real path is unaffected.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.