xdg-basedir.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Move ~/.pki directory to ${XDG_DATA_HOME:-$HOME/.local}/share/pki on linux
  2. # builds to follow the XDG Base Directory Specification. For details, refer to
  3. # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
  4. --- a/base/nix/xdg_util.cc
  5. +++ b/base/nix/xdg_util.cc
  6. @@ -29,6 +29,8 @@
  7. const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
  8. const char kXdgCurrentDesktopEnvVar[] = "XDG_CURRENT_DESKTOP";
  9. const char kXdgSessionTypeEnvVar[] = "XDG_SESSION_TYPE";
  10. +const char kDotDataDir[] = ".local/share";
  11. +const char kXdgDataHomeEnvVar[] = "XDG_DATA_HOME";
  12. FilePath GetXDGDirectory(Environment* env, const char* env_name,
  13. const char* fallback_dir) {
  14. --- a/base/nix/xdg_util.h
  15. +++ b/base/nix/xdg_util.h
  16. @@ -37,6 +37,12 @@
  17. // The XDG session type environment variable.
  18. BASE_EXPORT extern const char kXdgSessionTypeEnvVar[];
  19. +// The default XDG data directory name.
  20. +BASE_EXPORT extern const char kDotDataDir[];
  21. +
  22. +// The XDG data directory environment variable.
  23. +BASE_EXPORT extern const char kXdgDataHomeEnvVar[];
  24. +
  25. // Utility function for getting XDG directories.
  26. // |env_name| is the name of an environment variable that we want to use to get
  27. // a directory path. |fallback_dir| is the directory relative to $HOME that we
  28. --- a/crypto/nss_util.cc
  29. +++ b/crypto/nss_util.cc
  30. @@ -30,6 +30,9 @@
  31. #include "build/chromeos_buildflags.h"
  32. #include "crypto/nss_crypto_module_delegate.h"
  33. #include "crypto/nss_util_internal.h"
  34. +#include "base/environment.h"
  35. +#include "base/nix/xdg_util.h"
  36. +#include "chrome/common/chrome_constants.h"
  37. namespace crypto {
  38. @@ -45,12 +48,21 @@
  39. base::FilePath GetDefaultConfigDirectory() {
  40. base::FilePath dir;
  41. +#if defined(OS_LINUX)
  42. + std::unique_ptr<base::Environment> env(base::Environment::Create());
  43. + dir = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgDataHomeEnvVar, base::nix::kDotDataDir);
  44. +#else
  45. base::PathService::Get(base::DIR_HOME, &dir);
  46. +#endif
  47. if (dir.empty()) {
  48. - LOG(ERROR) << "Failed to get home directory.";
  49. + LOG(ERROR) << "Failed to get $HOME or $XDG_DATA_HOME directory.";
  50. return dir;
  51. }
  52. +#if defined(OS_LINUX)
  53. + dir = dir.Append(chrome::kBrowserProcessExecutableName).AppendASCII("pki").AppendASCII("nssdb");
  54. +#else
  55. dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
  56. +#endif
  57. if (!base::CreateDirectory(dir)) {
  58. LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
  59. dir.clear();