From f8add972d8e055cbfca54500cf3535e964c932cb Mon Sep 17 00:00:00 2001 From: gohai Date: Fri, 5 May 2017 22:37:28 +0200 Subject: [PATCH] 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. --- .../app/platform/LinuxPlatform.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/processing/app/platform/LinuxPlatform.java b/app/src/processing/app/platform/LinuxPlatform.java index cf539fdb6..b89ababaa 100644 --- a/app/src/processing/app/platform/LinuxPlatform.java +++ b/app/src/processing/app/platform/LinuxPlatform.java @@ -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");