diff --git a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java index a966d1bcae5..4edc8907d86 100644 --- a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java +++ b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java @@ -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 @@ -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 dataDir = - Files.list(resolvedWhlDir) - .filter( - path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path)) - .findFirst(); + Optional dataDir = Optional.empty(); + try (Stream list = Files.list(resolvedWhlDir)) { + dataDir = list.filter( + path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path)) + .findFirst(); + } if (!dataDir.isPresent()) { return StepExecutionResults.SUCCESS; }