From 0d0f3dcc7e7d2e17cfae99d24b9a2a29f6bc1032 Mon Sep 17 00:00:00 2001 From: Timothy Hutchins Date: Sun, 21 May 2023 17:07:15 -0500 Subject: [PATCH] Added program data directories to Linux platform device_info There are a couple of places where apps can store data in Linux, one is in the HOME directory, which is being phased out, the second, is in HOME/.config, and the other is HOME/.local/share. This uses HOME/.local/share, and since there isn't a common appdata path on Linux that function will just return the local appdata path. --- .../implementation/linux/device_info.cc | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/internal/platform/implementation/linux/device_info.cc b/internal/platform/implementation/linux/device_info.cc index b05aeda8..5ee10822 100644 --- a/internal/platform/implementation/linux/device_info.cc +++ b/internal/platform/implementation/linux/device_info.cc @@ -49,7 +49,7 @@ std::optional DeviceInfo::GetOsDeviceName() const { return std::wstring_convert, char16_t>().from_bytes(name); } - NEARBY_LOGS(ERROR) << ": Failed to get device name, error:" + NEARBY_LOGS(ERROR) << ": Failed to get device name, error: " << strerror(errno); delete[] device_name; return std::nullopt; @@ -210,6 +210,7 @@ std::optional DeviceInfo::GetDownloadPath() const { delete[] path; return std::nullopt; } + delete fp; std::filesystem::path fpath = std::filesystem::path(path); delete[] path; @@ -217,15 +218,32 @@ std::optional DeviceInfo::GetDownloadPath() const { } std::optional DeviceInfo::GetLocalAppDataPath() const { - //TODO: Figure out how to get cross distro path + // From lots of research I have done, it seems there is no way to get a path + // for this cross distro wise, some distros might implement this path in + // a different way. Because of that, this will have to be hard-coded and in + // the future may be able to detect which distro and if the path is different + // deal with that. + + std::string app_data_dir(getenv("HOME")); + app_data_dir.append("/.local/share"); + + if (std::filesystem::is_directory(app_data_dir)) { + return app_data_dir; + } return std::nullopt; } std::optional DeviceInfo::GetCommonAppDataPath() const { - //TODO: Figure out how to get cross distro path + // From lots of research I have done, it seems there is no way to get a path + // for this cross distro wise, some distros might implement this path in + // a different way. Because of that, this will have to be hard-coded and in + // the future may be able to detect which distro and if the path is different + // deal with that. + + // Also there is no common appdata path on Linux - return std::nullopt; + return GetLocalAppDataPath(); } std::optional DeviceInfo::GetTemporaryPath() const { @@ -233,14 +251,13 @@ std::optional DeviceInfo::GetTemporaryPath() const { } std::optional DeviceInfo::GetLogPath() const { - //TODO: Figure out how to get cross distro path - - return std::nullopt; + return std::nullopt; } std::optional DeviceInfo::GetCrashDumpPath() const { - //TODO: Figure out how to get cross distro path - + // Crash dumps are handled by the system, it will generate a core (crash) dump + // and put it in a directory. + // E.g. "Segmentation fault (core dumped)" return std::nullopt; }