Skip to content

fix: avoid shadowing the .astrbot marker file in the system temp dir - #10784

Merged
Soulter merged 5 commits into
AstrBotDevs:masterfrom
rwzdk:fix/plugin-install-marker-file-conflict
Oct 26, 2026
Merged

Soulter merged 5 commits into
AstrBotDevs:masterfrom
rwzdk:fix/plugin-install-marker-file-conflict

Conversation

@rwzdk

@rwzdk rwzdk commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10783

Problem

get_astrbot_system_tmp_path() joins .astrbot onto tempfile.gettempdir(). When the system temporary directory is unusable, Python falls back to the current working directory — the directory where astrbot init leaves the .astrbot marker file. The plugin installer then does:

temp_root = Path(get_astrbot_system_tmp_path())
temp_root.mkdir(parents=True, exist_ok=True)

which raises FileExistsError: [Errno 17] File exists: '/AstrBot/.astrbot' before the plugin is even downloaded.

This is the collision case the issue separates from the deployment problem: the unusable system temp dir is an environment issue, but AstrBot must not fail with a bare FileExistsError because its own marker file happens to sit at the resolved path.

Fix

get_astrbot_system_tmp_path() now checks whether the resolved .astrbot path is an existing file (the init marker). In that case it returns a sibling directory instead, so the marker file is never shadowed by a directory:

system_tmp = Path(tempfile.gettempdir())
candidate = system_tmp / ".astrbot"
if candidate.is_file():
    candidate = system_tmp / ".astrbot-tmp"
return os.path.realpath(str(candidate))

The normal case is unchanged: the shared directory is still <system temp>/.astrbot.

Tests

  • tests/test_astrbot_path.py (new): the shared directory stays <system temp>/.astrbot when that path is free or already a directory, and never resolves to the init marker file when that path is a regular file.
  • tests/test_plugin_manager.py: install_plugin() completes when the system temp dir contains the .astrbot marker file, and the marker file is left intact.

Red/green on the change:

# without the fix
FAILED tests/test_astrbot_path.py::test_system_tmp_path_never_shadows_the_init_marker_file
FAILED tests/test_plugin_manager.py::test_install_plugin_staging_root_does_not_shadow_the_marker_file
E   FileExistsError
2 failed, 127 passed

# with the fix
129 passed

ruff format and ruff check are clean on the changed files.

Summary by Sourcery

Prevent temporary-directory handling from shadowing AstrBot’s initialization marker file.

Bug Fixes:

  • Prevent plugin installation from failing when the resolved system temporary path conflicts with the .astrbot initialization marker file.

Enhancements:

  • Use a sibling .astrbot-tmp directory when .astrbot is an existing file while preserving the normal temporary-directory behavior.

Tests:

  • Add coverage for temporary-path resolution, marker-file preservation, and plugin installation in the fallback temporary-directory scenario.

Chores:

  • Ignore the fallback .astrbot-tmp directory in Git and Docker builds.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/utils/astrbot_path.py" line_range="106" />
<code_context>
+    system_tmp = Path(tempfile.gettempdir())
+    candidate = system_tmp / ".astrbot"
+    if candidate.is_file():
+        candidate = system_tmp / ".astrbot-tmp"
+    return os.path.realpath(str(candidate))

</code_context>
<issue_to_address>
**Temporary data enters images**

When the system temp directory falls back to the repository root and a Docker build runs while temporary files remain there, `Dockerfile` copies the build context with `COPY . /AstrBot/`, while `.dockerignore` excludes `.astrbot` but not `.astrbot-tmp`; temporary files created under the new path, including background shell logs, are therefore embedded in built images and exposed to anyone with access to them.

Add `.astrbot-tmp` to both `.dockerignore` and `.gitignore`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: astrbot/core/utils/astrbot_path.py:106


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/utils/astrbot_path.py
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 26, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai
sourcery-ai Bot dismissed their stale review October 26, 2026 14:53

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@Soulter Soulter changed the title fix: avoid shadowing the .astrbot marker file in the system temp dir fix: use a dedicated system temporary directory Oct 26, 2026
@Soulter Soulter changed the title fix: use a dedicated system temporary directory fix: avoid shadowing the .astrbot marker file in the system temp dir Oct 26, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@Soulter
Soulter merged commit f3cd584 into AstrBotDevs:master Oct 26, 2026
23 checks passed
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.

[Bug] 插件安装暂存目录与.astrbot标记文件冲突,导致FileExistsError

2 participants