Skip to content

add optional clean results before run#1253

Merged
skuznetsov-al merged 2 commits intomainfrom
clean-results-directory
Mar 25, 2026
Merged

add optional clean results before run#1253
skuznetsov-al merged 2 commits intomainfrom
clean-results-directory

Conversation

@skuznetsov-al
Copy link
Contributor

Context

Checklist

@skuznetsov-al skuznetsov-al added type:improvement Change that improves some user experience but can't be considered as a new feature and removed theme:core labels Mar 24, 2026
Comment on lines +122 to +156
private void cleanDirectoryContents(final Path directory) {
try {
if (!Files.exists(directory)) {
return;
}
try (Stream<Path> stream = Files.list(directory)) {
stream.forEach(path -> {
try {
if (Files.isDirectory(path)) {
deleteDirectory(path);
} else {
Files.deleteIfExists(path);
}
} catch (IOException e) {
LOGGER.warn("Failed to delete {} during directory cleanup", path, e);
}
});
}
} catch (IOException e) {
LOGGER.warn("Failed to clean directory contents: {}", directory, e);
}
}

private void deleteDirectory(final Path directory) throws IOException {
try (Stream<Path> stream = Files.walk(directory)) {
stream.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.deleteIfExists(path);
} catch (IOException e) {
LOGGER.warn("Failed to delete {} during directory deletion", path, e);
}
});
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void cleanDirectoryContents(final Path directory) {
try {
if (!Files.exists(directory)) {
return;
}
try (Stream<Path> stream = Files.list(directory)) {
stream.forEach(path -> {
try {
if (Files.isDirectory(path)) {
deleteDirectory(path);
} else {
Files.deleteIfExists(path);
}
} catch (IOException e) {
LOGGER.warn("Failed to delete {} during directory cleanup", path, e);
}
});
}
} catch (IOException e) {
LOGGER.warn("Failed to clean directory contents: {}", directory, e);
}
}
private void deleteDirectory(final Path directory) throws IOException {
try (Stream<Path> stream = Files.walk(directory)) {
stream.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.deleteIfExists(path);
} catch (IOException e) {
LOGGER.warn("Failed to delete {} during directory deletion", path, e);
}
});
}
}
private void cleanDirectoryContents(final Path directory) {
if (!Files.exists(directory)) {
return;
}
try (Stream<Path> stream = Files.walk(directory)) {
stream.sorted(Comparator.reverseOrder())
.filter(path -> !path.equals(directory))
.forEach(path -> {
try {
Files.deleteIfExists(path);
} catch (IOException e) {
LOGGER.warn("Failed to delete {} during directory cleanup", path, e);
}
});
} catch (IOException e) {
LOGGER.warn("Failed to clean directory contents: {}", directory, e);
}
}

it should work the same way

@skuznetsov-al skuznetsov-al merged commit d94943d into main Mar 25, 2026
7 checks passed
@skuznetsov-al skuznetsov-al deleted the clean-results-directory branch March 25, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:core type:improvement Change that improves some user experience but can't be considered as a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants