Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

resource leak due Files.list #2661

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/com/facebook/buck/features/python/MovePythonWhlDataStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Stream;

/**
* A {@link Step} that moves the contents of the {package}-{version}.data directory within an
Expand Down Expand Up @@ -56,11 +57,12 @@ public StepExecutionResult execute(ExecutionContext context) throws IOException
// to just list the couple of entries inside of the root of the extracted dir, rather than
// parsing out the *.dist-info/METADATA file (we also would need the package name/version
// anyways to find the .dist-info dir.
Optional<Path> dataDir =
Files.list(resolvedWhlDir)
.filter(
path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path))
.findFirst();
Optional<Path> dataDir = Optional.empty();
try (Stream<Path> list = Files.list(resolvedWhlDir)) {
dataDir = list.filter(
path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path))
.findFirst();
}
if (!dataDir.isPresent()) {
return StepExecutionResults.SUCCESS;
}
Expand Down