Skip to content

fix(lock): use TMPDIR with /tmp fallback for default lock path#1081

Open
tmchow wants to merge 1 commit intoamber-lang:stagingfrom
tmchow:osc/1018-termux-tmp-fallback
Open

fix(lock): use TMPDIR with /tmp fallback for default lock path#1081
tmchow wants to merge 1 commit intoamber-lang:stagingfrom
tmchow:osc/1018-termux-tmp-fallback

Conversation

@tmchow
Copy link
Copy Markdown
Contributor

@tmchow tmchow commented Apr 1, 2026

Summary

The lock builtin hardcodes /tmp for default lock file paths. This fails on Termux (Android terminal emulator) where /tmp is not accessible due to Android's app sandboxing.

Changes

  • src/modules/builtin/lock.rs: Replace hardcoded /tmp with ${TMPDIR:-/tmp} in the generated Bash fragment. This respects the TMPDIR environment variable (which Termux sets to a writable directory) and falls back to /tmp on standard systems.
  • src/tests/compiling.rs: Add a regression test verifying the generated lock path contains the TMPDIR-based pattern.

The fix is a single character-level change to the Bash template string. On Termux, TMPDIR points to /data/data/com.termux/files/usr/tmp. On standard Linux/macOS, TMPDIR is either unset (so /tmp is used) or set to a system-appropriate directory.

Testing

  • cargo test passes (653 tests, 0 failures)
  • cargo clippy passes with no warnings
  • New test test_lock_default_path_uses_tmpdir_with_tmp_fallback verifies the generated Bash contains ${TMPDIR:-/tmp}/${0##*/}.lock

Fixes #1018

This contribution was developed with AI assistance (Codex).

Summary by CodeRabbit

  • New Features

    • The lock behavior now respects the TMPDIR environment variable for determining the default lock-file location, falling back to /tmp when TMPDIR is unset. This lets lock files be placed in a user-configured temporary directory.
  • Tests

    • Added a unit test verifying the default lock-file path uses TMPDIR with a /tmp fallback.

@tmchow tmchow mentioned this pull request Apr 1, 2026
4 tasks
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 601c4753-057c-4460-93d3-3ff4a5250bed

📥 Commits

Reviewing files that changed from the base of the PR and between eb1e518 and 2a7023c.

📒 Files selected for processing (2)
  • src/modules/builtin/lock.rs
  • src/tests/compiling.rs
✅ Files skipped from review due to trivial changes (1)
  • src/modules/builtin/lock.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/compiling.rs

📝 Walkthrough

Walkthrough

Changed the lock builtin’s default lock-file path when path is not provided to expand ${TMPDIR:-/tmp}/${0##*/}.lock instead of always using /tmp/${0##*/}.lock. Added a unit test to assert the generated template includes the TMPDIR-based path with /tmp fallback.

Changes

Cohort / File(s) Summary
Lock builtin
src/modules/builtin/lock.rs
Default lock-file path now uses ${TMPDIR:-/tmp}/${0##*/}.lock when path is omitted, replacing the hardcoded /tmp fragment.
Tests
src/tests/compiling.rs
Added test_lock_default_path_uses_tmpdir_with_tmp_fallback to verify the lock translation emits the TMPDIR-based path template with /tmp fallback.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • Lock builtin, #448 #1034: Changes the Lock builtin's translation to use ${TMPDIR:-/tmp}/${0##*/}.lock for the default lock-file path.

Suggested reviewers

  • Ph0enixKM
  • callframe

Poem

🐰 I hopped through code to mend a plight,
From rigid /tmp to TMPDIR's light.
A fallback stitched, a safer lock,
Now scripts can run — tick-tock, tick-tock! 🐇🔒

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: using TMPDIR with /tmp fallback for the default lock path, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR directly addresses the core coding requirement from issue #1018: making the lock builtin respect TMPDIR to resolve /tmp access failures on Termux, enabling tests to succeed on that platform.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the lock builtin's default path and adding a regression test; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/tests/compiling.rs
@tmchow
Copy link
Copy Markdown
Contributor Author

tmchow commented Apr 4, 2026

any chance this can get merged? got 2 approvals and CI is green. happy to rebase if needed.

@Mte90
Copy link
Copy Markdown
Member

Mte90 commented Apr 4, 2026

@tmchow we are working in this days to finalize the 0.6.0 release so we think to postpone the merge of your PR when that version is released.

@tmchow
Copy link
Copy Markdown
Contributor Author

tmchow commented Apr 9, 2026

@tmchow we are working in this days to finalize the 0.6.0 release so we think to postpone the merge of your PR when that version is released.

Thanks for letting me know!

The lock builtin hardcoded /tmp for default lock file paths, which fails
on environments like Termux where /tmp is not accessible. Use the TMPDIR
environment variable with a /tmp fallback instead.

Fixes amber-lang#1018
@tmchow tmchow force-pushed the osc/1018-termux-tmp-fallback branch from eb1e518 to 2a7023c Compare April 10, 2026 21:18
@Mte90
Copy link
Copy Markdown
Member

Mte90 commented Apr 29, 2026

@coderabbitai resume

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

✅ Actions performed

Reviews resumed.

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.

[Feature] Support Termex

3 participants