Fix runtime directory for Termux on Android#420
Conversation
The xdg library returns /run/user/<uid> which doesn't exist on Android. Added android alongside linux in the GOOS checks so runtime directory falls back to ~/.local/state/surge/runtime instead of failing with 'mkdir /run: read-only file system'.
| if (runtime.GOOS == "linux" || runtime.GOOS == "android") && runtimeEnv == "" { | ||
| runtimeBase = "" | ||
| } |
There was a problem hiding this comment.
No tests for Android path resolution
The new runtime.GOOS == "android" branch in both GetRuntimeDir and EnsureDirs is untested. A table-driven test overriding the env vars and mocking runtime.GOOS (via build tags or a helper variable) would confirm that the fallback to GetStateDir()/runtime is taken on Android when XDG_RUNTIME_DIR is unset, and that the XDG path is still respected when it is set.
Rule Used: What: All code changes must include tests for edge... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/config/paths.go
Line: 82-84
Comment:
**No tests for Android path resolution**
The new `runtime.GOOS == "android"` branch in both `GetRuntimeDir` and `EnsureDirs` is untested. A table-driven test overriding the env vars and mocking `runtime.GOOS` (via build tags or a helper variable) would confirm that the fallback to `GetStateDir()/runtime` is taken on Android when `XDG_RUNTIME_DIR` is unset, and that the XDG path is still respected when it is set.
**Rule Used:** What: All code changes must include tests for edge... ([source](https://app.greptile.com/review/custom-context?memory=2b22782d-3452-4d55-b059-e631b2540ce8))
How can I resolve this? If you propose a fix, please make it concise.|
Wanted to ask a couple a questions.
|
Yep
Obviously, I plan to propose a PR to termux-packages once this gets merged after which the package will be available through termux package manager |
|
Amazing! Thanks for contributing :) Also whenever the PR to termux package manager is merged please let us know so we can add termux to the list of install options. Happy Downloading 🚀 |
|
Yo @AbhiTheModder, I've already packaged Surge in Termux, specifically in the Termux User Repository. Since the code is quite stable, I can request that the package be moved to the main repository. The error you resolved had already been fixed with a .patch by Robert Kirkman. I asked him if I could remove the .patch since you adjusted the code. |
|
@LukeGTH That's great, I do use tur, I forgot to check it up there beforehand lOl, my bad. Awesome.
That would be nice too, even if not tur is good enough :) |
|
By the way, Surge is crashing the terminal (I don't know if it was because of your change or a change you didn't make to the code). If it was, no problem, you were just trying to help, I appreciate your effort. |
|
My mistake, it's not a crash, the terminal just freezes, like starting a daemon without using & |
Sure, I would love to |
I'm still on my old commit fix on termux and not facing anything like that, so, unrelated to my changes. Edit: It looks like this commit 73bca40 is related somehow |
|
I figured it wasn't you, how could a detection tool to check if it's Android do that? |
|
My name in discord is Luke |
|
maybe we need to have some android-specific tests to prevent regressions like this in the future? would really appreciate if a new issue is created for this! |
It's up to you, I think it's a good idea |
I'll open an issue, I'll call Abhi. |
|
Wait, I'll do a test; if it works, I won't open an issue. |
|
sure @LukeGTH Thanks :) |
Hmmm, let's open an issue |
The xdg library returns /run/user/ which doesn't exist on Android.
Added android alongside linux in the GOOS checks so runtime directory falls back to ~/.local/state/surge/runtime instead of failing with 'mkdir /run: read-only file system'.
Greptile Summary
Extends two
runtime.GOOSchecks inGetRuntimeDirandEnsureDirsto include"android", so that Termux builds fall back to~/.local/state/surge/runtimeinstead of trying (and failing) to use/run/user/<uid>fromxdg.RuntimeDir. The fix is minimal and correctly scoped — the XDG path is still honoured on Android whenXDG_RUNTIME_DIRis explicitly set by the user.Confidence Score: 4/5
Safe to merge; the change is a two-line, low-risk platform guard with no behavioural impact on non-Android targets.
Only P2 findings (missing tests for the new Android branch). Logic is correct, change is minimal, and existing Linux/Windows/macOS behaviour is unaffected.
No files require special attention beyond the missing test coverage for the Android case in
internal/config/paths.go.Important Files Changed
runtime.GOOS == "android"alongside"linux"in two conditions to force the state-dir fallback for the runtime directory on Termux, fixing the read-only/runfilesystem error; logic is correct and minimal.Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: support Termux(Android)" | Re-trigger Greptile