Skip to content

Commit

Permalink
Move files into a scratch directory before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Nov 6, 2024
1 parent 9478914 commit b93c733
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ private OpportunityDatasetUploadStatus createOpportunityDataset(Request req, Res
OpportunityDatasetUploadStatus status = new OpportunityDatasetUploadStatus(regionId, sourceName);
addStatusAndRemoveOldStatuses(status);

// TODO should we delete this temporary directory at the end?
final File tmpDirectory = FileUtils.createScratchDirectory();
final List<File> files = new ArrayList<>();
final List<FileItem> fileItems;
final FileStorageFormat uploadFormat;
Expand All @@ -337,8 +339,9 @@ private OpportunityDatasetUploadStatus createOpportunityDataset(Request req, Res
// Call remove() rather than get() so that subsequent code will see only string parameters, not the files.
fileItems = formFields.remove("files");
for (var fi : fileItems) {
var dfi = (DiskFileItem) fi;
files.add(dfi.getStoreLocation());
var tmpFile = new File(tmpDirectory, fi.getName());
Files.move(((DiskFileItem) fi).getStoreLocation(), tmpFile);
files.add(tmpFile);
}
uploadFormat = detectUploadFormatAndValidate(files);
parameters = extractStringParameters(formFields);
Expand Down Expand Up @@ -540,7 +543,7 @@ private List<Grid> createGridsFromShapefile(List<File> files,
}

// Copy the shapefile component files into a temporary directory with a fixed base name.
File tempDir = Files.createTempDir();
File tempDir = FileUtils.createScratchDirectory();

File shpFile = new File(tempDir, "grid.shp");
Files.copy(filesByExtension.get("SHP"), shpFile);
Expand Down

0 comments on commit b93c733

Please sign in to comment.