Skip to content

Commit

Permalink
More fixes for the command. #9361
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed May 11, 2023
1 parent 2ac403d commit 87c7383
Showing 1 changed file with 8 additions and 11 deletions.
Expand Up @@ -118,7 +118,6 @@ public CreateNewDataFilesCommand(DataverseRequest aRequest, DatasetVersion versi

@Override
public CreateDataFileResult execute(CommandContext ctxt) throws CommandException {
logger.info("entering command.execute();");
List<DataFile> datafiles = new ArrayList<>();

//When there is no checksum/checksumtype being sent (normal upload, needs to be calculated), set the type to the current default
Expand All @@ -135,8 +134,6 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
Long storageQuotaLimit = null;

if (ctxt.systemConfig().isStorageQuotasEnforced()) {
//storageQuotaLimit = ctxt.files().getClass()...;
//UserStorageQuota quota = ctxt.files().getUserStorageQuota(super.getRequest().getAuthenticatedUser(), this.version.getDataset());
if (quota != null) {
storageQuotaLimit = quota.getRemainingQuotaInBytes();
}
Expand Down Expand Up @@ -220,9 +217,11 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
}

DataFile datafile = null;
long fileSize = 0L;
try {
uncompressedIn = new GZIPInputStream(new FileInputStream(tempFile.toFile()));
File unZippedTempFile = saveInputStreamInTempFile(uncompressedIn, fileSizeLimit, storageQuotaLimit);
fileSize = unZippedTempFile.length();
datafile = FileUtil.createSingleDataFile(version, unZippedTempFile, finalFileName, MIME_TYPE_UNDETERMINED_DEFAULT, ctxt.systemConfig().getFileFixityChecksumAlgorithm());
} catch (IOException | FileExceedsMaxSizeException | FileExceedsStorageQuotaException ioex) {
// it looks like we simply skip the file silently, if its uncompressed size
Expand Down Expand Up @@ -253,7 +252,7 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
datafiles.add(datafile);
// Update quota if present
if (quota != null) {
quota.setTotalUsageInBytes(quota.getTotalUsageInBytes() - datafile.getFilesize());
quota.setTotalUsageInBytes(quota.getTotalUsageInBytes() + fileSize);
}
return CreateDataFileResult.success(fileName, finalType, datafiles);
}
Expand Down Expand Up @@ -539,7 +538,7 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
logger.severe("Processing of zipped shapefile failed.");
return CreateDataFileResult.error(fileName, finalType);
}
Long storageQuotaLimitForRezippedFiles = storageQuotaLimit;
long combinedRezippedFileSize = 0L;

try {

Expand All @@ -551,7 +550,7 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
continue;
}

File unZippedShapeTempFile = saveInputStreamInTempFile(finalFileInputStream, fileSizeLimit, storageQuotaLimitForRezippedFiles);
File unZippedShapeTempFile = saveInputStreamInTempFile(finalFileInputStream, fileSizeLimit, storageQuotaLimit != null ? storageQuotaLimit - combinedRezippedFileSize : null);
DataFile new_datafile = FileUtil.createSingleDataFile(version, unZippedShapeTempFile, finalFile.getName(), finalType, ctxt.systemConfig().getFileFixityChecksumAlgorithm());

String directoryName = null;
Expand All @@ -569,10 +568,8 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
}
if (new_datafile != null) {
datafiles.add(new_datafile);
combinedRezippedFileSize += unZippedShapeTempFile.length();
// todo: can this new_datafile be null?
if (storageQuotaLimitForRezippedFiles != null) {
storageQuotaLimitForRezippedFiles = storageQuotaLimitForRezippedFiles - new_datafile.getFilesize();
}
} else {
logger.severe("Could not add part of rezipped shapefile. new_datafile was null: " + finalFile.getName());
}
Expand Down Expand Up @@ -615,7 +612,7 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException
}
// update the quota object:
if (quota != null) {
quota.setTotalUsageInBytes(storageQuotaLimitForRezippedFiles);
quota.setTotalUsageInBytes(quota.getTotalUsageInBytes() + combinedRezippedFileSize);
}
return CreateDataFileResult.success(fileName, finalType, datafiles);
} else {
Expand Down Expand Up @@ -686,7 +683,7 @@ public CreateDataFileResult execute(CommandContext ctxt) throws CommandException

// Update quota (may not be necessary in the context of direct upload - ?)
if (quota != null) {
quota.setTotalUsageInBytes(quota.getTotalUsageInBytes() - datafile.getFilesize());
quota.setTotalUsageInBytes(quota.getTotalUsageInBytes() + fileSize);
}
return CreateDataFileResult.success(fileName, finalType, datafiles);
}
Expand Down

0 comments on commit 87c7383

Please sign in to comment.