From d69bd78d13cb9e28ee1b472b4086ec00f05144e1 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Mon, 8 Apr 2024 12:08:43 -0700 Subject: [PATCH] Fix deadlock during log rotations. PiperOrigin-RevId: 622916139 --- internal/platform/device_info.h | 4 +++- internal/platform/device_info_impl.cc | 5 +++++ internal/platform/device_info_impl.h | 3 ++- internal/test/fake_device_info.h | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/platform/device_info.h b/internal/platform/device_info.h index 8769d560..c3454479 100644 --- a/internal/platform/device_info.h +++ b/internal/platform/device_info.h @@ -15,7 +15,8 @@ #ifndef PLATFORM_PUBLIC_DEVICE_INFO_H_ #define PLATFORM_PUBLIC_DEVICE_INFO_H_ -#include +#include +#include // NOLINT #include #include #include @@ -41,6 +42,7 @@ class DeviceInfo { virtual std::filesystem::path GetDownloadPath() const = 0; virtual std::filesystem::path GetAppDataPath() const = 0; virtual std::filesystem::path GetTemporaryPath() const = 0; + virtual std::filesystem::path GetLogPath() const = 0; virtual std::optional GetAvailableDiskSpaceInBytes( const std::filesystem::path& path) const = 0; diff --git a/internal/platform/device_info_impl.cc b/internal/platform/device_info_impl.cc index ff2bab20..868687d3 100644 --- a/internal/platform/device_info_impl.cc +++ b/internal/platform/device_info_impl.cc @@ -89,6 +89,11 @@ std::filesystem::path DeviceInfoImpl::GetTemporaryPath() const { nearby::sharing::CurrentDirectory()); } +std::filesystem::path DeviceInfoImpl::GetLogPath() const { + std::optional path = device_info_impl_->GetLogPath(); + return path.value_or(GetTemporaryPath()); +} + std::optional DeviceInfoImpl::GetAvailableDiskSpaceInBytes( const std::filesystem::path& path) const { std::error_code error_code; diff --git a/internal/platform/device_info_impl.h b/internal/platform/device_info_impl.h index 5c89c588..b9401c51 100644 --- a/internal/platform/device_info_impl.h +++ b/internal/platform/device_info_impl.h @@ -16,7 +16,7 @@ #define PLATFORM_PUBLIC_DEVICE_INFO_IMPL_H_ #include -#include +#include // NOLINT #include #include #include @@ -46,6 +46,7 @@ class DeviceInfoImpl : public DeviceInfo { std::filesystem::path GetDownloadPath() const override; std::filesystem::path GetAppDataPath() const override; std::filesystem::path GetTemporaryPath() const override; + std::filesystem::path GetLogPath() const override; std::optional GetAvailableDiskSpaceInBytes( const std::filesystem::path& path) const override; diff --git a/internal/test/fake_device_info.h b/internal/test/fake_device_info.h index f33e223f..0e15a055 100644 --- a/internal/test/fake_device_info.h +++ b/internal/test/fake_device_info.h @@ -16,7 +16,7 @@ #define THIRD_PARTY_NEARBY_INTERNAL_TEST_FAKE_DEVICE_INFO_H_ #include -#include +#include // NOLINT #include #include #include @@ -63,6 +63,8 @@ class FakeDeviceInfo : public DeviceInfo { std::filesystem::path GetTemporaryPath() const override { return temp_path_; } + std::filesystem::path GetLogPath() const override { return temp_path_; } + std::optional GetAvailableDiskSpaceInBytes( const std::filesystem::path& path) const override { std::wstring path_key = path.wstring();