From 807bf7172f41f110276ec6e8c0d6df25097d388d Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Wed, 6 Aug 2025 18:49:06 -0700 Subject: [PATCH] Set linux credential store path. PiperOrigin-RevId: 791932855 --- internal/platform/implementation/g3/BUILD | 11 ++++++ .../platform/implementation/g3/device_info.h | 11 ++---- .../implementation/g3/linux_path_util.h | 36 +++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 internal/platform/implementation/g3/linux_path_util.h diff --git a/internal/platform/implementation/g3/BUILD b/internal/platform/implementation/g3/BUILD index 9872e1c0..db53a1bc 100644 --- a/internal/platform/implementation/g3/BUILD +++ b/internal/platform/implementation/g3/BUILD @@ -15,6 +15,16 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") # limitations under the License. licenses(["notice"]) +cc_library( + name = "linux_path_util", + hdrs = ["linux_path_util.h"], + visibility = ["//visibility:public"], + deps = [ + "//internal/base:file_path", + "//internal/base:files", + ], +) + cc_library( name = "types", testonly = True, @@ -37,6 +47,7 @@ cc_library( ], visibility = ["//visibility:private"], deps = [ + ":linux_path_util", ":preferences_repository", "//internal/base:file_path", "//internal/base:files", diff --git a/internal/platform/implementation/g3/device_info.h b/internal/platform/implementation/g3/device_info.h index 85c306aa..be5b4fa6 100644 --- a/internal/platform/implementation/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -15,7 +15,6 @@ #ifndef PLATFORM_IMPL_G3_DEVICE_INFO_H_ #define PLATFORM_IMPL_G3_DEVICE_INFO_H_ -#include #include #include #include @@ -26,6 +25,7 @@ #include "internal/base/file_path.h" #include "internal/base/files.h" #include "internal/platform/implementation/device_info.h" +#include "internal/platform/implementation/g3/linux_path_util.h" namespace nearby { namespace g3 { @@ -49,14 +49,7 @@ class DeviceInfo : public api::DeviceInfo { } std::optional GetLocalAppDataPath() const override { - const char* home_dir = getenv("HOME"); - if (home_dir == nullptr) { - return Files::GetTemporaryDirectory(); - } - // Yhis matches the .NET LocalAppData directory on Linux. - return FilePath(home_dir) - .append(FilePath(".local")) - .append(FilePath("share")); + return GetAppDataPath(); } std::optional GetCommonAppDataPath() const override { diff --git a/internal/platform/implementation/g3/linux_path_util.h b/internal/platform/implementation/g3/linux_path_util.h new file mode 100644 index 00000000..96dc8c08 --- /dev/null +++ b/internal/platform/implementation/g3/linux_path_util.h @@ -0,0 +1,36 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_G3_LINUX_PATH_UTIL_H_ +#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_G3_LINUX_PATH_UTIL_H_ + +#include + +#include "internal/base/file_path.h" +#include "internal/base/files.h" + +namespace nearby::g3 { + +inline FilePath GetAppDataPath() { + const char* home_dir = getenv("HOME"); + if (home_dir == nullptr) { + return Files::GetTemporaryDirectory(); + } + // This matches the .NET LocalAppData directory on Linux. + return FilePath(home_dir).append(FilePath(".local/share")); +} + +} // namespace nearby::g3 + +#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_G3_LINUX_PATH_UTIL_H_