Skip to content

Commit

Permalink
prevent orig file size from being added to tabular files #6118
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jul 16, 2020
1 parent 1957776 commit 115353c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,8 @@ public void setSelectedNonDownloadallableFiles(List<FileMetadata> selectedNonDow
public String getSizeOfDataset() {
boolean countCachedFiles = false;
boolean useOrigFileSize = false;
GetDatasetStorageSizeCommand cmd = new GetDatasetStorageSizeCommand(dvRequestService.getDataverseRequest(), dataset, countCachedFiles, useOrigFileSize, GetDatasetStorageSizeCommand.Mode.DOWNLOAD, workingVersion);
boolean dbOnly = true;
GetDatasetStorageSizeCommand cmd = new GetDatasetStorageSizeCommand(dvRequestService.getDataverseRequest(), dataset, countCachedFiles, dbOnly, useOrigFileSize, GetDatasetStorageSizeCommand.Mode.DOWNLOAD, workingVersion);
try {
long bytes = commandEngine.submit(cmd);
return FileSizeChecker.bytesToHumanReadable(bytes);
Expand All @@ -2915,7 +2916,8 @@ public String getSizeOfDataset() {
public String getSizeOfDatasetOrig() {
boolean countCachedFiles = false;
boolean useOrigFileSize = true;
GetDatasetStorageSizeCommand cmd = new GetDatasetStorageSizeCommand(dvRequestService.getDataverseRequest(), dataset, countCachedFiles, useOrigFileSize, GetDatasetStorageSizeCommand.Mode.DOWNLOAD, workingVersion);
boolean dbOnly = true;
GetDatasetStorageSizeCommand cmd = new GetDatasetStorageSizeCommand(dvRequestService.getDataverseRequest(), dataset, countCachedFiles, useOrigFileSize, dbOnly, GetDatasetStorageSizeCommand.Mode.DOWNLOAD, workingVersion);
try {
long bytes = commandEngine.submit(cmd);
return FileSizeChecker.bytesToHumanReadable(bytes);
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ public long findStorageSize(Dataset dataset, boolean countCachedExtras) throws I

public long findStorageSize(Dataset dataset, boolean countCachedExtras, GetDatasetStorageSizeCommand.Mode mode, DatasetVersion version) throws IOException {
boolean useOrigFileSize = false;
return findStorageSize(dataset, countCachedExtras, useOrigFileSize, mode, version);
boolean dbOnly = false;
return findStorageSize(dataset, countCachedExtras, useOrigFileSize, dbOnly, mode, version);
}
/**
* Returns the total byte size of the files in this dataset
Expand All @@ -892,13 +893,14 @@ public long findStorageSize(Dataset dataset, boolean countCachedExtras, GetDatas
* @param useOrigFileSize allows original tabular file size to be used instead of derived archival file
* @param mode String indicating whether we are getting the result for storage (entire dataset) or download version based
* @param version optional param for dataset version
* @param dbOnly only get bytes from database, no countCachedExtras processing
* @return total size
* @throws IOException if it can't access the objects via StorageIO
* (in practice, this can only happen when called with countCachedExtras=true; when run in the
* default mode, the method doesn't need to access the storage system, as the
* sizes of the main files are recorded in the database)
*/
public long findStorageSize(Dataset dataset, boolean countCachedExtras, boolean useOrigFileSize, GetDatasetStorageSizeCommand.Mode mode, DatasetVersion version) throws IOException {
public long findStorageSize(Dataset dataset, boolean countCachedExtras, boolean useOrigFileSize, boolean dbOnly, GetDatasetStorageSizeCommand.Mode mode, DatasetVersion version) throws IOException {
long total = 0L;

if (dataset.isHarvested()) {
Expand Down Expand Up @@ -935,8 +937,13 @@ public long findStorageSize(Dataset dataset, boolean countCachedExtras, boolean
total += datafile.getFilesize();
}

if (dbOnly) {
// Skip the rest. Don't add any more to the total. No cached extras.
continue;
}

if (!countCachedExtras) {
if (!useOrigFileSize && datafile.isTabularData()) {
if (datafile.isTabularData()) {
// count the size of the stored original, in addition to the main tab-delimited file:
Long originalFileSize = datafile.getDataTable().getOriginalFileSize();
if (originalFileSize != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GetDatasetStorageSizeCommand extends AbstractCommand<Long> {
private final Dataset dataset;
private final Boolean countCachedFiles;
private final boolean useOrigFileSize;
private final boolean dbOnly;
private final Mode mode;
private final DatasetVersion version;

Expand All @@ -46,6 +47,7 @@ public GetDatasetStorageSizeCommand(DataverseRequest aRequest, Dataset target) {
dataset = target;
countCachedFiles = false;
this.useOrigFileSize = false;
this.dbOnly = false;
mode = Mode.DOWNLOAD;
version = null;
}
Expand All @@ -55,15 +57,17 @@ public GetDatasetStorageSizeCommand(DataverseRequest aRequest, Dataset target, b
dataset = target;
this.countCachedFiles = countCachedFiles;
this.useOrigFileSize = false;
this.dbOnly = false;
this.mode = mode;
this.version = version;
}

public GetDatasetStorageSizeCommand(DataverseRequest aRequest, Dataset target, boolean countCachedFiles, boolean useOrigFileSize, Mode mode, DatasetVersion version) {
public GetDatasetStorageSizeCommand(DataverseRequest aRequest, Dataset target, boolean countCachedFiles, boolean useOrigFileSize, boolean dbOnly, Mode mode, DatasetVersion version) {
super(aRequest, target);
dataset = target;
this.countCachedFiles = countCachedFiles;
this.useOrigFileSize = useOrigFileSize;
this.dbOnly = dbOnly;
this.mode = mode;
this.version = version;
}
Expand All @@ -78,7 +82,7 @@ public Long execute(CommandContext ctxt) throws CommandException {
}

try {
return ctxt.datasets().findStorageSize(dataset, countCachedFiles, useOrigFileSize, mode, version);
return ctxt.datasets().findStorageSize(dataset, countCachedFiles, useOrigFileSize, dbOnly, mode, version);
} catch (IOException ex) {
throw new CommandException(BundleUtil.getStringFromBundle("datasets.api.datasize.ioerror"), this);
}
Expand Down

0 comments on commit 115353c

Please sign in to comment.