summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Schwabe2014-07-29 15:25:55 +0200
committerNils Schwabe2014-07-29 15:25:55 +0200
commit54b40526b3cef4b03707a50126a2db365f331d1e (patch)
tree13a3df7794bba090571bfa37f7a32ab1b94a6e59
parentAdd error handling when CRCScheduler cannot read from crcfile on disk (diff)
downloadmasterserver-54b40526b3cef4b03707a50126a2db365f331d1e.tar.gz
masterserver-54b40526b3cef4b03707a50126a2db365f331d1e.tar.xz
masterserver-54b40526b3cef4b03707a50126a2db365f331d1e.zip
Add some todos for updating an image
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java26
1 files changed, 21 insertions, 5 deletions
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 );
}