util/read_files_in_dir: return map by value (#21815)
old-commit-hash: 11ffbc693694780c612d9d449f49a2feabe8a0a2
This commit is contained in:
@@ -327,12 +327,12 @@ std::string Params::get(const char *key, bool block) {
|
||||
}
|
||||
}
|
||||
|
||||
int Params::readAll(std::map<std::string, std::string> *params) {
|
||||
std::map<std::string, std::string> Params::readAll() {
|
||||
FileLock file_lock(params_path + "/.lock", LOCK_SH);
|
||||
std::lock_guard<FileLock> lk(file_lock);
|
||||
|
||||
std::string key_path = params_path + "/d";
|
||||
return util::read_files_in_dir(key_path, params);
|
||||
return util::read_files_in_dir(key_path);
|
||||
}
|
||||
|
||||
void Params::clearAll(ParamKeyType key_type) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
void clearAll(ParamKeyType type);
|
||||
|
||||
// read all values
|
||||
int readAll(std::map<std::string, std::string> *params);
|
||||
std::map<std::string, std::string> readAll();
|
||||
|
||||
// helpers for reading values
|
||||
std::string get(const char *key, bool block = false);
|
||||
|
||||
@@ -76,19 +76,20 @@ std::string read_file(const std::string& fn) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int read_files_in_dir(const std::string &path, std::map<std::string, std::string> *contents) {
|
||||
std::map<std::string, std::string> read_files_in_dir(const std::string &path) {
|
||||
std::map<std::string, std::string> ret;
|
||||
DIR *d = opendir(path.c_str());
|
||||
if (!d) return -1;
|
||||
if (!d) return ret;
|
||||
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(d))) {
|
||||
if (isalnum(de->d_name[0])) {
|
||||
(*contents)[de->d_name] = util::read_file(path + "/" + de->d_name);
|
||||
ret[de->d_name] = util::read_file(path + "/" + de->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int write_file(const char* path, const void* data, size_t size, int flags, mode_t mode) {
|
||||
|
||||
@@ -62,7 +62,7 @@ bool is_valid_dongle_id(std::string const& dongle_id);
|
||||
|
||||
// **** file fhelpers *****
|
||||
std::string read_file(const std::string& fn);
|
||||
int read_files_in_dir(const std::string& path, std::map<std::string, std::string>* contents);
|
||||
std::map<std::string, std::string> read_files_in_dir(const std::string& path);
|
||||
int write_file(const char* path, const void* data, size_t size, int flags = O_WRONLY, mode_t mode = 0777);
|
||||
std::string readlink(const std::string& path);
|
||||
bool file_exists(const std::string& fn);
|
||||
|
||||
@@ -12,8 +12,7 @@ static kj::Array<capnp::word> build_boot_log() {
|
||||
boot.setWallTimeNanos(nanos_since_epoch());
|
||||
|
||||
std::string pstore = "/sys/fs/pstore";
|
||||
std::map<std::string, std::string> pstore_map;
|
||||
util::read_files_in_dir(pstore, &pstore_map);
|
||||
std::map<std::string, std::string> pstore_map = util::read_files_in_dir(pstore);
|
||||
|
||||
const std::vector<std::string> log_keywords = {"Kernel panic"};
|
||||
auto lpstore = boot.initPstore().initEntries(pstore_map.size());
|
||||
|
||||
@@ -101,8 +101,7 @@ kj::Array<capnp::word> logger_build_init_data() {
|
||||
init.setPassive(params.getBool("Passive"));
|
||||
init.setDongleId(params.get("DongleId"));
|
||||
{
|
||||
std::map<std::string, std::string> params_map;
|
||||
params.readAll(¶ms_map);
|
||||
std::map<std::string, std::string> params_map = params.readAll();
|
||||
auto lparams = init.initParams().initEntries(params_map.size());
|
||||
int i = 0;
|
||||
for (auto& kv : params_map) {
|
||||
|
||||
Reference in New Issue
Block a user