-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdg-basedir.patch
69 lines (61 loc) · 2.38 KB
/
xdg-basedir.patch
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
# Move ~/.pki directory to ${XDG_DATA_HOME:-$HOME/.local}/share/pki on linux
# builds to follow the XDG Base Directory Specification. For details, refer to
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -30,6 +30,9 @@
#include "build/chromeos_buildflags.h"
#include "crypto/nss_crypto_module_delegate.h"
#include "crypto/nss_util_internal.h"
+#include "base/environment.h"
+#include "base/nix/xdg_util.h"
+#include "chrome/common/chrome_constants.h"
namespace crypto {
@@ -45,12 +48,25 @@ static const base::FilePath::CharType kReadOnlyCertDB[] =
base::FilePath GetDefaultConfigDirectory() {
base::FilePath dir;
+#if defined(OS_LINUX)
+ std::unique_ptr<base::Environment> env(base::Environment::Create());
+ dir = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgDataHomeEnvVar, base::nix::kDotDataDir);
+#else
base::PathService::Get(base::DIR_HOME, &dir);
+#endif
if (dir.empty()) {
+#if defined(OS_LINUX)
+ LOG(ERROR) << "Failed to get $HOME or $XDG_DATA_HOME directory.";
+#else
LOG(ERROR) << "Failed to get home directory.";
+#endif
return dir;
}
+#if defined(OS_LINUX)
+ dir = dir.Append(chrome::kBrowserProcessExecutableName).AppendASCII("pki").AppendASCII("nssdb");
+#else
dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
+#endif
if (!base::CreateDirectory(dir)) {
LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
dir.clear();
--- a/base/nix/xdg_util.cc
+++ b/base/nix/xdg_util.cc
@@ -41,6 +41,9 @@ std::optional<std::string>& GetXdgActivationToken() {
namespace base::nix {
+const char kDotDataDir[] = ".local/share";
+const char kXdgDataHomeEnvVar[] = "XDG_DATA_HOME";
+
const char kDotConfigDir[] = ".config";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
const char kXdgCurrentDesktopEnvVar[] = "XDG_CURRENT_DESKTOP";
--- a/base/nix/xdg_util.h
+++ b/base/nix/xdg_util.h
@@ -72,6 +72,12 @@ BASE_EXPORT extern const char kXdgConfigHomeEnvVar[];
// The XDG current desktop environment variable.
BASE_EXPORT extern const char kXdgCurrentDesktopEnvVar[];
+// The default XDG data directory name.
+BASE_EXPORT extern const char kDotDataDir[];
+
+// The XDG data directory environment variable.
+BASE_EXPORT extern const char kXdgDataHomeEnvVar[];
+
// The XDG session type environment variable.
BASE_EXPORT extern const char kXdgSessionTypeEnvVar[];