summarylogtreecommitdiffstats
path: root/xdg-basedir-compliant-userPrefs.patch
blob: 78601d6442b41f6a4f3332b56e78dbb484d2e5d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# TODO: consider changing system-wide preferences
#       consider removing dot in front of 'lock' files (both system and user)
--- a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
+++ b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
@@ -114,9 +114,30 @@
     private static void setupUserRoot() {
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
             public Void run() {
-                userRootDir =
-                      new File(System.getProperty("java.util.prefs.userRoot",
-                      System.getProperty("user.home")), ".java/.userPrefs");
+                /* On Linux systems, put the userPrefs dir into
+                 * ${XDG_CONFIG_HOME:-$HOME/.config}/java/userPrefs in order to
+                 * follow the XDG Base Directory Specification.
+                 */
+                if (System.getProperty("os.name").equals("Linux")) {
+                    /* assume findable homedir, which the jvm already does */
+                    String xdgDefaultConfigHome = System.getenv("HOME") +
+                                                  "/.config";
+                    String xdgConfigHomeEnvVar = "XDG_CONFIG_HOME";
+                    String xdgConfigDir;
+
+                    String xdgSetConfigDir = System.getenv(xdgConfigHomeEnvVar);
+
+                    if (xdgSetConfigDir == null)
+                        xdgConfigDir = xdgDefaultConfigHome;
+                    else
+                        xdgConfigDir = xdgSetConfigDir;
+
+                    userRootDir = new File(xdgConfigDir, "java/userPrefs");
+                } else {
+                    userRootDir =
+                        new File(System.getProperty("java.util.prefs.userRoot",
+                        System.getProperty("user.home")), ".java/.userPrefs");
+                }
                 // Attempt to create root dir if it does not yet exist.
                 if (!userRootDir.exists()) {
                     if (userRootDir.mkdirs()) {