SU3File: Flush and sync on extract (ticket #1941)

This commit is contained in:
zzz
2017-12-08 16:08:17 +00:00
parent a3e42c435c
commit 4c18e2f057

View File

@ -386,7 +386,7 @@ public class SU3File {
*/ */
public boolean verifyAndMigrate(File migrateTo) throws IOException { public boolean verifyAndMigrate(File migrateTo) throws IOException {
InputStream in = null; InputStream in = null;
OutputStream out = null; FileOutputStream out = null;
boolean rv = false; boolean rv = false;
try { try {
in = new BufferedInputStream(new FileInputStream(_file)); in = new BufferedInputStream(new FileInputStream(_file));
@ -421,7 +421,7 @@ public class SU3File {
throw new IOException("unknown signer: " + _signer + " for content type: " + _contentType.getName()); throw new IOException("unknown signer: " + _signer + " for content type: " + _contentType.getName());
} }
if (migrateTo != null) // else verify only if (migrateTo != null) // else verify only
out = new FileOutputStream(migrateTo); out = new SecureFileOutputStream(migrateTo);
byte[] buf = new byte[16*1024]; byte[] buf = new byte[16*1024];
long tot = 0; long tot = 0;
while (tot < _contentLength) { while (tot < _contentLength) {
@ -454,7 +454,15 @@ public class SU3File {
throw ioe; throw ioe;
} finally { } finally {
if (in != null) try { in.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch (IOException ioe) {}
if (out != null) try { out.close(); } catch (IOException ioe) {} if (out != null) {
// We will generally be reading this file right back in,
// so do a POSIX flush and sync to ensure it will be there.
try {
out.flush();
out.getFD().sync();
} catch (IOException ioe) {}
try { out.close(); } catch (IOException ioe) {}
}
if (migrateTo != null && !rv) if (migrateTo != null && !rv)
migrateTo.delete(); migrateTo.delete();
} }