summarylogtreecommitdiffstats
path: root/xdg-user-directories-compliant.patch
blob: 159b5ba0419f51298783d34606f91a610f8456a7 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff -aru a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
--- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	2022-04-06 10:38:33.754390574 +0800
+++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	2022-04-06 10:38:43.832555455 +0800
@@ -356,7 +356,29 @@
             String userDir = System.getProperty("user.home");
             String version = System.getProperty("java.version");
             String fs = File.separator;
-            String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
+	    String dir;
+
+            /* On Linux systems, put the font config into 
+             * ${XDG_CONFIG_HOME:-$HOME/.config}/java/fonts in order to follow
+             * the XDG Base Directory Specification.
+             */
+            if (System.getProperty("os.name").equals("Linux")) {
+                /* assume homedir can be found, 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;
+
+                dir = xdgConfigDir+"/java/fonts/"+version;
+            } else {
+                dir = userDir+fs+".java"+fs+"fonts"+fs+version;
+            }
             String lang = SunToolkit.getStartupLocale().getLanguage();
             String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
                 osName+"-"+osVersion+"-"+lang+".properties";
diff -aru a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
--- a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java	2022-04-06 10:38:33.791062882 +0800
+++ b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java	2022-04-06 10:38:43.862559781 +0800
@@ -113,9 +113,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()) {