mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Merge branch 'check-if-listfiles-returns-null' into 'master'
Check whether File#listFiles() returns null The docs say this can happen if there's an I/O error. Also fixed a throw-in-finally-block warning and renamed an IoUtils method to make its contract clearer. See merge request !328
This commit is contained in:
@@ -35,6 +35,7 @@ class H2Database extends JdbcDatabase {
|
||||
+ ";WRITE_DELAY=0;DB_CLOSE_ON_EXIT=false";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open() throws DbException {
|
||||
boolean reopen = config.databaseExists();
|
||||
if (!reopen) config.getDatabaseDirectory().mkdirs();
|
||||
@@ -42,6 +43,7 @@ class H2Database extends JdbcDatabase {
|
||||
return reopen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws DbException {
|
||||
// H2 will close the database when the last connection closes
|
||||
try {
|
||||
@@ -51,6 +53,7 @@ class H2Database extends JdbcDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFreeSpace() throws DbException {
|
||||
File dir = config.getDatabaseDirectory();
|
||||
long maxSize = config.getMaxSize();
|
||||
@@ -63,7 +66,9 @@ class H2Database extends JdbcDatabase {
|
||||
private long getDiskSpace(File f) {
|
||||
if (f.isDirectory()) {
|
||||
long total = 0;
|
||||
for (File child : f.listFiles()) total += getDiskSpace(child);
|
||||
File[] children = f.listFiles();
|
||||
if (children != null)
|
||||
for (File child : children) total += getDiskSpace(child);
|
||||
return total;
|
||||
} else if (f.isFile()) {
|
||||
return f.length();
|
||||
|
||||
@@ -35,7 +35,7 @@ class DevReporterImpl implements DevReporter {
|
||||
private final DevConfig devConfig;
|
||||
private final SocketFactory torSocketFactory;
|
||||
|
||||
public DevReporterImpl(CryptoComponent crypto, DevConfig devConfig,
|
||||
DevReporterImpl(CryptoComponent crypto, DevConfig devConfig,
|
||||
SocketFactory torSocketFactory) {
|
||||
this.crypto = crypto;
|
||||
this.devConfig = devConfig;
|
||||
@@ -90,7 +90,7 @@ class DevReporterImpl implements DevReporter {
|
||||
Socket s = connectToDevelopers();
|
||||
out = s.getOutputStream();
|
||||
in = new FileInputStream(f);
|
||||
IoUtils.copy(in, out);
|
||||
IoUtils.copyAndClose(in, out);
|
||||
f.delete();
|
||||
} catch (IOException e) {
|
||||
LOG.log(WARNING, "Failed to send reports", e);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class IoUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(InputStream in, OutputStream out)
|
||||
public static void copyAndClose(InputStream in, OutputStream out)
|
||||
throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user