Move utility prefix function into utils namespace

This commit is contained in:
Simon Fels 2016-10-18 22:08:59 +02:00
commit 244aa89a89
3 changed files with 14 additions and 13 deletions

View file

@ -24,28 +24,18 @@
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 config {
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) {
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) {
return prefix_dir_from_env(path, "SNAP_USER_COMMON");
return utils::prefix_dir_from_env(path, "SNAP_USER_COMMON");
}
std::string home_dir() {

View file

@ -151,5 +151,14 @@ void ensure_paths(const std::vector<std::string> &paths) {
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 anbox

View file

@ -43,6 +43,8 @@ bool is_env_set(const std::string &name);
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>
static std::string string_format(const std::string& fmt_str, Types&&... args);
} // namespace utils