diff options
author | Jonathan Bauer | 2015-08-28 18:29:55 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-08-28 18:29:55 +0200 |
commit | deed4d717d103ad244bdd3a1d7dfbeac359841e5 (patch) | |
tree | 9ea6053522b6d91b0b4339aaa59f847ce812cfe4 /dozentenmodul | |
parent | [client] save the selected download folder and not the generated folder (diff) | |
download | tutor-module-deed4d717d103ad244bdd3a1d7dfbeac359841e5.tar.gz tutor-module-deed4d717d103ad244bdd3a1d7dfbeac359841e5.tar.xz tutor-module-deed4d717d103ad244bdd3a1d7dfbeac359841e5.zip |
[client] download images as <name>.partial and rename them back to <name> when download finishes
Diffstat (limited to 'dozentenmodul')
3 files changed, 18 insertions, 8 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java index ba236c58..713c16c8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java @@ -134,6 +134,18 @@ public class DownloadTask extends TransferTask { boolean ret = downloader.download(cb, cb); if (!ret) { consecutiveInitFails.incrementAndGet(); + } else { + // remove the temporary '.partial' marking an incomplete download + String tmpFilePath = localFile.getAbsolutePath(); + if (tmpFilePath.endsWith(".partial")) { + // strip the .partial from the filename + String newFilePath = tmpFilePath.substring(0, tmpFilePath.lastIndexOf(".partial")); + if (!localFile.renameTo(new File(newFilePath))) { + // TODO handle + LOGGER.error("Could not rename '" + tmpFilePath + "' to '" + newFilePath + "'"); + } + } + } if (cb.current != null) { chunks.markFailed(cb.current); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java index 11699b6c..8c9d32b6 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java @@ -337,10 +337,6 @@ public class LoginWindow extends LoginWindowLayout { dispose(); return; } -// // did not work -// Gui.showMessageBox(this, -// "Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.", -// MessageType.ERROR, LOGGER, null); } @SuppressWarnings("deprecation") diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index 043063d1..8620fcc5 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -295,7 +295,7 @@ public class ThriftActions { try { hashGen = new AsyncHashGenerator(transferInformation.token, diskFile); hashGen.start(); - Util.sleep(50); // A little ugly... Give the hash generator a head start + Util.sleep(50);// A little ugly... Give the hash generator a head start } catch (FileNotFoundException | NoSuchAlgorithmException e) { Gui.showMessageBox(frame, "Kann keine Block-Hashes für den Upload berechnen, " + "automatische Fehlerkorrektur deaktiviert.", MessageType.WARNING, LOGGER, e); @@ -409,10 +409,12 @@ public class ThriftActions { return; } + // valid path, try to create temp file + final File tmpFile = new File(diskFile.getAbsolutePath() + ".partial"); try { - diskFile.createNewFile(); + tmpFile.createNewFile(); } catch (IOException e) { - Gui.showMessageBox(frame, "Kann die Datei\n" + diskFile.getAbsolutePath() + "\nnicht erzeugen.", + Gui.showMessageBox(frame, "Kann die Datei\n" + tmpFile.getAbsolutePath() + "\nnicht erzeugen.", MessageType.ERROR, LOGGER, e); return; } @@ -434,7 +436,7 @@ public class ThriftActions { final DownloadTask dlTask; try { dlTask = new DownloadTask(Session.getSatelliteAddress(), transInf.getPlainPort(), - transInf.getToken(), diskFile, imageSize, null); + transInf.getToken(), tmpFile, imageSize, null); } catch (FileNotFoundException e) { Gui.asyncMessageBox( "Konnte Download nicht vorbereiten: Der gewählte Zielort ist nicht beschreibbar", |