fix: preserve executable modes when extracting templates
Description
Preserves executable file modes when v3 template assets are extracted. This keeps the generated Android gradlew script executable after wails init, so wails3 task android:package can run it without a manual chmod.
Fixes #5606
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How Has This Been Tested?
- [x] Linux
Linux distro: Ubuntu 24.04-based container
cd v3 && go test ./internal/gosod -run 'TestExtract_StandardFilePreservesMode|TestExtract_StandardFile$' -count=1cd v3 && go test ./internal/gosod -count=1cd v3 && git diff --check
Test Configuration
wails doctor was not run in this container; the change is covered by focused internal/gosod unit tests.
Checklist:
- [ ] (v2 only) I have updated
website/src/pages/changelog.mdxwith details of this PR (v3 changelog entries are added automatically) - [x] My code follows the general coding style of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
Summary by CodeRabbit
-
Bug Fixes
- Fixed executable permissions not being preserved when extracting v3 template assets. Executable bits are now correctly restored for extracted files, including generated Android
gradlewscripts.
- Fixed executable permissions not being preserved when extracting v3 template assets. Executable bits are now correctly restored for extracted files, including generated Android
-
Tests
- Added regression coverage for embedded
gradlewextraction and new permission-focused checks (shebang-driven executability, executable source preservation, and read-only sources staying writable), skipping Windows where applicable.
- Added regression coverage for embedded
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3e38e598-1462-4604-8a40-08f58030a4d1
π₯ Commits
Reviewing files that changed from the base of the PR and between e4d1ed72cda1c241755d52f8f5b524c01d14a510 and 5ca95eba330c7a17d7ad9fa2c15b38a7c17a3060.
π Files selected for processing (3)
v3/internal/commands/gradlew_exec_test.gov3/internal/gosod/gosod.gov3/internal/gosod/gosod_test.go
β Files skipped from review due to trivial changes (1)
- v3/internal/commands/gradlew_exec_test.go
π§ Files skipped from review as they are similar to previous changes (1)
- v3/internal/gosod/gosod.go
Walkthrough
processTemplates and copyFile in gosod.go now restore executable bits using source file mode detection and shebang fallback: processTemplates calls makeExecutableIfNeeded after closing rendered template files, while copyFile uses os.OpenFile with explicit flags and then conditionally applies source executable bits. Unit tests validate shebang-based and pre-executable file preservation while ensuring read-only sources remain writable. An end-to-end regression test confirms embedded gradlew extracts executable. Changelog documents the fix for Android build failures.
Changes
Preserve executable file permissions during template extraction
| Layer / File(s) | Summary |
|---|---|
gosod.go executable bit restoration in processTemplates and copyFile v3/internal/gosod/gosod.go |
processTemplates calls makeExecutableIfNeeded after closing rendered template files to recover executability from shebang detection. copyFile opens the destination with os.OpenFile using O_WRONLY|O_CREATE|O_TRUNC and mode 0666, copies source bytes via io.Copy, closes the destination, then Stat()s the source and calls makeExecutableIfNeeded(dst, srcMode) to apply executable bits either from source mode or from #! shebang detection. |
gosod_test.go unit tests for executable preservation v3/internal/gosod/gosod_test.go |
runtime import added for OS-specific test skipping. Three new tests validate: TestExtract_ShebangScriptBecomesExecutable confirms shebang-only files with read-only source mode become executable after extraction, TestExtract_SourceExecBitPreserved verifies pre-executable source mode is preserved, and TestExtract_ReadOnlySourceModeStaysWritable ensures read-only source mode stays writable without gaining executable bits. All tests skip on Windows. callbackErrFileInfo method stubs reformatted with equivalent return values; alignment corrected in resolveTarget test region. |
gradlew_exec_test.go end-to-end extraction test v3/internal/commands/gradlew_exec_test.go |
Adds TestEmbeddedGradlewExtractsExecutable regression test (skipped on Windows) that verifies the embedded build_assets/android/gradlew is initially non-executable, extracts the embedded android subtree to a temp directory, and asserts the extracted gradlew file becomes executable. |
Changelog v3/UNRELEASED_CHANGELOG.md |
Adds a Fixed entry noting executable permissions are now preserved when extracting template assets, fixing Android gradlew scripts (referencing #5606). |
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~25 minutes
Poem
π Behold, the
gradlewscript now takes flight!processTemplatesandcopyFilepreserve the executable right, Shebang detection and source bits align, No more permission deniedβAndroid builds will shine! β¨
Suggested labels
reviewed β
Suggested reviewers
- leaanthony
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 60.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 |
|---|---|---|
| Title check | β Passed | The title clearly and concisely summarizes the main change: preserving executable modes when extracting templates, which directly addresses the core issue. |
| Description check | β Passed | The PR description provides a clear summary, references the fixed issue (#5606), documents the testing performed (Linux), and completes relevant checklist items including tests and code review. |
| Linked Issues check | β Passed | The code changes fully implement the fix for #5606: executable permissions are preserved when extracting template assets, ensuring the Android gradlew script is executable after wails init. |
| Out of Scope Changes check | β Passed | All changes are directly related to fixing #5606: they modify template extraction logic to preserve executable modes, add relevant tests, and update the changelog appropriately. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
π§ golangci-lint (2.12.2)
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Addressed both review comments in e4d1ed72c:
-
copyFileperms β No longer copy the source's full permission bits intoos.OpenFile(which would make files read-only when the source is an embeddedfs.FSreporting 0444/0555, and would silently no-op on overwrite since the perm arg is ignored for existing files). Now the file is created with 0666 so the umask applies, and only the executable bits are synced afterward viaos.Chmod. -
Flaky mode assertion β
TestExtract_StandardFilePreservesModenow asserts on the executable bits (&0111) instead of an exact 0755, and skips on Windows. AddedTestExtract_ReadOnlySourceModeStaysWritableas a regression test confirming a read-only (0444) source extracts to a writable, non-executable file.
go test ./internal/gosod -count=1 passes; gofmt clean.
Thanks for this, @cyphercodes β you correctly identified that embedded scripts lose their exec bit when extracted (go:embed reports them as non-executable), which broke ./gradlew.
That specific symptom (#5606) is already resolved on master: the Android Taskfile now does chmod +x ./gradlew immediately before invoking it (added as part of the mobile support work in #5562/#5602). Your approach of fixing the root cause in the gosod extractor is arguably cleaner, but since the live bug is already handled and this PR doesn't remove the now-redundant Taskfile chmods, I'm going to close it to avoid two parallel mechanisms for the same thing.
If we later find more embedded scripts hitting this (and want to drop the per-Taskfile chmods), the gosod approach here is a good reference. Really appreciate the fix and the test. π