mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-01 03:43:46 +08:00
params: cleanup old params that aren't defined (#28017)
* delete files that are not defined in the keys * assert after create file * remove util::remove_files_in_dir * cleanup * fix up test --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 10a1b8b7b172420047fab5caa84829dd510e1e38
This commit is contained in:
+11
-6
@@ -305,14 +305,19 @@ std::map<std::string, std::string> Params::readAll() {
|
||||
void Params::clearAll(ParamKeyType key_type) {
|
||||
FileLock file_lock(params_path + "/.lock");
|
||||
|
||||
if (key_type == ALL) {
|
||||
util::remove_files_in_dir(getParamPath());
|
||||
} else {
|
||||
for (auto &[key, type] : keys) {
|
||||
if (type & key_type) {
|
||||
unlink(getParamPath(key).c_str());
|
||||
// 1) delete params of key_type
|
||||
// 2) delete files that are not defined in the keys.
|
||||
if (DIR *d = opendir(getParamPath().c_str())) {
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(d))) {
|
||||
if (de->d_type != DT_DIR) {
|
||||
auto it = keys.find(de->d_name);
|
||||
if (it == keys.end() || (it->second & key_type)) {
|
||||
unlink(getParamPath(de->d_name).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
fsync_dir(getParamPath());
|
||||
|
||||
Reference in New Issue
Block a user