Skip to content

Commit 7d54f24

Browse files
committed
streamline results directory cleanup logic
1 parent 4db4ee2 commit 7d54f24

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

allure-java-commons/src/main/java/io/qameta/allure/FileSystemResultsWriter.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,38 +120,21 @@ private void ensureInitialized() {
120120
}
121121

122122
private void cleanDirectoryContents(final Path directory) {
123-
try {
124-
if (!Files.exists(directory)) {
125-
return;
126-
}
127-
try (Stream<Path> stream = Files.list(directory)) {
128-
stream.forEach(path -> {
129-
try {
130-
if (Files.isDirectory(path)) {
131-
deleteDirectory(path);
132-
} else {
133-
Files.deleteIfExists(path);
134-
}
135-
} catch (IOException e) {
136-
LOGGER.warn("Failed to delete {} during directory cleanup", path, e);
137-
}
138-
});
139-
}
140-
} catch (IOException e) {
141-
LOGGER.warn("Failed to clean directory contents: {}", directory, e);
123+
if (!Files.exists(directory)) {
124+
return;
142125
}
143-
}
144-
145-
private void deleteDirectory(final Path directory) throws IOException {
146126
try (Stream<Path> stream = Files.walk(directory)) {
147127
stream.sorted(Comparator.reverseOrder())
128+
.filter(path -> !path.equals(directory))
148129
.forEach(path -> {
149130
try {
150131
Files.deleteIfExists(path);
151132
} catch (IOException e) {
152-
LOGGER.warn("Failed to delete {} during directory deletion", path, e);
133+
LOGGER.warn("Failed to delete {} during directory cleanup", path, e);
153134
}
154135
});
136+
} catch (IOException e) {
137+
LOGGER.warn("Failed to clean directory contents: {}", directory, e);
155138
}
156139
}
157140

0 commit comments

Comments
 (0)