Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read base path for config files from TMPDIR env var #33846

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ClangFormat changed files
  • Loading branch information
jpm-canonical committed Jun 19, 2024
commit ceaafa6f0748f2af061dde6467c9779c3d207656
16 changes: 8 additions & 8 deletions src/platform/Linux/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ bool PosixConfig::ConfigValueExists(Key key)
return storage->HasValue(key.Name);
}

std::string PosixConfig::GetFilePath(const std::string &defaultFileName)
std::string PosixConfig::GetFilePath(const std::string & defaultFileName)
{
// Match what GetFilename in ExamplePersistentStorage.cpp does.
const char *dir = std::getenv("TMPDIR");
const char * dir = std::getenv("TMPDIR");
if (dir == nullptr)
{
dir = "/tmp";
Expand All @@ -474,21 +474,21 @@ CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)

if (strcmp(ns, kConfigNamespace_ChipFactory) == 0)
{
storage = &gChipLinuxFactoryStorage;
storage = &gChipLinuxFactoryStorage;
std::string filePath = GetFilePath(CHIP_DEFAULT_FACTORY_FILE_NAME);
err = storage->Init(filePath.c_str());
err = storage->Init(filePath.c_str());
}
else if (strcmp(ns, kConfigNamespace_ChipConfig) == 0)
{
storage = &gChipLinuxConfigStorage;
storage = &gChipLinuxConfigStorage;
std::string filePath = GetFilePath(CHIP_DEFAULT_CONFIG_FILE_NAME);
err = storage->Init(filePath.c_str());
err = storage->Init(filePath.c_str());
}
else if (strcmp(ns, kConfigNamespace_ChipCounters) == 0)
{
storage = &gChipLinuxCountersStorage;
storage = &gChipLinuxCountersStorage;
std::string filePath = GetFilePath(CHIP_DEFAULT_DATA_FILE_NAME);
err = storage->Init(filePath.c_str());
err = storage->Init(filePath.c_str());
}

SuccessOrExit(err);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Linux/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

#pragma once

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

#include <lib/core/CHIPError.h>

Expand Down Expand Up @@ -113,7 +113,7 @@ class PosixConfig

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

struct PosixConfig::Key
Expand Down
Loading