@@ -169,33 +169,36 @@ public void close() {
169
169
throw new DataException ("Target already closed" );
170
170
}
171
171
172
- if (!deleted ) {
173
- // If we get error on closing the stream we must return it to the caller
174
- RuntimeException streamCloseException = null ;
175
- try {
176
- closeStreams ();
177
- } catch (final RuntimeException e ) {
178
- streamCloseException = e ;
179
- }
180
-
181
- // Only write meta for the root target.
182
- if (parent == null ) {
183
- // Update attributes and write the manifest.
184
- updateAttribute (this , MetaFields .RAW_SIZE , String .valueOf (getStreamSize ()));
185
- updateAttribute (this , MetaFields .FILE_SIZE , String .valueOf (getTotalFileSize ()));
186
- writeManifest ();
187
-
188
- if (streamCloseException == null ) {
189
- // Unlock will update the meta data so set it back on the stream
190
- // target so the client has the up to date copy
191
- unlock (getMeta (), getAttributes ());
192
- } else {
193
- throw streamCloseException ;
172
+ try {
173
+ if (!deleted ) {
174
+ // If we get error on closing the stream we must return it to the caller
175
+ RuntimeException streamCloseException = null ;
176
+ try {
177
+ closeStreams ();
178
+ } catch (final RuntimeException e ) {
179
+ streamCloseException = e ;
180
+ } finally {
181
+ // Only write meta for the root target.
182
+ if (parent == null ) {
183
+ // Update attributes and write the manifest.
184
+ updateAttribute (this , MetaFields .RAW_SIZE , String .valueOf (getStreamSize ()));
185
+ updateAttribute (this , MetaFields .FILE_SIZE , String .valueOf (getTotalFileSize ()));
186
+ writeManifest ();
187
+
188
+ if (streamCloseException == null ) {
189
+ // Unlock will update the meta data so set it back on the stream
190
+ // target so the client has the up to date copy
191
+ unlock (getMeta (), getAttributes ());
192
+ } else {
193
+ throw streamCloseException ;
194
+ }
195
+ }
194
196
}
195
197
}
198
+ } finally {
199
+ outputStream = null ;
200
+ closed = true ;
196
201
}
197
-
198
- closed = true ;
199
202
}
200
203
201
204
private void unlock (final Meta meta , final AttributeMap attributeMap ) {
@@ -225,16 +228,20 @@ public void delete() {
225
228
// Close the stream target.
226
229
closeStreams ();
227
230
} finally {
228
- // Only delete the root target.
229
- if (parent == null ) {
230
- // Mark the target meta as deleted.
231
- this .meta = metaService .updateStatus (meta , Status .LOCKED , Status .DELETED );
231
+ try {
232
+ // Only delete the root target.
233
+ if (parent == null ) {
234
+ // Mark the target meta as deleted.
235
+ this .meta = metaService .updateStatus (meta , Status .LOCKED , Status .DELETED );
236
+ }
237
+ } finally {
238
+ outputStream = null ;
239
+ deleted = true ;
232
240
}
233
- deleted = true ;
234
241
}
235
242
}
236
243
237
- private synchronized void closeStreams () {
244
+ private void closeStreams () {
238
245
RuntimeException exception = null ;
239
246
240
247
// Close the stream target.
@@ -244,8 +251,6 @@ private synchronized void closeStreams() {
244
251
} catch (final IOException e ) {
245
252
LOGGER .error (() -> "closeStreams() - Error on closing stream " + this , e );
246
253
exception = new UncheckedIOException (e );
247
- } finally {
248
- outputStream = null ;
249
254
}
250
255
}
251
256
0 commit comments