Skip to content

fix(maa-dirs): treat empty directory environment variables as unset#563

Open
JIAFALSEDREAM wants to merge 1 commit into
MaaAssistantArknights:mainfrom
JIAFALSEDREAM:fix/ignore-empty-env-dirs
Open

fix(maa-dirs): treat empty directory environment variables as unset#563
JIAFALSEDREAM wants to merge 1 commit into
MaaAssistantArknights:mainfrom
JIAFALSEDREAM:fix/ignore-empty-env-dirs

Conversation

@JIAFALSEDREAM

@JIAFALSEDREAM JIAFALSEDREAM commented Jul 24, 2026

Copy link
Copy Markdown

问题描述

dir_from_env 当前会将值为空的环境变量视为有效路径。

例如:

XDG_DATA_HOME=
XDG_CACHE_HOME=

此时数据目录和缓存目录都可能被解析为相对路径 maa/

data:  maa
cache: maa

这会导致 MaaCore 的基础资源目录与热更新缓存目录重合。热更新下载的 tasks.json 增量资源可能因此覆盖基础资源中的完整 tasks.json,最终导致资源加载失败。

根据 XDG Base Directory Specification,XDG 环境变量未设置或值为空时,都应回退到默认目录。

修改内容

  • 忽略值为空的 MAA_*_DIR 环境变量,并继续尝试对应的 XDG 环境变量。
  • 忽略值为空的 XDG_*_HOME 环境变量,并回退到平台默认目录。
  • 保持非空 MAA_*_DIR 优先于 XDG 环境变量的现有行为。
  • 添加空环境变量相关的回归测试。

测试结果

  • cargo test -p maa-dirs
  • cargo clippy --workspace --all-targets
  • cargo x test
  • 验证所有 XDG 变量为空时,数据目录正确解析为 ~/.local/share/maa,而不是相对路径 maa/

Summary by Sourcery

将与目录相关的空环境变量视为未设置,这样目录解析会回退到 XDG 或平台默认值,而不是使用无效的相对路径。

Bug Fixes:

  • MAA_*_DIRXDG_*_HOME 变量被设置为空字符串时,防止数据、缓存、状态和配置目录解析为意料之外的相对路径。

Tests:

  • 添加回归测试,确保空的 MAA_*_DIRXDG_*_HOME 环境变量会被忽略,并且行为与未设置变量时相同。
Original summary in English

Summary by Sourcery

Treat empty directory-related environment variables as unset so directory resolution falls back to XDG or platform defaults instead of using invalid relative paths.

Bug Fixes:

  • Prevent data, cache, state, and config directories from resolving to unintended relative paths when MAA_DIR or XDG_HOME variables are set to empty strings.

Tests:

  • Add regression tests to ensure empty MAA_DIR and XDG_HOME environment variables are ignored and behave the same as unset variables.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨,我已经审查了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有帮助!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant