mirror of https://github.com/apache/nifi.git
NIFI-2089: Ensure streams are closed before attempting to remove files
This closes #573 Signed-off-by: jpercivall <joepercivall@yahoo.com>
This commit is contained in:
parent
f0811ca45a
commit
8da571d6d6
|
@ -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});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue