[PATCH] D147498: [dsymutil] Remove empty reproducer directory on exit

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 21:49:51 PDT 2023


keith created this revision.
keith added a reviewer: JDevlieghere.
Herald added a project: All.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In the case the reproducer isn't generated, we don't want to leave
around an empty temporary directory.

Fixes https://github.com/llvm/llvm-project/issues/61920


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147498

Files:
  llvm/test/tools/dsymutil/X86/reproducer.test
  llvm/tools/dsymutil/Reproducer.cpp


Index: llvm/tools/dsymutil/Reproducer.cpp
===================================================================
--- llvm/tools/dsymutil/Reproducer.cpp
+++ llvm/tools/dsymutil/Reproducer.cpp
@@ -40,6 +40,8 @@
 ReproducerGenerate::~ReproducerGenerate() {
   if (GenerateOnExit && !Generated)
     generate();
+  else if (!Generated && !Root.empty())
+    sys::fs::remove_directories(Root, /* IgnoreErrors */ true);
 }
 
 void ReproducerGenerate::generate() {
Index: llvm/test/tools/dsymutil/X86/reproducer.test
===================================================================
--- llvm/test/tools/dsymutil/X86/reproducer.test
+++ llvm/test/tools/dsymutil/X86/reproducer.test
@@ -4,7 +4,7 @@
 
 # Recreate the folder structure in a temp directory we can remove later.
 RUN: rm -rf %t
-RUN: mkdir -p %t/Inputs
+RUN: mkdir -p %t/Inputs %t/tempdir
 RUN: cp %p/../Inputs/basic.macho.x86_64 %t/Inputs
 RUN: cp %p/../Inputs/basic1.macho.x86_64.o %t/Inputs
 RUN: cp %p/../Inputs/basic2.macho.x86_64.o %t/Inputs
@@ -16,6 +16,10 @@
 # Make sure we don't crash with an empty TMPDIR.
 RUN: env TMPDIR="" dsymutil -o -f -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1
 
+# Make sure we don't leave around a temporary directory.
+RUN: env TMPDIR="%t/tempdir" dsymutil -o - -f %t/Inputs/basic.macho.x86_64
+RUN: not ls %t/tempdir/dsymutil-*
+
 # Create a reproducer.
 RUN: env DSYMUTIL_REPRODUCER_PATH=%t.repro dsymutil -gen-reproducer -f -o %t.generate -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1 | FileCheck %s --check-prefixes=REPRODUCER
 RUN: llvm-dwarfdump -a %t.generate | FileCheck %s


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147498.510685.patch
Type: text/x-patch
Size: 1593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230404/876c31c1/attachment.bin>


More information about the llvm-commits mailing list