Skip to content

Commit c58b368

Browse files
SummerEskibear
authored andcommitted
Fix ftp upload retry logic (#2395)
* Fix ftp upload retry logic * Resolve comments
1 parent a6018c6 commit c58b368

File tree

1 file changed

+14
-13
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig

1 file changed

+14
-13
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/WebAppRunState.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,26 +344,27 @@ private int uploadFileViaZipDeploy(@NotNull WebAppBase webapp, @NotNull File zip
344344

345345
/**
346346
* when upload file to FTP, the plugin will retry 3 times in case of unexpected errors.
347-
* For each try, the method will wait 5 seconds.
348347
*/
349348
private int uploadFileToFtp(@NotNull FTPClient ftp, @NotNull String path,
350-
@NotNull InputStream stream, RunProcessHandler processHandler) throws IOException {
351-
boolean success = false;
352-
int count = 0;
353-
while (!success && ++count < UPLOADING_MAX_TRY) {
349+
@NotNull InputStream stream, RunProcessHandler processHandler) throws IOException {
350+
int retry = UPLOADING_MAX_TRY;
351+
while (retry > 0) {
352+
try {
353+
retry -= 1;
354+
if (ftp.storeFile(path, stream)) {
355+
processHandler.setText(UPLOADING_SUCCESSFUL);
356+
return UPLOADING_MAX_TRY - retry;
357+
}
358+
} catch (IOException e) {
359+
// swallow exception
360+
}
354361
try {
355362
Thread.sleep(SLEEP_TIME);
356363
} catch (InterruptedException e) {
357-
e.printStackTrace();
364+
// swallow exception
358365
}
359-
success = ftp.storeFile(path, stream);
360-
}
361-
if (!success) {
362-
int rc = ftp.getReplyCode();
363-
throw new IOException(String.format(FAIL_FTP_STORE, rc));
364366
}
365-
processHandler.setText(UPLOADING_SUCCESSFUL);
366-
return count;
367+
throw new IOException(String.format(FAIL_FTP_STORE, ftp.getReplyCode()));
367368
}
368369

369370
@NotNull

0 commit comments

Comments
 (0)