Skip to content

feat: add configurable temp directory to resolve Windows access denied errors#629

Open
sergio-sisternes-epam wants to merge 7 commits intomicrosoft:mainfrom
sergio-sisternes-epam:fix/624-configurable-temp-dir
Open

feat: add configurable temp directory to resolve Windows access denied errors#629
sergio-sisternes-epam wants to merge 7 commits intomicrosoft:mainfrom
sergio-sisternes-epam:fix/624-configurable-temp-dir

Conversation

@sergio-sisternes-epam
Copy link
Copy Markdown
Collaborator

Description

Add temp-dir configuration key so users can override the system temporary directory used during apm install. This resolves [WinError 5] Access is denied errors in corporate Windows environments where endpoint security or Group Policy restricts access to %TEMP%.

Fixes #624

Changes

  • src/apm_cli/config.py -- Add get_temp_dir(), set_temp_dir(), get_apm_temp_dir() with resolution chain: APM_TEMP_DIR env var > config file > system default
  • src/apm_cli/commands/config.py -- Wire temp-dir into set/get/display subcommands
  • src/apm_cli/deps/github_downloader.py -- Use get_apm_temp_dir() at all 4 temp creation sites + catch PermissionError/OSError with actionable message
  • src/apm_cli/bundle/unpacker.py, runtime/manager.py, commands/update.py -- Wire dir=get_apm_temp_dir() at remaining temp sites
  • Docs -- CLI reference, skills resource, CHANGELOG updated

Usage

# Set a custom temp directory
apm config set temp-dir C:\apm-temp

# Check current setting
apm config get temp-dir

# Or use environment variable (takes precedence)
export APM_TEMP_DIR=/tmp/apm-work

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (3776 passed)
  • Added tests for new functionality (51 new tests across 2 files)

Add `temp-dir` configuration key so users can override the system
temporary directory used during apm install. This resolves
[WinError 5] Access is denied errors in corporate Windows
environments where endpoint security restricts %TEMP%.

- Add get_temp_dir(), set_temp_dir(), get_apm_temp_dir() to config module
- Resolution order: APM_TEMP_DIR env var > config file > system default
- Wire all tempfile.mkdtemp/TemporaryDirectory call sites
- Catch PermissionError/OSError in download path with actionable message
- Add 51 new tests covering config, CLI, and error handling
- Update CLI reference docs, skills resource, and CHANGELOG

Fixes microsoft#624

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergio-sisternes-epam sergio-sisternes-epam marked this pull request as ready for review April 9, 2026 08:05
Copilot AI review requested due to automatic review settings April 9, 2026 08:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a user-configurable temporary directory override (env var + persisted config + CLI wiring) so apm install and other operations can avoid locked-down %TEMP% locations in corporate Windows environments.

Changes:

  • Introduces get_temp_dir(), set_temp_dir(), and get_apm_temp_dir() with APM_TEMP_DIR > config file > system default resolution.
  • Wires temp-dir into apm config show/get/set and routes temp creation sites to use the effective temp directory.
  • Adds unit tests + updates docs and CHANGELOG.md to document the new configuration key.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/apm_cli/config.py Adds temp-dir config getters/setters and effective temp dir resolution logic.
src/apm_cli/commands/config.py Exposes temp-dir via apm config show/get/set flows.
src/apm_cli/deps/github_downloader.py Uses configurable temp dir for git temp work; adds access-denied error messaging.
src/apm_cli/bundle/unpacker.py Extract temp dir for bundle unpacking now respects configured temp base.
src/apm_cli/runtime/manager.py Embedded runtime scripts now run in temp dirs under the configured base.
src/apm_cli/commands/update.py Update installer temp script is created under the configured temp base.
tests/unit/test_github_downloader_temp_dir.py Adds tests around access-denied handling in subdirectory downloads.
tests/unit/test_config_command.py Adds tests for config display + config/temp-dir resolution helpers + CLI config get/set temp-dir.
docs/src/content/docs/reference/cli-commands.md Documents temp-dir in CLI reference and usage examples.
packages/apm-guide/.apm/skills/apm-usage/commands.md Updates skill resource command list to mention temp-dir.
CHANGELOG.md Adds an Unreleased entry for the new temp-dir configuration key.

- Move mkdtemp() inside try block so PermissionError is caught (microsoft#629)
- Narrow error handler to check failing path is under temp_dir
- Differentiate "does not exist" vs "not a directory" in set_temp_dir
- Log resolved path in success message, not raw input
- Fix tests to trigger PermissionError from mkdtemp (realistic path)
- Fix test temp dir leaks using tmp_path fixture
- Update CHANGELOG to reference PR microsoft#629

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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] apm install access is denied to temp folder

3 participants