Skip to content

Add support for custom temporary directories in image creation scripts#26

Open
ali-ghanati wants to merge 2 commits into
drakmor:mainfrom
ali-ghanati:main
Open

Add support for custom temporary directories in image creation scripts#26
ali-ghanati wants to merge 2 commits into
drakmor:mainfrom
ali-ghanati:main

Conversation

@ali-ghanati

@ali-ghanati ali-ghanati commented May 17, 2026

Copy link
Copy Markdown

note: because of my poor english, I've wrote description using ai, and did some refactor in code using ai, I just wanted to help and improve this awesome project from my own point of view, thank you everyone who helped this project

Summary

Adds an optional temp/work directory flag across all exFAT image creation paths so large builds can use a fast or spacious disk (e.g. /mnt/hdd, D:\temp) instead of default system temp or fixed mount paths.

  • Linux (mkexfat.sh): -t / --tmp-dir / --temp-dir may appear anywhere in the command line. Creates a unique mount dir under the chosen base (mkexfat.XXXXXX). Mount prefers direct exfat-fuse file access and falls back to -o loop when needed (fixes loop setup failures on some removable exFAT targets).
  • macOS (mkexfat_macos.sh): Same flag parsing; when omitted, behavior is unchanged (mktemp defaults). When set, sizing scratch file and mount staging dir are created under the given path.
  • Windows (New-OsfExfatImage.ps1, make_image.bat): -TempDir / -t (PowerShell) and -t / --tmp-dir / --temp-dir (batch). Sets %TEMP% / %TMP% for format redirect files and related scratch work.

Motivation

Large game/app images (~80GB+) can fail or run slowly when temp/mount work uses root-owned paths, small system partitions, or loop mounts on USB exFAT volumes. Letting users point temp work at another drive avoids those issues without changing default behavior for existing scripts.

Behavior

Platform Without temp flag With -t / --tmp-dir
Linux Temp mount under /tmp/mkexfat.* Temp mount under <dir>/mkexfat.*
macOS System default mktemp <dir>/mkexfat.* and <dir>/mkexfat_sizes.*
Windows Windows default %TEMP% User directory for script temp files

Output image path is always the positional/output argument you pass; only intermediate work moves to the temp directory.


Linux — mkexfat.sh

Requires: exfatprogs, exfat-fuse, fuse3, rsync
(often run with sudo for mount operations)

# Default (temp under /tmp)
./mkexfat.sh /path/to/payload /path/to/output.exfat

# Use another disk for mount staging (flag can be anywhere)
./mkexfat.sh -t /mnt/hdd /mnt/hdd/payload /media/usb/game.exfat

./mkexfat.sh /mnt/hdd/payload /media/usb/game.exfat --tmp-dir /mnt/hdd

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Specify a custom temporary directory across Windows, macOS, and Linux image-creation tools (-t/--tmp-dir), including examples in help text.

* **Improvements**
  * Improved CLI parsing, validation, and usage messages.
  * Safer mount/cleanup flow and per-run temp/mount directories to avoid conflicts and ensure proper cleanup.
  * Default output behavior and fallbacks clarified for more reliable image creation.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/drakmor/ShadowMountPlus/pull/26?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

- Updated `make_image.bat`, `mkexfat_macos.sh`, and `mkexfat.sh` to accept a temporary directory argument for improved flexibility.
- Enhanced error handling for missing or invalid temporary directories.
- Modified `New-OsfExfatImage.ps1` to utilize a custom temp directory for logs and temporary files.
- Updated usage instructions in all scripts to reflect new options.
@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 92284f79-afba-42c4-8713-d31e05e94403

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6505d and b45396c.

📒 Files selected for processing (4)
  • New-OsfExfatImage.ps1
  • make_image.bat
  • mkexfat.sh
  • mkexfat_macos.sh

📝 Walkthrough

Walkthrough

Adds an optional temp-directory option across PowerShell, Batch, Linux, and macOS scripts to control where temporary files and mount points are created during exFAT image building; includes CLI parsing, validation, dynamic mounts, and a PowerShell temp-file helper.

Changes

Temporary Directory Control Across Platforms

Layer / File(s) Summary
PowerShell Parameter and Temp Directory Helpers
New-OsfExfatImage.ps1
New-OsfExfatImage.ps1 adds a -TempDir parameter (alias -t) with documentation, implements Initialize-ScriptTempDir to validate and configure environment variables, and New-ScriptTempFile to create temp files within the specified directory.
PowerShell Format and Initialization Integration
New-OsfExfatImage.ps1
Invoke-FormatVolume uses the new temp-file helper for format.com stdout/stderr redirection instead of direct system temp names, and the main script flow initializes the temp directory before image creation.
Batch Script Argument Parsing and Pass-Through
make_image.bat
Argument parsing replaces positional handling with a loop parser supporting -t, --tmp-dir, and --temp-dir flags; validation confirms directory existence and passes it to PowerShell conditionally; usage documentation includes new examples.
Linux Shell Script CLI Parsing and Dynamic Mounting
mkexfat.sh
Option parsing supports -t/--tmp-dir/--temp-dir alongside -h/--help and -- positional separation; new cleanup() trap handler unmounts and removes dynamically created mount directories; mounting attempts unwrapped exfat-fuse before falling back to loop device and uses rsync into the dynamic mount.
macOS Shell Script CLI Parsing and Conditional Temp Placement
mkexfat_macos.sh
Option parsing supports -t/--tmp-dir/--temp-dir with -- separation and expands validation; intermediate sizes file and mount-point directory are conditionally placed under the user-specified temp base when provided.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

"🐰 I hopped through temp paths wide and narrow,
I tucked the files where you point the burrow,
Mounts cleaned up with a tidy sweep,
ExFAT sleeps safe and copies sleep deep,
Hooray — one small hop to a neater burrow!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately and concisely describes the main change across all affected scripts: adding support for custom temporary directories in image creation tools.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@make_image.bat`:
- Around line 75-77: Replace the insecure hardcoded "-ExecutionPolicy Bypass"
invocations for launching "%SCRIPT%" with a safer approach: sign
New-OsfExfatImage.ps1 using a code-signing certificate and change the PowerShell
launches in the batch file (the two powershell.exe calls that pass -File
"%SCRIPT%") to use "-ExecutionPolicy RemoteSigned"; if signing cannot be done,
add clear documentation near the "%SCRIPT%" invocation explaining the security
implications of using Bypass and require an explicit opt-in approval step
instead of silently bypassing execution policy.

In `@mkexfat_macos.sh`:
- Around line 76-79: Add an explicit validation step before normalizing OUTPUT:
check the parent directory of OUTPUT (derived via dirname "$OUTPUT") exists and
is writable; if it does not, print a clear error message referencing OUTPUT and
exit non-zero instead of letting the subsequent cd fail. Implement this
validation right before the OUTPUT="$(cd ...)" normalization and keep the OUTPUT
variable name and the dirname/"basename" approach so the check targets the same
path used for normalization.

In `@mkexfat.sh`:
- Around line 84-87: The current check only verifies TMP_BASE exists; change it
to validate that TMP_BASE is both writable and searchable/executable so mktemp
and child processes can create files there: update the directory check around
TMP_BASE to assert -d, -w and -x (or attempt a safe mktemp creation) and, on
failure, emit a clear error mentioning missing write/execute permissions for
TMP_BASE and exit 1; reference the TMP_BASE variable and the mktemp usage in the
script when implementing the check.

In `@New-OsfExfatImage.ps1`:
- Around line 140-149: The Initialize-ScriptTempDir function currently only
checks existence; update it to fail fast on non-writable directories by
attempting a safe write/delete in $resolved (e.g., create and remove a small
temp marker file) and throw a clear error if that operation fails; keep the
existing Resolve-Path, $script:ScriptTempDir assignment and env:TEMP/TMP updates
but perform the write-check before setting those and before continuing, and
ensure the thrown message mentions the directory and that it is not writable to
aid debugging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c0061dd0-8ac7-44cf-9c95-cd3cc12002a5

📥 Commits

Reviewing files that changed from the base of the PR and between 8622d87 and 9d6505d.

📒 Files selected for processing (4)
  • New-OsfExfatImage.ps1
  • make_image.bat
  • mkexfat.sh
  • mkexfat_macos.sh

Comment thread make_image.bat Outdated
Comment thread mkexfat_macos.sh
Comment thread mkexfat.sh
Comment thread New-OsfExfatImage.ps1
@ali-ghanati ali-ghanati reopened this May 17, 2026
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