Skip to content

Commit ca555a9

Browse files
committed
Fixed missing explicit conversions from fs::path to std::string
1 parent 7f45c27 commit ca555a9

35 files changed

+192
-158
lines changed

libmamba/include/mamba/api/configuration.hpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ namespace mamba
487487
catch (const YAML::Exception& e)
488488
{
489489
LOG_ERROR << "Bad conversion of configurable '" << this->m_name << "' from source '"
490-
<< source << "'";
490+
<< source << "' : " << e.what();
491491
}
492492
}
493493

@@ -569,6 +569,24 @@ namespace mamba
569569
node[name] = m_value;
570570
}
571571

572+
template <>
573+
inline void ConfigurableImpl<fs::path>::dump_json(nlohmann::json& node,
574+
const std::string& name) const
575+
{
576+
node[name] = m_value.string();
577+
}
578+
579+
template <>
580+
inline void ConfigurableImpl<std::vector<fs::path>>::dump_json(nlohmann::json& node, const std::string& name) const
581+
{
582+
std::vector<std::string> values(m_value.size());
583+
std::transform(m_value.begin(),
584+
m_value.end(),
585+
values.begin(),
586+
[](const auto& value) { return value.string(); });
587+
node[name] = values;
588+
}
589+
572590
template <class T>
573591
void ConfigurableImpl<T>::set_rc_value(const T& value, const std::string& source)
574592
{

libmamba/include/mamba/core/fsutil.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace mamba
2020
{
2121
inline bool starts_with_home(const fs::path& p)
2222
{
23-
std::string path = p;
23+
std::string path = p.string();
2424
return path[0] == '~'
2525
|| starts_with(env::expand_user(path).string(), env::expand_user("~").string());
2626
}

libmamba/include/mamba/core/util.hpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,29 @@ namespace mamba
196196
std::string& extension);
197197
fs::path strip_package_extension(const std::string& file);
198198

199-
template <class S>
200-
inline std::string join(const char* j, const S& container)
199+
namespace details
200+
{
201+
struct PlusEqual
202+
{
203+
template<typename T, typename U>
204+
auto operator()(T& left, const U& right)
205+
{
206+
left += right;
207+
}
208+
};
209+
}
210+
211+
template <class S, class Joiner = details::PlusEqual>
212+
auto join(const char* j, const S& container, Joiner joiner = details::PlusEqual{})
213+
-> typename S::value_type
201214
{
202215
if (container.empty())
203-
return "";
204-
std::string result = container[0];
216+
return {};
217+
auto result = container[0];
205218
for (std::size_t i = 1; i < container.size(); ++i)
206219
{
207-
result += j;
208-
result += container[i];
220+
joiner(result, j);
221+
joiner(result, container[i]);
209222
}
210223
return result;
211224
}

libmamba/src/api/clean.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace mamba
170170
std::vector<std::vector<printers::FormattedString>> rows;
171171
for (auto& p : fs::directory_iterator(pkg_cache->path()))
172172
{
173-
std::string fname = p.path().filename();
173+
std::string fname = p.path().filename().string();
174174
if (!p.is_directory()
175175
&& (ends_with(p.path().string(), ".tar.bz2")
176176
|| ends_with(p.path().string(), ".conda")))
@@ -244,10 +244,9 @@ namespace mamba
244244
std::vector<std::vector<printers::FormattedString>> rows;
245245
for (auto& p : fs::directory_iterator(pkg_cache->path()))
246246
{
247-
std::string fname = p.path().filename();
248247
if (p.is_directory() && fs::exists(p.path() / "info" / "index.json"))
249248
{
250-
if (installed_pkgs.find(p.path().filename()) != installed_pkgs.end())
249+
if (installed_pkgs.find(p.path().filename().string()) != installed_pkgs.end())
251250
{
252251
// do not remove installed packages
253252
continue;

libmamba/src/api/configuration.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ namespace mamba
809809
{
810810
if (!Configuration::instance().at("root_prefix").configured() || force)
811811
{
812-
env::set("MAMBA_ROOT_PREFIX", get_conda_root_prefix());
812+
env::set("MAMBA_ROOT_PREFIX", get_conda_root_prefix().string());
813813
}
814814
}
815815

@@ -1851,7 +1851,7 @@ namespace mamba
18511851
if (!yaml[key] || yaml[key].IsNull())
18521852
continue;
18531853

1854-
c.set_rc_yaml_value(yaml[key], env::shrink_user(source));
1854+
c.set_rc_yaml_value(yaml[key], env::shrink_user(source).string());
18551855
}
18561856
}
18571857
}

libmamba/src/api/info.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace mamba
125125
items.push_back({ "env location", location });
126126

127127
// items.insert( { "shell level", { 1 } });
128-
items.push_back({ "user config files", { env::home_directory() / ".mambarc" } });
128+
items.push_back({ "user config files", { (env::home_directory() / ".mambarc").string() } });
129129

130130
Configuration& config = Configuration::instance();
131131
std::vector<std::string> sources;

libmamba/src/api/install.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace mamba
7777
specs_f << d.c_str() << '\n';
7878
specs_f.close();
7979

80-
replace_all(install_instructions, "{0}", specs.path());
80+
replace_all(install_instructions, "{0}", specs.path().string());
8181

8282
const auto& ctx = Context::instance();
8383

@@ -166,7 +166,7 @@ namespace mamba
166166
YAML::Node f;
167167
try
168168
{
169-
f = YAML::LoadFile(file);
169+
f = YAML::LoadFile(file.string());
170170
}
171171
catch (YAML::Exception& e)
172172
{
@@ -220,7 +220,7 @@ namespace mamba
220220
result.others_pkg_mgrs_specs.push_back(
221221
{ "pip",
222222
map_el.second.as<std::vector<std::string>>(),
223-
fs::absolute(yaml_file.parent_path()) });
223+
fs::absolute(yaml_file.parent_path()).string() });
224224
has_pip_deps = true;
225225
}
226226
}
@@ -568,7 +568,7 @@ namespace mamba
568568
detail::create_target_directory(prefix);
569569

570570
Console::instance().print(join(
571-
"", std::vector<std::string>({ "Empty environment created at prefix: ", prefix })));
571+
"", std::vector<std::string>({ "Empty environment created at prefix: ", prefix.string() })));
572572
Console::instance().json_write({ { "success", true } });
573573
}
574574

libmamba/src/api/shell.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ namespace mamba
9090
if (action == "init")
9191
{
9292
if (prefix.empty() || prefix == "base")
93-
shell_prefix = ctx.root_prefix;
93+
shell_prefix = ctx.root_prefix.string();
9494
else
95-
shell_prefix = fs::weakly_canonical(env::expand_user(prefix));
95+
shell_prefix = fs::weakly_canonical(env::expand_user(prefix)).string();
9696

9797
init_shell(shell_type, shell_prefix);
9898
}
@@ -115,11 +115,11 @@ namespace mamba
115115
else if (action == "activate")
116116
{
117117
if (prefix.empty() || prefix == "base")
118-
shell_prefix = ctx.root_prefix;
118+
shell_prefix = ctx.root_prefix.string();
119119
else if (prefix.find_first_of("/\\") == std::string::npos)
120-
shell_prefix = ctx.root_prefix / "envs" / prefix;
120+
shell_prefix = (ctx.root_prefix / "envs" / prefix).string();
121121
else
122-
shell_prefix = fs::weakly_canonical(env::expand_user(prefix));
122+
shell_prefix = fs::weakly_canonical(env::expand_user(prefix)).string();
123123

124124
if (!fs::exists(shell_prefix))
125125
throw std::runtime_error("Cannot activate, prefix does not exist at: "

libmamba/src/core/activation.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ namespace mamba
5555
// if ../miniconda3/envs/my_super_env, return `my_super_env`, else path
5656
if (prefix.parent_path().stem() == "envs")
5757
{
58-
return prefix.stem();
58+
return prefix.stem().string();
5959
}
6060
else
6161
{
62-
return prefix;
62+
return prefix.string();
6363
}
6464
}
6565

@@ -162,8 +162,8 @@ namespace mamba
162162
std::string prompt = Context::instance().env_prompt;
163163
replace_all(prompt, "{default_env}", conda_default_env);
164164
replace_all(prompt, "{stacked_env}", conda_stacked_env);
165-
replace_all(prompt, "{prefix}", prefix);
166-
replace_all(prompt, "{name}", prefix.stem());
165+
replace_all(prompt, "{prefix}", prefix.string());
166+
replace_all(prompt, "{name}", prefix.stem().string());
167167
return prompt;
168168
}
169169
else
@@ -268,7 +268,7 @@ namespace mamba
268268
bool no_condabin
269269
= std::none_of(path_list.begin(),
270270
path_list.end(),
271-
[](const std::string& s) { return ends_with(s, "condabin"); });
271+
[](const fs::path& s) { return ends_with(s.string(), "condabin"); });
272272
if (no_condabin)
273273
{
274274
auto condabin_dir = Context::instance().root_prefix / "condabin";
@@ -282,7 +282,7 @@ namespace mamba
282282
final_path.insert(final_path.end(), path_list.begin(), path_list.end());
283283
final_path.erase(std::unique(final_path.begin(), final_path.end()), final_path.end());
284284

285-
std::string result = join(env::pathsep(), final_path);
285+
std::string result = join(env::pathsep(), final_path).string();
286286
return result;
287287
}
288288

@@ -325,14 +325,14 @@ namespace mamba
325325

326326
// remove duplicates
327327
final_path.erase(std::unique(final_path.begin(), final_path.end()), final_path.end());
328-
std::string result = join(env::pathsep(), final_path);
328+
std::string result = join(env::pathsep(), final_path).string();
329329
return result;
330330
}
331331
else
332332
{
333333
current_path.erase(std::unique(current_path.begin(), current_path.end()),
334334
current_path.end());
335-
std::string result = join(env::pathsep(), current_path);
335+
std::string result = join(env::pathsep(), current_path).string();
336336
return result;
337337
}
338338
}
@@ -602,16 +602,15 @@ namespace mamba
602602
LOG_WARNING << "Overwriting variables: " << join(",", clobbering_env_vars);
603603
}
604604

605-
std::vector<std::pair<std::string, std::string>> env_vars_to_export;
606-
std::vector<std::string> unset_vars;
607-
608605
std::string new_path = add_prefix_to_path(prefix, old_conda_shlvl);
609606

610-
env_vars_to_export = { { "path", std::string(new_path) },
611-
{ "conda_prefix", std::string(prefix) },
612-
{ "conda_shlvl", std::to_string(new_conda_shlvl) },
613-
{ "conda_default_env", conda_default_env },
614-
{ "conda_prompt_modifier", conda_prompt_modifier } };
607+
std::vector<std::pair<std::string, std::string>> env_vars_to_export{
608+
{ "path", new_path },
609+
{ "conda_prefix", prefix.string() },
610+
{ "conda_shlvl", std::to_string(new_conda_shlvl) },
611+
{ "conda_default_env", conda_default_env },
612+
{ "conda_prompt_modifier", conda_prompt_modifier }
613+
};
615614

616615
for (auto& [k, v] : conda_environment_env_vars)
617616
{
@@ -634,7 +633,7 @@ namespace mamba
634633
}
635634
else
636635
{
637-
new_path = replace_prefix_in_path(old_conda_prefix, prefix);
636+
new_path = replace_prefix_in_path(old_conda_prefix, prefix.string());
638637
envt.deactivate_scripts = get_deactivate_scripts(old_conda_prefix);
639638
env_vars_to_export[0] = { "PATH", new_path };
640639
get_export_unset_vars(envt, env_vars_to_export);

libmamba/src/core/context.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace mamba
171171
if (ends_with(entry.path().filename().string(), ".token"))
172172
{
173173
found_tokens.push_back(entry.path());
174-
std::string token_url = decode_url(entry.path().filename());
174+
std::string token_url = decode_url(entry.path().filename().string());
175175

176176
// anaconda client writes out a token for https://api.anaconda.org...
177177
// but we need the token for https://conda.anaconda.org
@@ -256,10 +256,10 @@ namespace mamba
256256
{
257257
if (paths_equal(d, maybe_env_dir))
258258
{
259-
return prefix.filename();
259+
return prefix.filename().string();
260260
}
261261
}
262-
return prefix;
262+
return prefix.string();
263263
}
264264

265265
// Find the location of a prefix given a conda env name.

libmamba/src/core/env_lockfile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ namespace mamba
154154
try
155155
{
156156
// TODO: add fields validation here (using some schema validation tool)
157-
const YAML::Node lockfile_content = YAML::LoadFile(file_path);
157+
const YAML::Node lockfile_content = YAML::LoadFile(file_path.string());
158158
const auto lockfile_version = lockfile_content["version"].as<int>();
159159
switch (lockfile_version)
160160
{

libmamba/src/core/environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace mamba
208208
auto p = path.string();
209209
if (p[0] == '~')
210210
{
211-
p.replace(0, 1, home_directory());
211+
p.replace(0, 1, home_directory().string());
212212
}
213213
return p;
214214
}

libmamba/src/core/environments_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace mamba
3838
}
3939
}
4040

41-
std::string final_location_string = remove_trailing_slash(final_location);
41+
std::string final_location_string = remove_trailing_slash(final_location.string());
4242
if (final_location_string.find("placehold_pl") != std::string::npos
4343
|| final_location_string.find("skeleton_") != std::string::npos)
4444
{

0 commit comments

Comments
 (0)