@@ -1571,25 +1571,37 @@ fs::path
fs::temp_directory_path()
{
error_code ec;
- path tmp = temp_directory_path(ec);
+ path p = fs::get_temp_directory_from_env(ec);
+ if (!ec)
+ {
+ auto st = status(p, ec);
+ if (!ec && !is_directory(st))
+ ec = std::make_error_code(std::errc::not_a_directory);
+ }
if (ec)
- _GLIBCXX_THROW_OR_ABORT(filesystem_error("temp_directory_path", ec));
- return tmp;
+ {
+ if (p.empty())
+ _GLIBCXX_THROW_OR_ABORT(filesystem_error("temp_directory_path", ec));
+ else
+ _GLIBCXX_THROW_OR_ABORT(filesystem_error("temp_directory_path", p, ec));
+ }
+ return p;
}
fs::path
fs::temp_directory_path(error_code& ec)
{
path p = fs::get_temp_directory_from_env(ec);
- if (ec)
- return p;
- auto st = status(p, ec);
- if (ec)
- p.clear();
- else if (!is_directory(st))
+ if (!ec)
{
- p.clear();
- ec = std::make_error_code(std::errc::not_a_directory);
+ auto st = status(p, ec);
+ if (ec)
+ p.clear();
+ else if (!is_directory(st))
+ {
+ p.clear();
+ ec = std::make_error_code(std::errc::not_a_directory);
+ }
}
return p;
}
@@ -1326,25 +1326,32 @@ fs::path
fs::temp_directory_path()
{
error_code ec;
- path tmp = temp_directory_path(ec);
- if (ec.value())
- _GLIBCXX_THROW_OR_ABORT(filesystem_error("temp_directory_path", ec));
- return tmp;
+ path p = fs::get_temp_directory_from_env(ec);
+ if (!ec)
+ {
+ auto st = status(p, ec);
+ if (!ec && !is_directory(st))
+ ec = std::make_error_code(std::errc::not_a_directory);
+ }
+ if (ec)
+ _GLIBCXX_THROW_OR_ABORT(filesystem_error("temp_directory_path", p, ec));
+ return p;
}
fs::path
fs::temp_directory_path(error_code& ec)
{
path p = fs::get_temp_directory_from_env(ec);
- if (ec)
- return p;
- auto st = status(p, ec);
- if (ec)
- p.clear();
- else if (!is_directory(st))
+ if (!ec)
{
- p.clear();
- ec = std::make_error_code(std::errc::not_a_directory);
+ auto st = status(p, ec);
+ if (ec)
+ p.clear();
+ else if (!is_directory(st))
+ {
+ p.clear();
+ ec = std::make_error_code(std::errc::not_a_directory);
+ }
}
return p;
}
@@ -140,12 +140,17 @@ test04()
VERIFY( r == fs::path() );
std::error_code ec2;
+ std::string failed_path;
try {
fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
+ // On Windows the returned path will be in preferred form, i.e. using L'\\'
+ // and will have a trailing slash, so compare generic forms.
+ failed_path = e.path1().generic_string();
}
VERIFY( ec2 == ec );
+ VERIFY( failed_path.find(f.path.generic_string()) != std::string::npos );
}
int
@@ -141,12 +141,17 @@ test04()
VERIFY( r == fs::path() );
std::error_code ec2;
+ std::string failed_path;
try {
fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
+ // On Windows the returned path will be in preferred form, i.e. using L'\\'
+ // and will have a trailing slash, so compare generic forms.
+ failed_path = e.path1().generic_string();
}
VERIFY( ec2 == ec );
+ VERIFY( failed_path.find(f.path.generic_string()) != std::string::npos );
}
int