about summary refs log tree commit diff
path: root/config/firefox/release/D6695.diff
blob: d15342ba50fa87fe88e0a93cd9df2a118e37ea19 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
diff --git a/toolkit/moz.build b/toolkit/moz.build
index 109fb2ce9..0b871d931 100644
--- a/toolkit/moz.build
+++ b/toolkit/moz.build
@@ -72,3 +72,5 @@ with Files('mozapps/preferences/**'):
 with Files('pluginproblem/**'):
     BUG_COMPONENT = ('Core', 'Plug-ins')
 
+if CONFIG['ENABLE_TESTS']:
+    DIRS += ['tests/gtest']
diff --git a/toolkit/tests/gtest/TestXREAppDir.cpp b/toolkit/tests/gtest/TestXREAppDir.cpp
new file mode 100644
index 000000000..afa5f1b54
--- /dev/null
+++ b/toolkit/tests/gtest/TestXREAppDir.cpp
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsXREDirProvider.h"
+#include "gtest/gtest.h"
+
+#if defined(XP_UNIX) && !defined(XP_MACOSX)
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+// Remove @path and all its subdirs.
+static void
+cleanup(std::string path)
+{
+  nsresult rv;
+  nsCOMPtr<nsIFile> localDir;
+  rv = NS_NewNativeLocalFile(
+    nsDependentCString((char*)path.c_str()), true, getter_AddRefs(localDir));
+  EXPECT_EQ(NS_OK, rv);
+  rv = localDir->Remove(true);
+  EXPECT_EQ(NS_OK, rv);
+}
+
+// Create a temp dir and set HOME to it.
+// Upon successful completion, return the string with the path of the homedir.
+static std::string
+getNewHome()
+{
+  char tmpHomedir[] = "/tmp/mozilla-tmp.XXXXXX";
+  std::string homedir = mkdtemp(tmpHomedir);
+  EXPECT_EQ(0, setenv("HOME", (char*)homedir.c_str(), 1));
+  return homedir;
+}
+
+// Check if '$HOME/.mozilla' is used when it exists.
+TEST(toolkit_xre, LegacyAppUserDir)
+{
+  nsCOMPtr<nsIFile> localDir;
+  nsresult rv;
+  nsAutoCString cwd;
+  std::string homedir = getNewHome();
+  ASSERT_EQ(0, mkdir((char*)(homedir + "/.mozilla").c_str(), S_IRWXU));
+  rv = nsXREDirProvider::GetUserAppDataDirectory(getter_AddRefs(localDir));
+  ASSERT_EQ(NS_OK, rv);
+  localDir->GetNativePath(cwd);
+  std::string expectedAppDir = homedir + "/.mozilla/firefox";
+  std::string appDir = cwd.get();
+  ASSERT_EQ(expectedAppDir, appDir);
+  cleanup(homedir);
+}
+
+// Check if '$HOME/.local/share/mozilla' is used
+// if $HOME/.mozilla does not exist and the env
+// variable XDG_DATA_HOME is not set.
+TEST(toolkit_xre, XDGDefaultAppUserDir)
+{
+  nsCOMPtr<nsIFile> localDir;
+  nsresult rv;
+  nsAutoCString cwd;
+  std::string homedir = getNewHome();
+  ASSERT_EQ(0, unsetenv("XDG_DATA_HOME"));
+  rv = nsXREDirProvider::GetUserAppDataDirectory(getter_AddRefs(localDir));
+  ASSERT_EQ(NS_OK, rv);
+  localDir->GetNativePath(cwd);
+  std::string expectedAppDir = homedir + "/.local/share/mozilla/firefox";
+  std::string appDir = cwd.get();
+  ASSERT_EQ(expectedAppDir, appDir);
+  cleanup(homedir);
+}
+
+// Check if '$XDG_DATA_HOME/mozilla' is
+// used if '$HOME/.mozilla' does not exist
+// and the env variable XDG_DATA_HOME is set.
+TEST(toolkit_xre, XDGAppUserDir)
+{
+  nsCOMPtr<nsIFile> localDir;
+  nsresult rv;
+  nsAutoCString cwd;
+  std::string homedir = getNewHome();
+  ASSERT_EQ(0, setenv("XDG_DATA_HOME", (char*)homedir.c_str(), 1));
+  rv = nsXREDirProvider::GetUserAppDataDirectory(getter_AddRefs(localDir));
+  ASSERT_EQ(NS_OK, rv);
+  localDir->GetNativePath(cwd);
+  std::string expectedAppDir = homedir + "/mozilla/firefox";
+  std::string appDir = cwd.get();
+  ASSERT_EQ(expectedAppDir, appDir);
+  cleanup(homedir);
+}
+#endif
diff --git a/toolkit/tests/gtest/moz.build b/toolkit/tests/gtest/moz.build
new file mode 100644
index 000000000..4c1a10181
--- /dev/null
+++ b/toolkit/tests/gtest/moz.build
@@ -0,0 +1,17 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at http://mozilla.org/MPL/2.0/.
+
+Library('toolkit')
+
+UNIFIED_SOURCES = [
+    'TestXREAppDir.cpp',
+]
+
+LOCAL_INCLUDES += [
+  '/toolkit/xre'
+]
+
+FINAL_LIBRARY = 'xul-gtest'
diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
index 62da8de9b..164d7792e 100644
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -421,13 +421,6 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
     nsCOMPtr<nsIFile> localDir;
     rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), false);
     if (NS_SUCCEEDED(rv)) {
-#if defined(XP_MACOSX)
-      rv = localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla"));
-#else
-      rv = localDir->AppendNative(NS_LITERAL_CSTRING(".mozilla"));
-#endif
-    }
-    if (NS_SUCCEEDED(rv)) {
       localDir.swap(file);
     }
   }
@@ -1381,7 +1374,8 @@ nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
                                          GetAppName())))) {
       return NS_ERROR_FAILURE;
     }
-  } else if (NS_FAILED(localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla")))) {
+  }
+  else if (NS_FAILED(localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla")))) {
     return NS_ERROR_FAILURE;
   }
 
@@ -1562,6 +1556,9 @@ nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
   NS_ENSURE_SUCCESS(rv, rv);
 
   localDir = dirFileMac;
+
+  rv = localDir->AppendRelativeNativePath(nsDependentCString("Mozilla"));
+  NS_ENSURE_SUCCESS(rv, rv);
 #elif defined(XP_IOS)
   nsAutoCString userDir;
   if (GetUIKitDirectory(aLocal, userDir)) {
@@ -1587,6 +1584,9 @@ nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = localDir->AppendRelativeNativePath(nsDependentCString("Mozilla"));
+  NS_ENSURE_SUCCESS(rv, rv);
 #elif defined(XP_UNIX)
   const char* homeDir = getenv("HOME");
   if (!homeDir || !*homeDir)
@@ -1609,8 +1609,51 @@ nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
         rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache"));
     }
   } else {
+    bool exists;
+    // check old config ~/.mozilla
     rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
                                getter_AddRefs(localDir));
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = localDir->AppendRelativeNativePath(nsDependentCString(".mozilla"));
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = localDir->Exists(&exists);
+    NS_ENSURE_SUCCESS(rv, rv);
+    // otherwise, use new config
+    if (!exists) {
+      const char* xdghomedir = getenv("XDG_DATA_HOME");
+      if (!xdghomedir || !*xdghomedir) {
+        rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
+                                   getter_AddRefs(localDir));
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = localDir->AppendRelativeNativePath(nsDependentCString(".local"));
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = localDir->Exists(&exists);
+        if (NS_SUCCEEDED(rv) && !exists) {
+          rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
+          NS_ENSURE_SUCCESS(rv, rv);
+        }
+        rv = localDir->AppendRelativeNativePath(nsDependentCString("share"));
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = localDir->Exists(&exists);
+        if (NS_SUCCEEDED(rv) && !exists) {
+          rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
+        }
+      }
+      else {
+        rv = NS_NewNativeLocalFile(nsDependentCString(xdghomedir), true,
+                               getter_AddRefs(localDir));
+      }
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = localDir->AppendRelativeNativePath(nsDependentCString("mozilla"));
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = localDir->Exists(&exists);
+      NS_ENSURE_SUCCESS(rv, rv);
+      if (NS_SUCCEEDED(rv) && !exists) {
+        rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
+    }
   }
 #else
 #error "Don't know how to get product dir on your platform"
@@ -1734,20 +1777,12 @@ nsXREDirProvider::AppendSysUserExtensionPath(nsIFile* aFile)
 
 #if defined (XP_MACOSX) || defined(XP_WIN)
 
-  static const char* const sXR = "Mozilla";
-  rv = aFile->AppendNative(nsDependentCString(sXR));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   static const char* const sExtensions = "Extensions";
   rv = aFile->AppendNative(nsDependentCString(sExtensions));
   NS_ENSURE_SUCCESS(rv, rv);
 
 #elif defined(XP_UNIX)
 
-  static const char* const sXR = ".mozilla";
-  rv = aFile->AppendNative(nsDependentCString(sXR));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   static const char* const sExtensions = "extensions";
   rv = aFile->AppendNative(nsDependentCString(sExtensions));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1767,20 +1802,12 @@ nsXREDirProvider::AppendSysUserExtensionsDevPath(nsIFile* aFile)
 
 #if defined (XP_MACOSX) || defined(XP_WIN)
 
-  static const char* const sXR = "Mozilla";
-  rv = aFile->AppendNative(nsDependentCString(sXR));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   static const char* const sExtensions = "SystemExtensionsDev";
   rv = aFile->AppendNative(nsDependentCString(sExtensions));
   NS_ENSURE_SUCCESS(rv, rv);
 
 #elif defined(XP_UNIX)
 
-  static const char* const sXR = ".mozilla";
-  rv = aFile->AppendNative(nsDependentCString(sXR));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   static const char* const sExtensions = "systemextensionsdev";
   rv = aFile->AppendNative(nsDependentCString(sExtensions));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1843,10 +1870,6 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal)
   NS_ENSURE_SUCCESS(rv, rv);
 #elif defined(XP_UNIX)
   nsAutoCString folder;
-  // Make it hidden (by starting with "."), except when local (the
-  // profile is already under ~/.cache or XDG_CACHE_HOME).
-  if (!aLocal)
-    folder.Assign('.');
 
   if (!profile.IsEmpty()) {
     // Skip any leading path characters
@@ -1869,8 +1892,12 @@ nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal)
       folder.Append(vendor);
       ToLowerCase(folder);
 
-      rv = aFile->AppendNative(folder);
-      NS_ENSURE_SUCCESS(rv, rv);
+      // Keep the 'mozilla' path for cache:
+      // Use ${XDG_DATA_HOME:-$HOME/.cache}/mozilla/firefox
+      if (aLocal) {
+        rv = aFile->AppendNative(folder);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
 
       folder.Truncate();
     }
diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp
index 45628ed7a..dfe517c77 100644
--- a/xpcom/io/nsAppFileLocationProvider.cpp
+++ b/xpcom/io/nsAppFileLocationProvider.cpp
@@ -252,7 +252,7 @@ nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile** aLocalFile)
 //----------------------------------------------------------------------------------------
 // GetProductDirectory - Gets the directory which contains the application data folder
 //
-// UNIX   : ~/.mozilla/
+// UNIX   : ~/.mozilla/ or ${XDG_DATA_HOME:-~/.local/share}/mozilla
 // WIN    : <Application Data folder on user's machine>\Mozilla
 // Mac    : :Documents:Mozilla:
 //----------------------------------------------------------------------------------------
@@ -297,19 +297,80 @@ nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
     return rv;
   }
 #elif defined(XP_UNIX)
-  rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), true,
+  const char* homeDir = PR_GetEnv("HOME");
+  /* check old config ~/.mozilla */
+  rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
                              getter_AddRefs(localDir));
   if (NS_FAILED(rv)) {
     return rv;
   }
+  rv = localDir->AppendRelativeNativePath(nsDependentCString(".mozilla"));
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  rv = localDir->Exists(&exists);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  /* otherwise, use new config */
+  if (!exists) {
+    const char* xdghomedir = PR_GetEnv("XDG_DATA_HOME");
+    if (!xdghomedir || !*xdghomedir) {
+      /* XDG_DATA_HOME=$HOME/.local/share */
+      rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
+                                 getter_AddRefs(localDir));
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
+      rv = localDir->AppendRelativeNativePath(nsDependentCString(".local"));
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
+      rv = localDir->Exists(&exists);
+      if (NS_SUCCEEDED(rv) && !exists) {
+        rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
+        if (NS_FAILED(rv)) {
+          return rv;
+        }
+      }
+      rv = localDir->AppendRelativeNativePath(nsDependentCString("share"));
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
+      rv = localDir->Exists(&exists);
+      if (NS_SUCCEEDED(rv) && !exists) {
+        rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0755);
+      }
+    }
+    else {
+      rv = NS_NewNativeLocalFile(nsDependentCString(xdghomedir), true,
+                                 getter_AddRefs(localDir));
+    }
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
+    rv = localDir->AppendRelativeNativePath(nsDependentCString("mozilla"));
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
+  }
 #else
 #error dont_know_how_to_get_product_dir_on_your_platform
 #endif
 
+#if !defined(XP_UNIX) || defined(XP_MACOSX)
+  // Since we have to check for legacy configuration, we have
+  // the complete path for Linux already, so this is not
+  // needed. If we stop checking for legacy at some point,
+  // then we can change this to not be protected by
+  // this clause.
   rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
+
   if (NS_FAILED(rv)) {
     return rv;
   }
+#endif
+
   rv = localDir->Exists(&exists);
 
   if (NS_SUCCEEDED(rv) && !exists) {
@@ -329,7 +390,7 @@ nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
 //----------------------------------------------------------------------------------------
 // GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
 //
-// UNIX   : ~/.mozilla/
+// UNIX   : ~/.mozilla/ or ${XDG_DATA_HOME:-~/.local/share}/mozilla
 // WIN    : <Application Data folder on user's machine>\Mozilla\Profiles
 // Mac    : :Documents:Mozilla:Profiles:
 //----------------------------------------------------------------------------------------