Move utility prefix function into utils namespace
This commit is contained in:
parent
46b4303b41
commit
244aa89a89
3 changed files with 14 additions and 13 deletions
|
|
@ -24,28 +24,18 @@
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
namespace {
|
|
||||||
std::string prefix_dir_from_env(const std::string &path, const std::string &env_var) {
|
|
||||||
static auto snap_data_path = anbox::utils::get_env_value(env_var, "");
|
|
||||||
auto result = path;
|
|
||||||
if (!snap_data_path.empty())
|
|
||||||
result = anbox::utils::string_format("%s%s", snap_data_path, path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace anbox {
|
namespace anbox {
|
||||||
namespace config {
|
namespace config {
|
||||||
std::string in_snap_dir(const std::string &path) {
|
std::string in_snap_dir(const std::string &path) {
|
||||||
return prefix_dir_from_env(path, "SNAP");
|
return utils::prefix_dir_from_env(path, "SNAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string in_snap_data_dir(const std::string &path) {
|
std::string in_snap_data_dir(const std::string &path) {
|
||||||
return prefix_dir_from_env(path, "SNAP_COMMON");
|
return utils::prefix_dir_from_env(path, "SNAP_COMMON");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string in_snap_user_data_dir(const std::string &path) {
|
std::string in_snap_user_data_dir(const std::string &path) {
|
||||||
return prefix_dir_from_env(path, "SNAP_USER_COMMON");
|
return utils::prefix_dir_from_env(path, "SNAP_USER_COMMON");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string home_dir() {
|
std::string home_dir() {
|
||||||
|
|
|
||||||
|
|
@ -151,5 +151,14 @@ void ensure_paths(const std::vector<std::string> &paths) {
|
||||||
fs::create_directories(fs::path(path));
|
fs::create_directories(fs::path(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string prefix_dir_from_env(const std::string &path, const std::string &env_var) {
|
||||||
|
static auto snap_data_path = anbox::utils::get_env_value(env_var, "");
|
||||||
|
auto result = path;
|
||||||
|
if (!snap_data_path.empty())
|
||||||
|
result = anbox::utils::string_format("%s%s", snap_data_path, path);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
} // namespace anbox
|
} // namespace anbox
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ bool is_env_set(const std::string &name);
|
||||||
|
|
||||||
void ensure_paths(const std::vector<std::string> &paths);
|
void ensure_paths(const std::vector<std::string> &paths);
|
||||||
|
|
||||||
|
std::string prefix_dir_from_env(const std::string &path, const std::string &env_var);
|
||||||
|
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
static std::string string_format(const std::string& fmt_str, Types&&... args);
|
static std::string string_format(const std::string& fmt_str, Types&&... args);
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue