From ff5cf4a6e6e7fd59e79ff097264644fc1605c464 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 24 Aug 2015 18:33:53 +0200 Subject: [server] Handle image version deletion, interface for sending mails (no SMTP yet) --- .../org/openslx/bwlp/sat/fileserv/FileServer.java | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java') 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 7d158459..6e8bcf1c 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 @@ -18,8 +18,8 @@ import javax.net.ssl.SSLContext; import org.apache.log4j.Logger; import org.openslx.bwlp.sat.database.mappers.DbImage; import org.openslx.bwlp.sat.database.models.LocalImageVersion; -import org.openslx.bwlp.sat.util.Configuration; import org.openslx.bwlp.sat.util.Constants; +import org.openslx.bwlp.sat.util.FileSystem; import org.openslx.bwlp.sat.util.Formatter; import org.openslx.bwlp.sat.util.Identity; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; @@ -190,25 +190,29 @@ public class FileServer implements IncomingEvent { + "/" + Constants.MAX_UPLOADS + ")."); } // Determine src file and go - File srcFile = composeAbsolutePath(localImageData); - if (!srcFile.canRead()) { + File srcFile = FileSystem.composeAbsoluteImagePath(localImageData); + String errorMessage = null; + if (srcFile == null) { + LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + + ": Invalid local relative path"); + errorMessage = "File has invalid path on server"; + } else if (!srcFile.canRead()) { LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Missing " + srcFile.getPath()); - try { - DbImage.markValid(false, true, localImageData); - } catch (SQLException e) { - } - throw new TTransferRejectedException("File missing on server"); + errorMessage = "File missing on server"; } if (srcFile.length() != localImageData.fileSize) { LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Size mismatch for " + srcFile.getPath() + " (expected " + localImageData.fileSize + ", is " + srcFile.length() + ")"); + errorMessage = "File corrupted on server"; + } + if (errorMessage != null) { try { DbImage.markValid(false, true, localImageData); } catch (SQLException e) { } - throw new TTransferRejectedException("File corrupted on server"); + throw new TTransferRejectedException(errorMessage); } String key = UUID.randomUUID().toString(); ActiveDownload transfer = new ActiveDownload(key, srcFile); @@ -216,8 +220,4 @@ public class FileServer implements IncomingEvent { return transfer; } - public static File composeAbsolutePath(LocalImageVersion localImageData) { - return new File(Configuration.getVmStoreBasePath(), localImageData.filePath); - } - } -- cgit v1.2.3-55-g7522