From f500d1a5cf47230a26a4e2b2fe124815052578da Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Fri, 2 Jun 2023 15:46:50 +0200 Subject: [server] Use upload token as filename for ongoing uploads --- .../java/org/openslx/bwlp/sat/fileserv/FileServer.java | 9 +++++---- .../java/org/openslx/bwlp/sat/thrift/ServerHandler.java | 2 +- .../src/main/java/org/openslx/bwlp/sat/util/Formatter.java | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java index 597e4306..04212c42 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java @@ -156,22 +156,23 @@ public class FileServer implements IncomingEvent { + "/" + Constants.MAX_UPLOADS + ")."); } File destinationFile = null; + String uploadkey = UUID.randomUUID().toString(); do { - destinationFile = Formatter.getTempImageName(); + destinationFile = Formatter.getTempImageName(uploadkey); } while (destinationFile.exists()); destinationFile.getParentFile().mkdirs(); - String key = UUID.randomUUID().toString(); IncomingDataTransfer upload; try { - upload = new IncomingDataTransfer(key, owner, image, destinationFile, fileSize, sha1Sums, + upload = new IncomingDataTransfer(uploadkey, owner, image, destinationFile, fileSize, sha1Sums, machineDescription, false); } catch (FileNotFoundException e) { LOGGER.error("Could not open destination file for writing", e); throw new TTransferRejectedException("Destination file not writable!"); } - uploads.put(key, upload); + LOGGER.info(owner.getFirstName() + " " + owner.getLastName() + " (" + owner.getUserId() + ") started upload " + uploadkey + " of '" + image.getImageName() + "'"); + uploads.put(uploadkey, upload); return upload; } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java index f2382d78..ad99b2cf 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java @@ -166,7 +166,7 @@ public class ServerHandler implements SatelliteServer.Iface { public void cancelUpload(String uploadToken) { IncomingDataTransfer upload = fileServer.getUploadByToken(uploadToken); if (upload != null) { - LOGGER.debug("User is cancelling upload " + uploadToken); + LOGGER.info("User is cancelling upload " + uploadToken); upload.cancel(); } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java index 268ceda1..0bdc0ab7 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Formatter.java @@ -25,6 +25,20 @@ public class Formatter { + Constants.INCOMPLETE_UPLOAD_SUFFIX); } + /** + * Generate a file name used for a virtual machine + * image that is currently uploading, but use a given + * string as part of the file name. + * String should be some random uuid to get a unique + * file name. + * + * @param s String to use as part of the filename + * @return Absolute path name of file + */ + public static File getTempImageName(String s) { + return new File(Configuration.getCurrentVmStorePath(), s + Constants.INCOMPLETE_UPLOAD_SUFFIX); + } + /** * Generate a file name for the given VM based on owner and display name. * -- cgit v1.2.3-55-g7522