[libcxx-commits] [libcxx] 68e4596 - [libcxx] Fix the function name in exceptions from create_directories

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 25 13:50:20 PDT 2021


Author: Martin Storsjö
Date: 2021-05-25T23:48:50+03:00
New Revision: 68e45962531a25a0fab63eab163a6c9f84c81f1e

URL: https://github.com/llvm/llvm-project/commit/68e45962531a25a0fab63eab163a6c9f84c81f1e
DIFF: https://github.com/llvm/llvm-project/commit/68e45962531a25a0fab63eab163a6c9f84c81f1e.diff

LOG: [libcxx] Fix the function name in exceptions from create_directories

If the nested create_directory call fails, we'd still want to
re-report the errors with the create_directories function name,
which is what the caller called.

This fixes one aspect from MS STL's tests for std::filesystem.

Differential Revision: https://reviews.llvm.org/D102365

Added: 
    

Modified: 
    libcxx/src/filesystem/operations.cpp
    libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 99001a0679333..5179eeae42b58 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -1022,7 +1022,10 @@ bool __create_directories(const path& p, error_code* ec) {
     } else if (not is_directory(parent_st))
       return err.report(errc::not_a_directory);
   }
-  return __create_directory(p, ec);
+  bool ret = __create_directory(p, &m_ec);
+  if (m_ec)
+    return err.report(m_ec);
+  return ret;
 }
 
 bool __create_directory(const path& p, error_code* ec) {

diff  --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
index 50cbd93227747..5174b7d454e06 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
@@ -138,6 +138,18 @@ TEST_CASE(dest_final_part_is_file)
     TEST_CHECK(!exists(dir));
 }
 
+TEST_CASE(dest_is_empty_path)
+{
+    std::error_code ec = GetTestEC();
+    TEST_CHECK(fs::create_directories(fs::path{}, ec) == false);
+    TEST_CHECK(ec);
+    TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
+    ExceptionChecker Checker(path{}, std::errc::no_such_file_or_directory,
+                             "create_directories");
+    TEST_CHECK_THROW_RESULT(filesystem_error, Checker,
+                            fs::create_directories(path{}));
+}
+
 #ifdef _WIN32
 TEST_CASE(nonexistent_root)
 {


        


More information about the libcxx-commits mailing list