Skip to content

Commit 8245f26

Browse files
committed
[dsymutil] Remove empty reproducer directory on exit
In the case the reproducer isn't generated, we don't want to leave around an empty temporary directory. Fixes #61920 Differential Revision: https://reviews.llvm.org/D147498
1 parent 53152f1 commit 8245f26

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

llvm/test/tools/dsymutil/X86/reproducer.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Recreate the folder structure in a temp directory we can remove later.
66
RUN: rm -rf %t
7-
RUN: mkdir -p %t/Inputs
7+
RUN: mkdir -p %t/Inputs %t/tempdir
88
RUN: cp %p/../Inputs/basic.macho.x86_64 %t/Inputs
99
RUN: cp %p/../Inputs/basic1.macho.x86_64.o %t/Inputs
1010
RUN: cp %p/../Inputs/basic2.macho.x86_64.o %t/Inputs
@@ -16,6 +16,10 @@ RUN: dsymutil -f -o - -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 | llvm-d
1616
# Make sure we don't crash with an empty TMPDIR.
1717
RUN: env TMPDIR="" dsymutil -o -f -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1
1818

19+
# Make sure we don't leave around a temporary directory.
20+
RUN: env TMPDIR="%t/tempdir" dsymutil -o - -f %t/Inputs/basic.macho.x86_64
21+
RUN: not ls %t/tempdir/dsymutil-*
22+
1923
# Create a reproducer.
2024
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
2125
RUN: llvm-dwarfdump -a %t.generate | FileCheck %s

llvm/tools/dsymutil/Reproducer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ ReproducerGenerate::ReproducerGenerate(std::error_code &EC, int Argc,
4040
ReproducerGenerate::~ReproducerGenerate() {
4141
if (GenerateOnExit && !Generated)
4242
generate();
43+
else if (!Generated && !Root.empty())
44+
sys::fs::remove_directories(Root, /* IgnoreErrors */ true);
4345
}
4446

4547
void ReproducerGenerate::generate() {

0 commit comments

Comments
 (0)