Skip to content

Commit

Permalink
KVS_PATH also use env var
Browse files Browse the repository at this point in the history
Add suggestions by @locnnil
  • Loading branch information
jpm-canonical committed Jun 12, 2024
1 parent 1977782 commit 1e73d53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/platform/Linux/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;

// ==================== Security Configuration Overrides ====================

#ifndef CHIP_CONFIG_KVS_PATH
#define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs"
#endif // CHIP_CONFIG_KVS_PATH
#define CHIP_DEFAULT_CONFIG_KVS_FILE_NAME "chip_kvs"
13 changes: 7 additions & 6 deletions src/platform/Linux/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ ChipLinuxStorage * PosixConfig::GetStorageForNamespace(Key key)

CHIP_ERROR PosixConfig::Init()
{
return PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
std::string filePath = GetFilePath(CHIP_DEFAULT_CONFIG_KVS_FILE_NAME);
return PersistedStorage::KeyValueStoreMgrImpl().Init(filePath.c_str());
}

CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)
Expand Down Expand Up @@ -453,17 +454,17 @@ bool PosixConfig::ConfigValueExists(Key key)
return storage->HasValue(key.Name);
}

std::string PosixConfig::GetFilePath(std::string defaultFileName)
std::string PosixConfig::GetFilePath(const std::string &defaultFileName)
{
// Match what GetFilename in ExamplePersistentStorage.cpp does.
const char * dir = getenv("TMPDIR");
const char *dir = std::getenv("TMPDIR");
if (dir == nullptr)
{
dir = "/tmp";
}
std::string storageDir = dir;

return storageDir + "/" + defaultFileName;
std::filesystem::path storageDir(dir);
std::filesystem::path filePath = storageDir / defaultFileName;
return filePath.string();
}

CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)
Expand Down
3 changes: 2 additions & 1 deletion src/platform/Linux/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <functional>
#include <string>
#include <filesystem>
#include <inttypes.h>

#include <lib/core/CHIPError.h>
Expand Down Expand Up @@ -112,7 +113,7 @@ class PosixConfig

private:
static ChipLinuxStorage * GetStorageForNamespace(Key key);
static std::string GetFilePath(std::string defaultFileName);
static std::string GetFilePath(const std::string &defaultFileName);
};

struct PosixConfig::Key
Expand Down

0 comments on commit 1e73d53

Please sign in to comment.