From c28735358e48a6360b95e9cc15d47ec16acaa83d Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Tue, 17 May 2022 00:58:13 +0200 Subject: [PATCH] params: support OPENPILOT_PREFIX (#24495) * prefix params * set env * prefix in manager * filesystem except * dont delete manager folder * Update selfdrive/common/params.h Co-authored-by: Adeeb Shihadeh * debug same path * remove cleanup + same default * dont use filesystem lib * param symlink path * path * spelling Co-authored-by: Adeeb Shihadeh --- selfdrive/common/params.cc | 11 +++++++---- selfdrive/common/params.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index f3c599a36a..f6d7adfd4e 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -60,9 +60,9 @@ bool create_params_path(const std::string ¶m_path, const std::string &key_pa return true; } -std::string ensure_params_path(const std::string &path = {}) { +std::string ensure_params_path(const std::string &prefix, const std::string &path = {}) { std::string params_path = path.empty() ? Path::params() : path; - if (!create_params_path(params_path, params_path + "/d")) { + if (!create_params_path(params_path, params_path + prefix)) { throw std::runtime_error(util::string_format("Failed to ensure params path, errno=%d", errno)); } return params_path; @@ -180,9 +180,12 @@ std::unordered_map keys = { } // namespace + Params::Params(const std::string &path) { - static std::string default_param_path = ensure_params_path(); - params_path = path.empty() ? default_param_path : ensure_params_path(path); + const char* env = std::getenv("OPENPILOT_PREFIX"); + prefix = env ? "/" + std::string(env) : "/d"; + std::string default_param_path = ensure_params_path(prefix); + params_path = path.empty() ? default_param_path : ensure_params_path(prefix, path); } bool Params::checkKey(const std::string &key) { diff --git a/selfdrive/common/params.h b/selfdrive/common/params.h index be09c63d54..aa4b1d7af3 100644 --- a/selfdrive/common/params.h +++ b/selfdrive/common/params.h @@ -18,7 +18,7 @@ public: bool checkKey(const std::string &key); ParamKeyType getKeyType(const std::string &key); inline std::string getParamPath(const std::string &key = {}) { - return key.empty() ? params_path + "/d" : params_path + "/d/" + key; + return params_path + prefix + (key.empty() ? "" : "/" + key); } // Delete a value @@ -43,4 +43,5 @@ public: private: std::string params_path; + std::string prefix; };