Skip to content

Commit 7a3fb49

Browse files
committed
get: also benefits from temp download mechanism
1 parent 4dfde5a commit 7a3fb49

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

src/main/java/me/itzg/helpers/get/GetCommand.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ public class GetCommand implements Callable<Integer> {
134134
@Option(names = "--retry-delay", description = "in seconds", defaultValue = "2")
135135
int retryDelay;
136136

137-
@Option(names = {"--use-temp-file"},
138-
description = "Download to a temporary file in the same directory with .download extension, then rename to the final destination when complete",
139-
defaultValue = "false")
140-
boolean useTempFile;
141-
142137
@Parameters(split = OPTION_SPLIT_COMMAS, paramLabel = "URI",
143138
description = "The URI of the resource to retrieve. When the output is a directory,"
144139
+ " more than one URI can be requested.",
@@ -214,10 +209,8 @@ null, new JsonPathOutputHandler(
214209
stdout.println(outputFile);
215210
}
216211
} else {
217-
final Path saveToFile = getSaveToFile();
218-
try {
219212
final Path file = fetch(uris.get(0))
220-
.toFile(saveToFile)
213+
.toFile(outputFile)
221214
.skipUpToDate(skipUpToDate)
222215
.acceptContentTypes(acceptContentTypes)
223216
.handleDownloaded((uri, f, contentSizeBytes) -> {
@@ -226,25 +219,9 @@ null, new JsonPathOutputHandler(
226219
}
227220
})
228221
.execute();
229-
if (useTempFile) {
230-
Files.move(saveToFile, outputFile);
231-
}
232222
if (this.outputFilename) {
233223
stdout.println(file);
234224
}
235-
} catch (Exception e) {
236-
// Clean up temp file if download fails
237-
if (useTempFile && Files.exists(saveToFile)) {
238-
try {
239-
Files.delete(saveToFile);
240-
log.debug("Cleaned up temporary file {} after failed download", saveToFile);
241-
} catch (IOException cleanupEx) {
242-
log.warn("Failed to clean up temporary file {} after failed download",
243-
saveToFile, cleanupEx);
244-
}
245-
}
246-
throw e; // Re-throw the original exception
247-
}
248225
}
249226
}
250227
} catch (URISyntaxException e) {
@@ -500,10 +477,5 @@ private static URI removeUserInfo(URI uri) throws URISyntaxException {
500477
);
501478
}
502479

503-
private Path getSaveToFile() {
504-
return useTempFile ?
505-
Paths.get(outputFile.toString() + ".download") :
506-
outputFile;
507-
}
508480

509481
}

0 commit comments

Comments
 (0)