Skip to content

Commit 76e4435

Browse files
committed
KVS_PATH also use env var
Add suggestions by @locnnil
1 parent b32e67c commit 76e4435

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/platform/Linux/CHIPPlatformConfig.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;
6666

6767
// ==================== Security Configuration Overrides ====================
6868

69-
#ifndef CHIP_CONFIG_KVS_PATH
70-
#define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs"
71-
#endif // CHIP_CONFIG_KVS_PATH
69+
#define CHIP_DEFAULT_CONFIG_KVS_FILE_NAME "chip_kvs"

src/platform/Linux/PosixConfig.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ ChipLinuxStorage * PosixConfig::GetStorageForNamespace(Key key)
9797

9898
CHIP_ERROR PosixConfig::Init()
9999
{
100-
return PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
100+
std::string filePath = GetFilePath(CHIP_DEFAULT_CONFIG_KVS_FILE_NAME);
101+
return PersistedStorage::KeyValueStoreMgrImpl().Init(filePath.c_str());
101102
}
102103

103104
CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)
@@ -453,17 +454,17 @@ bool PosixConfig::ConfigValueExists(Key key)
453454
return storage->HasValue(key.Name);
454455
}
455456

456-
std::string PosixConfig::GetFilePath(std::string defaultFileName)
457+
std::string PosixConfig::GetFilePath(const std::string &defaultFileName)
457458
{
458459
// Match what GetFilename in ExamplePersistentStorage.cpp does.
459-
const char * dir = getenv("TMPDIR");
460+
const char *dir = std::getenv("TMPDIR");
460461
if (dir == nullptr)
461462
{
462463
dir = "/tmp";
463464
}
464-
std::string storageDir = dir;
465-
466-
return storageDir + "/" + defaultFileName;
465+
std::filesystem::path storageDir(dir);
466+
std::filesystem::path filePath = storageDir / defaultFileName;
467+
return filePath.string();
467468
}
468469

469470
CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)

src/platform/Linux/PosixConfig.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <functional>
2727
#include <string>
28+
#include <filesystem>
2829
#include <inttypes.h>
2930

3031
#include <lib/core/CHIPError.h>
@@ -112,7 +113,7 @@ class PosixConfig
112113

113114
private:
114115
static ChipLinuxStorage * GetStorageForNamespace(Key key);
115-
static std::string GetFilePath(std::string defaultFileName);
116+
static std::string GetFilePath(const std::string &defaultFileName);
116117
};
117118

118119
struct PosixConfig::Key

0 commit comments

Comments
 (0)