[libcxx-commits] [PATCH] D98702: [libcxx] [test] Avoid littering the temp dir with empty directories

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 16 06:07:03 PDT 2021


mstorsjo created this revision.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

When the filesystem tests want to create a directory, a temporary
path is created as <temp>/<cwd filename>/static_env.0. The directory
is created, and when done, this particular directory is removed.
However, the directory <temp>/<cwd filename> is left around, empty.

(When running tests locally, the <cwd filename> bit is derived from
the individual test, like "copy_symlink.pass.cpp.dir". When doing
remote testing, the cwd name is a unique temporary name like
"libcxx.pZVQdKeSEN".)

Instead name these temporary directories as
<temp>/<cwd filename>-static_env.0. That way, when they are removed,
no extra intermediate directory is left behind.

Prior to e0d01294bc124211a8ffb55e69162eb34a242680 <https://reviews.llvm.org/rGe0d01294bc124211a8ffb55e69162eb34a242680>, the temporary
directories were created in only one level, leaving no empty
directories behind.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98702

Files:
  libcxx/test/support/filesystem_test_helper.h


Index: libcxx/test/support/filesystem_test_helper.h
===================================================================
--- libcxx/test/support/filesystem_test_helper.h
+++ libcxx/test/support/filesystem_test_helper.h
@@ -299,11 +299,11 @@
     static inline fs::path available_cwd_path() {
         fs::path const cwd = utils::getcwd();
         fs::path const tmp = fs::temp_directory_path();
-        fs::path const base = tmp / cwd.filename();
+        std::string base = cwd.filename().string();
         int i = 0;
-        fs::path p = base / ("static_env." + std::to_string(i));
+        fs::path p = tmp / (base + "-static_env." + std::to_string(i));
         while (utils::exists(p.string())) {
-            p = fs::path(base) / ("static_env." + std::to_string(++i));
+            p = tmp / (base + "-static_env." + std::to_string(++i));
         }
         return p;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98702.330959.patch
Type: text/x-patch
Size: 885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210316/9122325b/attachment.bin>


More information about the libcxx-commits mailing list