Backup DB is now closed if backup fails due to exception

This commit is contained in:
Rsl1122 2018-05-25 09:55:08 +03:00
parent 1e75a665b9
commit 4291a94cc6

View File

@ -30,16 +30,22 @@ public class ManageUtils {
* @param copyFromDB Database you want to backup.
*/
public static void backup(String dbName, Database copyFromDB) throws DBInitException, SQLException {
String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-");
String fileName = dbName + "-backup-" + timeStamp;
SQLiteDB backupDB = new SQLiteDB(fileName);
Collection<UUID> uuids = ManageUtils.getUUIDS(copyFromDB);
if (uuids.isEmpty()) {
return;
SQLiteDB backupDB = null;
try {
String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-");
String fileName = dbName + "-backup-" + timeStamp;
backupDB = new SQLiteDB(fileName);
Collection<UUID> uuids = ManageUtils.getUUIDS(copyFromDB);
if (uuids.isEmpty()) {
return;
}
backupDB.init();
clearAndCopy(backupDB, copyFromDB);
} finally {
if (backupDB != null) {
backupDB.close();
}
}
backupDB.init();
clearAndCopy(backupDB, copyFromDB);
backupDB.close();
}
/**