Skip to content

Commit a522f36

Browse files
implement more suggestions from code review
[deploy]
1 parent 73332c8 commit a522f36

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/main/java/org/cryptomator/integrations/update/DownloadUpdateStep.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.http.HttpResponse;
1414
import java.nio.channels.Channels;
1515
import java.nio.channels.FileChannel;
16+
import java.nio.file.Files;
1617
import java.nio.file.Path;
1718
import java.nio.file.StandardOpenOption;
1819
import java.security.MessageDigest;
@@ -54,7 +55,14 @@ public String description() {
5455
return switch (downloadThread.getState()) {
5556
case NEW -> Localization.get().getString("org.cryptomator.api.update.download.new");
5657
case TERMINATED -> Localization.get().getString("org.cryptomator.api.update.download.done");
57-
default -> Localization.get().getString("org.cryptomator.api.update.download.progress").formatted(preparationProgress() * 100);
58+
default -> {
59+
double progress = preparationProgress();
60+
if (progress < 0.0) {
61+
yield Localization.get().getString("org.cryptomator.api.update.download.indeterminateProgress");
62+
} else {
63+
yield Localization.get().getString("org.cryptomator.api.update.download.progress").formatted(progress * 100.0);
64+
}
65+
}
5866
};
5967
}
6068

@@ -86,6 +94,11 @@ public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
8694
@Override
8795
public void cancel() {
8896
downloadThread.interrupt();
97+
try {
98+
Files.deleteIfExists(destination);
99+
} catch (IOException e) {
100+
// ignore, this is a best-effort cleanup
101+
}
89102
}
90103

91104
protected void download() {
@@ -119,7 +132,7 @@ protected void downloadInternal(HttpClient client, HttpRequest request) throws I
119132
// prepare checksum calculation
120133
MessageDigest sha256;
121134
try {
122-
sha256 = MessageDigest.getInstance("SHA-256"); // Initialize SHA-256 digest, not used here but can be extended for checksum validation
135+
sha256 = MessageDigest.getInstance("SHA-256");
123136
} catch (NoSuchAlgorithmException e) {
124137
throw new AssertionError("Every implementation of the Java platform is required to support [...] SHA-256", e);
125138
}

src/main/java/org/cryptomator/integrations/update/UpdateStep.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public String description() {
6868

6969
/**
7070
* Blocks the current thread until this update step completed or an error occurred.
71+
* If this step failed, an exception will be rethrown as soon as attempting to invoke {@link #nextStep()}.
7172
* <p>
7273
* If the step is already complete, this method returns immediately.
7374
*
@@ -77,6 +78,7 @@ public String description() {
7778

7879
/**
7980
* Blocks the current thread until this update step completed or an error occurred, or until the specified timeout expires.
81+
* If this step failed, an exception will be rethrown as soon as attempting to invoke {@link #nextStep()}.
8082
* <p>
8183
* If the step is already complete, this method returns immediately.
8284
*

src/main/resources/IntegrationsApi.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
org.cryptomator.api.update.download.new=Download...
2+
org.cryptomator.api.update.download.indeterminateProgress=Downloading...
23
org.cryptomator.api.update.download.progress=Downloading... %1.0f%%
34
org.cryptomator.api.update.download.done=Downloaded.
45

0 commit comments

Comments
 (0)