<div dir="ltr">Minor nit: your diff is much bigger than it should have been due to whitespace changes.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 5, 2017 at 9:21 AM, Saleem Abdulrasool via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: compnerd<br>
Date: Sun Feb 5 11:21:52 2017<br>
New Revision: 294127<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=294127&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=294127&view=rev</a><br>
Log:<br>
filesystem: fix n4100 conformance for `temp_directory_path`<br>
<br>
N4100 states that an error shall be reported if<br>
`!exists(p) || !is_directory(p)`. We were missing the first half of the<br>
conditional. Invert the error and normal code paths to make the code<br>
easier to follow.<br>
<br>
Modified:<br>
libcxx/trunk/src/experimental/<wbr>filesystem/operations.cpp<br>
libcxx/trunk/test/std/<wbr>experimental/filesystem/fs.op.<wbr>funcs/fs.op.temp_dir_path/<wbr>temp_directory_path.pass.cpp<br>
<br>
Modified: libcxx/trunk/src/experimental/<wbr>filesystem/operations.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=294127&r1=294126&r2=294127&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxx/trunk/src/<wbr>experimental/filesystem/<wbr>operations.cpp?rev=294127&r1=<wbr>294126&r2=294127&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxx/trunk/src/experimental/<wbr>filesystem/operations.cpp (original)<br>
+++ libcxx/trunk/src/experimental/<wbr>filesystem/operations.cpp Sun Feb 5 11:21:52 2017<br>
@@ -886,23 +886,28 @@ path __system_complete(const path& p, st<br>
return absolute(p, current_path());<br>
}<br>
<br>
-path __temp_directory_path(std::<wbr>error_code *ec) {<br>
- const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};<br>
- const char* ret = nullptr;<br>
- for (auto & ep : env_paths) {<br>
- if ((ret = std::getenv(ep)))<br>
- break;<br>
- }<br>
- path p(ret ? ret : "/tmp");<br>
- std::error_code m_ec;<br>
- if (is_directory(p, m_ec)) {<br>
- if (ec) ec->clear();<br>
- return p;<br>
- }<br>
+path __temp_directory_path(std::<wbr>error_code* ec) {<br>
+ const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};<br>
+ const char* ret = nullptr;<br>
+<br>
+ for (auto& ep : env_paths)<br>
+ if ((ret = std::getenv(ep)))<br>
+ break;<br>
+ if (ret == nullptr)<br>
+ ret = "/tmp";<br>
+<br>
+ path p(ret);<br>
+ std::error_code m_ec;<br>
+ if (!exists(p, m_ec) || !is_directory(p, m_ec)) {<br>
if (!m_ec || m_ec == make_error_code(errc::no_such_<wbr>file_or_directory))<br>
- m_ec = make_error_code(errc::not_a_<wbr>directory);<br>
+ m_ec = make_error_code(errc::not_a_<wbr>directory);<br>
set_or_throw(m_ec, ec, "temp_directory_path");<br>
return {};<br>
+ }<br>
+<br>
+ if (ec)<br>
+ ec->clear();<br>
+ return p;<br>
}<br>
<br>
// An absolute path is composed according to the table in [fs.op.absolute].<br>
<br>
Modified: libcxx/trunk/test/std/<wbr>experimental/filesystem/fs.op.<wbr>funcs/fs.op.temp_dir_path/<wbr>temp_directory_path.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp?rev=294127&r1=294126&r2=294127&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxx/trunk/test/std/<wbr>experimental/filesystem/fs.op.<wbr>funcs/fs.op.temp_dir_path/<wbr>temp_directory_path.pass.cpp?<wbr>rev=294127&r1=294126&r2=<wbr>294127&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxx/trunk/test/std/<wbr>experimental/filesystem/fs.op.<wbr>funcs/fs.op.temp_dir_path/<wbr>temp_directory_path.pass.cpp (original)<br>
+++ libcxx/trunk/test/std/<wbr>experimental/filesystem/fs.op.<wbr>funcs/fs.op.temp_dir_path/<wbr>temp_directory_path.pass.cpp Sun Feb 5 11:21:52 2017<br>
@@ -97,6 +97,14 @@ TEST_CASE(basic_tests)<br>
TEST_CHECK(ec == std::make_error_code(std::<wbr>errc::permission_denied));<br>
TEST_CHECK(ret == "");<br>
<br>
+ // Set the env variable to point to a non-existent dir<br>
+ PutEnv(TC.name, TC.p / "does_not_exist");<br>
+ ec = GetTestEC();<br>
+ ret = temp_directory_path(ec);<br>
+ TEST_CHECK(ec != GetTestEC());<br>
+ TEST_CHECK(ec);<br>
+ TEST_CHECK(ret == "");<br>
+<br>
// Finally erase this env variable<br>
UnsetEnv(TC.name);<br>
}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>