Added support for single file uploads.

This process could potentially be simplified if we were to modify the structure of the actual zipped data (on the writer side), but this approach is more of a "catch-all" (on the reader side) to support multiple different zip structures, giving us more flexibility. We can still choose to modify the written zip structure if we choose to, which would then cause most of this new code to be skipped.

Note: the filename of a single file is not currently retained; it is renamed to "data" as part of the packaging process. Need to decide if this is okay before we go live.
This commit is contained in:
CalDescent
2021-11-12 13:35:50 +00:00
parent 7bc745fa8e
commit 236a456cae
2 changed files with 56 additions and 2 deletions

View File

@@ -167,7 +167,7 @@ public class ArbitraryDataReader {
private void createUncompressedDirectory() {
try {
Files.createDirectories(this.uncompressedPath);
Files.createDirectories(this.uncompressedPath.getParent());
} catch (IOException e) {
throw new IllegalStateException("Unable to create temp directory");
}
@@ -366,9 +366,24 @@ public class ArbitraryDataReader {
throw new IllegalStateException(String.format("Unable to unzip file: %s", e.getMessage()));
}
// If unzipped data was a file not a directory, move it into a data/ directory so that the .qortal
// metadata folder is able to be created there too
if (this.uncompressedPath.toFile().isFile()) {
// Rename to temporary filename
Path tempDest = Paths.get(this.uncompressedPath.getParent().toString(), "data2");
this.uncompressedPath.toFile().renameTo(tempDest.toFile());
// Create a "data" directory
Files.createDirectories(this.uncompressedPath);
// Move the original file into the newly created directory
Path finalPath = Paths.get(this.uncompressedPath.toString(), "data");
tempDest.toFile().renameTo(finalPath.toFile());
}
// Replace filePath pointer with the uncompressed file path
if (FilesystemUtils.pathInsideDataOrTempPath(this.filePath)) {
Files.delete(this.filePath);
if (Files.exists(this.filePath)) {
Files.delete(this.filePath);
}
}
this.filePath = this.uncompressedPath;
}