Skip to content

Fix runtime directory for Termux on Android#420

Merged
SuperCoolPencil merged 1 commit intoSurgeDM:mainfrom
AbhiTheModder:fix/android-termux
Apr 30, 2026
Merged

Fix runtime directory for Termux on Android#420
SuperCoolPencil merged 1 commit intoSurgeDM:mainfrom
AbhiTheModder:fix/android-termux

Conversation

@AbhiTheModder
Copy link
Copy Markdown
Contributor

@AbhiTheModder AbhiTheModder commented Apr 28, 2026

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.GOOS checks in GetRuntimeDir and EnsureDirs to include "android", so that Termux builds fall back to ~/.local/state/surge/runtime instead of trying (and failing) to use /run/user/<uid> from xdg.RuntimeDir. The fix is minimal and correctly scoped — the XDG path is still honoured on Android when XDG_RUNTIME_DIR is 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

Filename Overview
internal/config/paths.go Adds runtime.GOOS == "android" alongside "linux" in two conditions to force the state-dir fallback for the runtime directory on Termux, fixing the read-only /run filesystem error; logic is correct and minimal.
Prompt To Fix All 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.

Reviews (1): Last reviewed commit: "fix: support Termux(Android)" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

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'.
Comment thread internal/config/paths.go
Comment on lines +82 to 84
if (runtime.GOOS == "linux" || runtime.GOOS == "android") && runtimeEnv == "" {
runtimeBase = ""
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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.

@SuperCoolPencil
Copy link
Copy Markdown
Member

Hi @AbhiTheModder

Wanted to ask a couple a questions.

  • Surge doesnt officially support Android yet. I am assuming you build manually and use via cli alone?
  • Would you want Surge to support Android? If so, why? (I really dont know about the Android DM scene)

@AbhiTheModder
Copy link
Copy Markdown
Contributor Author

AbhiTheModder commented Apr 30, 2026

  • Surge doesnt officially support Android yet. I am assuming you build manually and use via cli alone?

Yep

  • Would you want Surge to support Android? If so, why? (I really dont know about the Android DM scene)

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 pkg. As for your other question, I use cli DM a lot, I have used aria2c, axel and many others, just happened to across serge and wanted to give it a try after looking at its benchmarks but that /run issue happened and I explored & applied simplest fix i could think of, loving it so far though I would love if there could be a very similar kind of support like aria2c/axel where I just download through cli flags, (not really fan of opening TUI, or keeping server running when I just need to download 1/2 urls)

@SuperCoolPencil
Copy link
Copy Markdown
Member

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 🚀

@SuperCoolPencil SuperCoolPencil merged commit 6205957 into SurgeDM:main Apr 30, 2026
8 checks passed
@LukeGTH
Copy link
Copy Markdown

LukeGTH commented Apr 30, 2026

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.
And yea, you can install the Surge package with: pkg install tur-repo, and pkg install surge-cli.

@AbhiTheModder AbhiTheModder deleted the fix/android-termux branch May 1, 2026 00:26
@AbhiTheModder
Copy link
Copy Markdown
Contributor Author

AbhiTheModder commented May 1, 2026

@LukeGTH That's great, I do use tur, I forgot to check it up there beforehand lOl, my bad. Awesome.

I can request that the package be moved to the main repository.

That would be nice too, even if not tur is good enough :)

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

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.
I should have spoken to Kirkman already, but he hasn't responded yet, and the other devs don't like direct pings.
So, do you want to join the Termux server? @AbhiTheModder I added another @ because I don't know if you're still subscribed to this PR.

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

My mistake, it's not a crash, the terminal just freezes, like starting a daemon without using &

@AbhiTheModder
Copy link
Copy Markdown
Contributor Author

So, do you want to join the Termux server?

Sure, I would love to

@AbhiTheModder
Copy link
Copy Markdown
Contributor Author

AbhiTheModder commented May 1, 2026

My mistake, it's not a crash, the terminal just freezes, like starting a daemon without using &

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

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

So, do you want to join the Termux server?

Sure, I would love to

Here is the Discord server

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

My mistake, it's not a crash, the terminal just freezes, like starting a daemon without using &

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?

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

My name in discord is Luke

@SuperCoolPencil
Copy link
Copy Markdown
Member

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!

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

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

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

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.

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

Wait, I'll do a test; if it works, I won't open an issue.

@SuperCoolPencil
Copy link
Copy Markdown
Member

sure @LukeGTH

Thanks :)

@LukeGTH
Copy link
Copy Markdown

LukeGTH commented May 1, 2026

sure @LukeGTH

Thanks :)

Hmmm, let's open an issue

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.

3 participants