Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit d239f28

Browse files
author
mikkomaa
authored
Merge pull request #374 from tmc-cli/updater-check-juha
Abort if couldn't fetch binary
2 parents 61cbb02 + 3fd5d54 commit d239f28

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/java/fi/helsinki/cs/tmc/cli/updater/TmcCliUpdater.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public boolean run() {
7878
File destination = new File(currentBinLocation + binName);
7979

8080
io.println("Downloading...");
81-
fetchTmcCliBinary(dlUrl, destination);
81+
if (!fetchTmcCliBinary(dlUrl, destination)) {
82+
return false;
83+
}
8284

8385
io.println("Running " + destination.getAbsolutePath());
8486
return runNewTmcCliBinary(destination.getAbsolutePath());
@@ -136,16 +138,18 @@ protected String fetchLatestReleaseJson() {
136138
* Downloads a binary file from downloadUrl and saves it to destination
137139
* file.
138140
*/
139-
protected void fetchTmcCliBinary(String downloadUrl, File destination) {
141+
protected boolean fetchTmcCliBinary(String downloadUrl, File destination) {
140142
byte[] content = fetchHttpEntity(downloadUrl);
141143
if (content == null) {
142144
io.println("Failed to download tmc-cli.");
143-
return;
145+
return false;
144146
}
145147
try {
146148
FileUtils.writeByteArrayToFile(destination, content);
149+
return true;
147150
} catch (IOException ex) {
148151
io.println("Failed to write the new version into \'" + destination + "\'.");
152+
return false;
149153
}
150154
}
151155

src/test/java/fi/helsinki/cs/tmc/cli/updater/TmcCliUpdaterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void downloadsAndRunsNewBinaryIfOk() {
107107
TmcCliUpdater updater = spy(new TmcCliUpdater(io, "0.1.0", false));
108108
doReturn(latestJson).when(updater).fetchLatestReleaseJson();
109109
//when(updater.fetchLatestReleaseJson()).thenReturn(latestJson);
110-
doNothing().when(updater).fetchTmcCliBinary(any(String.class), any(File.class));
110+
doReturn(true).when(updater).fetchTmcCliBinary(any(String.class), any(File.class));
111111
when(updater.runNewTmcCliBinary(any(String.class))).thenReturn(true);
112112
updater.run();
113113
assertThat(io.out(), containsString("A new version of tmc-cli is available!"));

0 commit comments

Comments
 (0)