From 54b40526b3cef4b03707a50126a2db365f331d1e Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Tue, 29 Jul 2014 15:25:55 +0200 Subject: Add some todos for updating an image --- .../serverconnection/ImageProcessor.java | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java index f73f019..73e2f4a 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java @@ -81,6 +81,19 @@ public class ImageProcessor throw new ImageDataException( ImageDataError.INVALID_DATA, "User is not known." ); } + DbImage i; + boolean isUpdate = false; + if ( ( i = DbImage.getImageByUUID( imageData.uuid ) ) != null ) { + // image is already available + // is the client updating?? + if ( imageData.imageVersion <= i.imageVersion ) { + throw new ImageDataException( ImageDataError.INVALID_DATA, "This image with the same or a newer version is already available." ); + } else { + // TODO: update db and prepare for new image file + isUpdate = true; + } + } + log.debug( serverSessionId + " is submitting " + imageData.uuid ); String uuid = imageData.uuid; @@ -93,7 +106,7 @@ public class ImageProcessor synchronized ( uploadingImages ) { // check if image is already uploading if ( ( image = uploadingImages.get( uuid ) ) != null ) { - if (image.getCrcFile() == null) { + if ( image.getCrcFile() == null ) { CRCFile crcFile; try { // try to write crc file ... @@ -118,7 +131,7 @@ public class ImageProcessor } if ( !CRCFile.sumsAreValid( crcSums ) ) throw new UploadException( UploadError.INVALID_CRC, "CRC sums were invalid." ); - filepath = Globals.getImageDir() + "/" + uuid + ".vmdk"; + filepath = Globals.getImageDir() + "/" + uuid + ".vmdk"; // TODO: needs to be saved in another way... (Because of the versions.) token = RandomString.generate( 100, false ); nBlocks = Util.getNumberOfBlocks( imageData.fileSize, Globals.blockSize ); allBlocks = new int[ nBlocks ]; // initialize array with all zeros which mean that this block is missing @@ -129,7 +142,7 @@ public class ImageProcessor CRCFile crcFile; try { // try to write crc file ... - crcFile = CRCFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); + crcFile = CRCFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); //TODO: same here ^ } catch ( IOException e ) { // ... and keep it in ram if it fails crcFile = new CRCFile( crcSums ); @@ -137,11 +150,14 @@ public class ImageProcessor image.setCrcFile( crcFile ); ConnectionHandler.addConnection( token, filepath, Connection.UPLOADING ).image = image; - DbImage.insert( imageData, System.currentTimeMillis(), token, nBlocks, serverSessionId, filepath ); + if ( isUpdate ) { + // TODO: update db + } else { + DbImage.insert( imageData, System.currentTimeMillis(), token, nBlocks, serverSessionId, filepath ); + } imagesToCheck.add( uuid ); log.debug( imagesToCheck ); - log.debug( "Returning UploadInfos. Client should goint to start the upload. " ); log.debug( image.toString() ); return new UploadInfos( token, Globals.getSslSocketPort(), getNMissingBlocks( image, AMOUNT ), false ); } -- cgit v1.2.3-55-g7522