Consider the $HOME on Linux for locating the sketchbook folder

The aim of this change is to make "sudo -E processing{,-java}" work with custom libraries installed in the invoking user's home directory.
This commit is contained in:
gohai
2017-05-05 22:37:28 +02:00
parent 7393e6961e
commit f8add972d8
@@ -67,6 +67,26 @@ public class LinuxPlatform extends DefaultPlatform {
}
// Unlike many other UNIX programs, the JVM does not evaluate
// the HOME environment variable to construct user.home and
// friends, but solely relies on the UID of the current user
// for this purpose.
// For this reason user.home will always be "/root", even when
// a different user attempts to launch Processing with "sudo".
// (see also https://askubuntu.com/a/659882)
// Attempt to work around this in the least invasive manner,
// so that "sudo -E processing" or "sudo -E processing-java"
// will pick up the invoking user's sketchbook folder instead.
public File getDefaultSketchbookFolder() throws Exception {
String sysEnvHome = System.getenv("HOME");
if (sysEnvHome != null && 0 < sysEnvHome.length()) {
return new File(sysEnvHome, "sketchbook");
} else {
return super.getDefaultSketchbookFolder();
}
}
public void openURL(String url) throws Exception {
if (openFolderAvailable()) {
String launcher = Preferences.get("launcher");