Repository: nifi Updated Branches: refs/heads/master f0811ca45 -> 8da571d6d
NIFI-2089: Ensure streams are closed before attempting to remove files This closes #573 Signed-off-by: jpercivall <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/8da571d6 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/8da571d6 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/8da571d6 Branch: refs/heads/master Commit: 8da571d6d67d0f6bd870a408210cadf9dae9f61e Parents: f0811ca Author: Mark Payne <[email protected]> Authored: Thu Jun 23 15:21:44 2016 -0400 Committer: jpercivall <[email protected]> Committed: Thu Jun 23 18:43:20 2016 -0400 ---------------------------------------------------------------------- .../controller/repository/FileSystemRepository.java | 10 ++++++++++ .../repository/TestFileSystemRepository.java | 13 +++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/8da571d6/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java index ad8ff49..210fcca 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java @@ -628,6 +628,16 @@ public class FileSystemRepository implements ContentRepository { } catch (final ContentNotFoundException cnfe) { } + // Ensure that we have no writable claim streams for this resource claim + final ByteCountingOutputStream bcos = writableClaimStreams.remove(claim); + if (bcos != null) { + try { + bcos.close(); + } catch (final IOException e) { + LOG.warn("Failed to close Output Stream for {} due to {}", claim, e); + } + } + final File file = path.toFile(); if (!file.delete() && file.exists()) { LOG.warn("Unable to delete {} at path {}", new Object[] {claim, path}); http://git-wip-us.apache.org/repos/asf/nifi/blob/8da571d6/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java index ed792a4..c00b91a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java @@ -329,10 +329,11 @@ public class TestFileSystemRepository { @Test public void testExportToOutputStream() throws IOException { final ContentClaim claim = repository.create(true); - final Path path = getPath(claim); - Files.createDirectories(path.getParent()); - Files.copy(helloWorldFile.toPath(), path, StandardCopyOption.REPLACE_EXISTING); + try (final OutputStream out = repository.write(claim)) { + Files.copy(helloWorldFile.toPath(), out); + } + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); repository.exportTo(claim, baos); final byte[] data = baos.toByteArray(); @@ -342,10 +343,10 @@ public class TestFileSystemRepository { @Test public void testExportToFile() throws IOException { final ContentClaim claim = repository.create(true); - final Path path = getPath(claim); + try (final OutputStream out = repository.write(claim)) { + Files.copy(helloWorldFile.toPath(), out); + } - Files.createDirectories(path.getParent()); - Files.copy(helloWorldFile.toPath(), path, StandardCopyOption.REPLACE_EXISTING); final File outFile = new File("target/testExportToFile"); final Path outPath = outFile.toPath(); Files.deleteIfExists(outPath);
