Skip to content

Commit 3f78af3

Browse files
shai-almogclaude
andcommitted
Linux port: override getAppHomePath so relative File paths resolve to a writable dir
new File("tmpaudio.wav").getAbsolutePath() resolved to /null/tmpaudio.wav, so a recorded clip came back as file:///null/tmpaudio.wav and could not be played. The base getAppHomePath() builds listFilesystemRoots()[0] + getProperty("AppName", packageName), which on Linux is "/" + the app name -- unwritable -- and "/null/" when no AppName/packageName is set. Override it to the per-user storage directory (the same writable location Storage and capturePhoto already use), which fixes every relative File path in the port, not just the audio capture round-trip. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3bab176 commit 3f78af3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Ports/LinuxPort/src/com/codename1/impl/linux/LinuxImplementation.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,29 @@ public String[] listFilesystemRoots() {
22912291
return LinuxNative.fileRoots();
22922292
}
22932293

2294+
/**
2295+
* Anchors the app home at the per-user storage directory.
2296+
*
2297+
* The base getAppHomePath() builds {@code listFilesystemRoots()[0] + AppName},
2298+
* which here is the real filesystem root "/" + the app name -- unwritable, and
2299+
* literally "/null/" when neither an AppName property nor a packageName is set.
2300+
* That made {@code new File("x").getAbsolutePath()} resolve to "/null/x" (which
2301+
* is exactly why a recorded "tmpaudio.wav" came back as file:///null/tmpaudio.wav
2302+
* and would not play). Use the same writable per-user directory that Storage and
2303+
* capturePhoto already rely on.
2304+
*/
2305+
@Override
2306+
public String getAppHomePath() {
2307+
String dir = LinuxNative.storageDir();
2308+
if (dir == null || dir.length() == 0) {
2309+
dir = "/tmp";
2310+
}
2311+
if (!dir.endsWith("/")) {
2312+
dir += "/";
2313+
}
2314+
return dir;
2315+
}
2316+
22942317
@Override
22952318
public String[] listFiles(String directory) throws IOException {
22962319
return LinuxNative.fileList(stripFileUrl(directory));

0 commit comments

Comments
 (0)