bug4671 fixed issue with temporary files not properly deleted, upon

uploading socket connection loss
This commit is contained in:
Kai Börnert committed 2018-07-20 17:23:09 +02:00
1 parent 6e046c7e29
commit 155de3537b
1 file changed
+21 -9
@@ -17,6 +17,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DateFormat;
@@ -221,13 +222,23 @@ public class MediaServiceImpl extends RemoteServiceServlet implements MediaServi
private VideoMetadataDTO checkMetadataByFullFileDownload(URL input)
throws ParserConfigurationException, SAXException, IOException {
try (IsoFile isof = new IsoFile(Channels.newChannel(input.openStream()))) {
boolean canDownload = true;
Date recordStartedTimer = determineRecordingStart(isof);
Duration duration = determineDuration(isof);
boolean spherical = determine360(isof);
removeTempFiles(isof);
return new VideoMetadataDTO(canDownload, duration, spherical, recordStartedTimer, "");
File tmp = null;
try {
tmp = File.createTempFile("upload", "metadataCheck");
ReadableByteChannel rbc = Channels.newChannel(input.openStream());
try (FileOutputStream fos = new FileOutputStream(tmp)) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
try (IsoFile isof = new IsoFile(Channels.newChannel(input.openStream()))) {
boolean canDownload = true;
Date recordStartedTimer = determineRecordingStart(isof);
Duration duration = determineDuration(isof);
boolean spherical = determine360(isof);
removeTempFiles(isof);
return new VideoMetadataDTO(canDownload, duration, spherical, recordStartedTimer, "");
}
}
} finally {
Files.delete(tmp.toPath());
}
}
@@ -276,8 +287,9 @@ public class MediaServiceImpl extends RemoteServiceServlet implements MediaServi
Field field = box.getClass().getDeclaredField("dataFile");
field.setAccessible(true);
File data = (File) field.get(box);
data.delete();
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
Files.delete(data.toPath());
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException
| IOException e) {
logger.log(Level.WARNING, "Could not delete mp4 temp files", e);
}
}