nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jperciv...@apache.org
Subject nifi git commit: NIFI-2089: Ensure streams are closed before attempting to remove files
Date Thu, 23 Jun 2016 22:30:22 GMT
Repository: nifi
Updated Branches:
  refs/heads/0.x 03c937623 -> 56dc8aefa


NIFI-2089: Ensure streams are closed before attempting to remove files

This closes #573

Signed-off-by: jpercivall <joepercivall@yahoo.com>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/56dc8aef
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/56dc8aef
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/56dc8aef

Branch: refs/heads/0.x
Commit: 56dc8aefac822454f2d4133e8cbde903a628ec5b
Parents: 03c9376
Author: Mark Payne <markap14@hotmail.com>
Authored: Thu Jun 23 15:21:44 2016 -0400
Committer: jpercivall <joepercivall@yahoo.com>
Committed: Thu Jun 23 18:29:10 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/56dc8aef/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/56dc8aef/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);


Mime
View raw message