mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-05 06:21:26 +12:00
Improve fs::create_path
Don't fail if already exists
This commit is contained in:
parent
88dc6b7700
commit
eae78a8711
1 changed files with 16 additions and 14 deletions
|
@ -495,14 +495,19 @@ bool fs::create_dir(const std::string& path)
|
||||||
|
|
||||||
bool fs::create_path(const std::string& path)
|
bool fs::create_path(const std::string& path)
|
||||||
{
|
{
|
||||||
const auto& parent = get_parent_dir(path);
|
const std::string parent = get_parent_dir(path);
|
||||||
|
|
||||||
if (!parent.empty() && !is_dir(parent) && !create_path(parent))
|
if (!parent.empty() && !create_path(parent))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return create_dir(path);
|
if (!create_dir(path) && g_tls_error != error::exist)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fs::remove_dir(const std::string& path)
|
bool fs::remove_dir(const std::string& path)
|
||||||
|
@ -1336,7 +1341,7 @@ const std::string& fs::get_config_dir()
|
||||||
|
|
||||||
dir += "/rpcs3/";
|
dir += "/rpcs3/";
|
||||||
|
|
||||||
if (!is_dir(dir) && !create_path(dir))
|
if (!create_path(dir))
|
||||||
{
|
{
|
||||||
std::printf("Failed to create configuration directory '%s' (%d).\n", dir.c_str(), errno);
|
std::printf("Failed to create configuration directory '%s' (%d).\n", dir.c_str(), errno);
|
||||||
}
|
}
|
||||||
|
@ -1352,9 +1357,9 @@ std::string fs::get_data_dir(const std::string& prefix, const std::string& locat
|
||||||
{
|
{
|
||||||
static const std::string s_dir = []
|
static const std::string s_dir = []
|
||||||
{
|
{
|
||||||
const std::string& dir = get_config_dir() + "data/";
|
const std::string dir = get_config_dir() + "data/";
|
||||||
|
|
||||||
if (!is_dir(dir) && !create_path(dir))
|
if (!create_path(dir))
|
||||||
{
|
{
|
||||||
return get_config_dir();
|
return get_config_dir();
|
||||||
}
|
}
|
||||||
|
@ -1390,17 +1395,14 @@ std::string fs::get_data_dir(const std::string& prefix, const std::string& locat
|
||||||
sha1(buf.data(), buf.size(), hash);
|
sha1(buf.data(), buf.size(), hash);
|
||||||
|
|
||||||
// Concatenate
|
// Concatenate
|
||||||
std::string&& result = fmt::format("%s%s/%016llx%08x-%s/", s_dir, prefix, reinterpret_cast<be_t<u64>&>(hash[0]), reinterpret_cast<be_t<u32>&>(hash[8]), suffix);
|
std::string result = fmt::format("%s%s/%016llx%08x-%s/", s_dir, prefix, reinterpret_cast<be_t<u64>&>(hash[0]), reinterpret_cast<be_t<u32>&>(hash[8]), suffix);
|
||||||
|
|
||||||
if (!is_dir(result))
|
|
||||||
{
|
|
||||||
// Create dir if necessary
|
// Create dir if necessary
|
||||||
if (create_path(result))
|
if (create_path(result))
|
||||||
{
|
{
|
||||||
// Acknowledge original location
|
// Acknowledge original location
|
||||||
file(result + ".location", rewrite).write(buf);
|
file(result + ".location", rewrite).write(buf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue