Skip to content

Commit 1de235b

Browse files
authored
Merge pull request #196 from StillGreen-san/strengthen-uploadthread
strengthen uploadthread
2 parents 679ca86 + d74a9f7 commit 1de235b

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/UploadThread.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,32 @@ public void initiatorError(String input, String... placeholders) {
187187
*/
188188
@Override
189189
public void run() {
190-
Config config = ConfigParser.getConfig();
191190
if (initiator != null && backupStatus != BackupStatus.NOT_RUNNING) {
192191
logger.initiatorError(
193-
intl("backup-already-running"),
192+
intl("backup-already-running"),
194193
"backup-status", getBackupStatus());
195194
return;
196195
}
196+
try {
197+
run_internal();
198+
} catch (Exception e) {
199+
lastBackupSuccessful = false;
200+
throw e;
201+
} finally {
202+
backupStatus = BackupStatus.NOT_RUNNING;
203+
if (lastBackupSuccessful) {
204+
DriveBackupApi.backupDone();
205+
} else {
206+
DriveBackupApi.backupError();
207+
}
208+
}
209+
}
210+
211+
/**
212+
* actual backup logic
213+
*/
214+
void run_internal() {
215+
Config config = ConfigParser.getConfig();
197216
totalTimer.start();
198217
backupStatus = BackupStatus.STARTING;
199218
if (!locationsToBePruned.isEmpty()) {
@@ -302,12 +321,6 @@ public void run() {
302321
long totalBackupTime = totalTimer.getTime();
303322
long totalSeconds = Duration.of(totalBackupTime, ChronoUnit.MILLIS).getSeconds();
304323
logger.log(intl("backup-total-time"), "time", String.valueOf(totalSeconds));
305-
backupStatus = BackupStatus.NOT_RUNNING;
306-
if (errorOccurred) {
307-
DriveBackupApi.backupError();
308-
} else {
309-
DriveBackupApi.backupDone();
310-
}
311324
}
312325

313326
private void ensureMethodsAuthenticated() {
@@ -561,11 +574,9 @@ public static String getBackupStatus() {
561574
message = intl("backup-status-uploading");
562575
break;
563576
case STARTING:
564-
message = intl("backup-status-starting");
565-
break;
577+
return intl("backup-status-starting");
566578
case PRUNING:
567-
message = intl("backup-status-pruning");
568-
break;
579+
return intl("backup-status-pruning");
569580
default:
570581
return intl("backup-status-not-running");
571582
}
@@ -608,7 +619,7 @@ public static String getNextAutoBackup() {
608619
* Sets the time of the next interval-based backup to the current time + the configured interval.
609620
*/
610621
public static void updateNextIntervalBackupTime() {
611-
nextIntervalBackupTime = LocalDateTime.now().plus(ConfigParser.getConfig().backupStorage.delay, ChronoUnit.MINUTES);
622+
nextIntervalBackupTime = LocalDateTime.now().plusMinutes(ConfigParser.getConfig().backupStorage.delay);
612623
}
613624

614625
public static boolean wasLastBackupSuccessful() {

0 commit comments

Comments
 (0)