forked from Qortal/qortal
Renamed newly added classes to ArbitraryData*.java instead of DataFile*.java
This commit is contained in:
parent
e15cf063c6
commit
16d93b1775
@ -47,7 +47,7 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.storage.DataFile;
|
||||
import org.qortal.storage.DataFileChunk;
|
||||
import org.qortal.storage.DataFileWriter;
|
||||
import org.qortal.storage.ArbitraryDataWriter;
|
||||
import org.qortal.transaction.ArbitraryTransaction;
|
||||
import org.qortal.transaction.Transaction;
|
||||
import org.qortal.transaction.Transaction.TransactionType;
|
||||
@ -272,16 +272,16 @@ public class ArbitraryResource {
|
||||
Service service = Service.ARBITRARY_DATA;
|
||||
Compression compression = Compression.NONE;
|
||||
|
||||
DataFileWriter dataFileWriter = new DataFileWriter(Paths.get(path), name, service, method, compression);
|
||||
ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(path), name, service, method, compression);
|
||||
try {
|
||||
dataFileWriter.save();
|
||||
arbitraryDataWriter.save();
|
||||
} catch (IOException | DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE);
|
||||
} catch (IllegalStateException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
|
||||
DataFile dataFile = dataFileWriter.getDataFile();
|
||||
DataFile dataFile = arbitraryDataWriter.getDataFile();
|
||||
if (dataFile == null) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.storage.DataFile;
|
||||
import org.qortal.storage.DataFile.*;
|
||||
import org.qortal.storage.DataFileReader;
|
||||
import org.qortal.storage.DataFileWriter;
|
||||
import org.qortal.storage.ArbitraryDataReader;
|
||||
import org.qortal.storage.ArbitraryDataWriter;
|
||||
import org.qortal.transaction.ArbitraryTransaction;
|
||||
import org.qortal.transaction.Transaction;
|
||||
import org.qortal.transform.TransformationException;
|
||||
@ -103,16 +103,16 @@ public class WebsiteResource {
|
||||
ArbitraryTransactionData.Service service = ArbitraryTransactionData.Service.WEBSITE;
|
||||
ArbitraryTransactionData.Compression compression = ArbitraryTransactionData.Compression.ZIP;
|
||||
|
||||
DataFileWriter dataFileWriter = new DataFileWriter(Paths.get(path), name, service, method, compression);
|
||||
ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(path), name, service, method, compression);
|
||||
try {
|
||||
dataFileWriter.save();
|
||||
arbitraryDataWriter.save();
|
||||
} catch (IOException | DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE);
|
||||
} catch (IllegalStateException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
|
||||
DataFile dataFile = dataFileWriter.getDataFile();
|
||||
DataFile dataFile = arbitraryDataWriter.getDataFile();
|
||||
if (dataFile == null) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
@ -203,16 +203,16 @@ public class WebsiteResource {
|
||||
Method method = Method.PUT;
|
||||
Compression compression = Compression.ZIP;
|
||||
|
||||
DataFileWriter dataFileWriter = new DataFileWriter(Paths.get(directoryPath), name, service, method, compression);
|
||||
ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(directoryPath), name, service, method, compression);
|
||||
try {
|
||||
dataFileWriter.save();
|
||||
arbitraryDataWriter.save();
|
||||
} catch (IOException | DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE);
|
||||
} catch (IllegalStateException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
}
|
||||
|
||||
DataFile dataFile = dataFileWriter.getDataFile();
|
||||
DataFile dataFile = arbitraryDataWriter.getDataFile();
|
||||
if (dataFile != null) {
|
||||
String digest58 = dataFile.digest58();
|
||||
if (digest58 != null) {
|
||||
@ -286,16 +286,16 @@ public class WebsiteResource {
|
||||
}
|
||||
|
||||
Service service = Service.WEBSITE;
|
||||
DataFileReader dataFileReader = new DataFileReader(resourceId, resourceIdType, service);
|
||||
dataFileReader.setSecret58(secret58); // Optional, used for loading encrypted file hashes only
|
||||
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(resourceId, resourceIdType, service);
|
||||
arbitraryDataReader.setSecret58(secret58); // Optional, used for loading encrypted file hashes only
|
||||
try {
|
||||
// TODO: overwrite if new transaction arrives, to invalidate cache
|
||||
// We could store the latest transaction signature in the extracted folder
|
||||
dataFileReader.load(false);
|
||||
arbitraryDataReader.load(false);
|
||||
} catch (Exception e) {
|
||||
return this.get404Response();
|
||||
}
|
||||
java.nio.file.Path path = dataFileReader.getFilePath();
|
||||
java.nio.file.Path path = arbitraryDataReader.getFilePath();
|
||||
if (path == null) {
|
||||
return this.get404Response();
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DataFileBuilder {
|
||||
public class ArbitraryDataBuilder {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileBuilder.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataBuilder.class);
|
||||
|
||||
private String name;
|
||||
private Service service;
|
||||
@ -30,7 +30,7 @@ public class DataFileBuilder {
|
||||
private List<Path> paths;
|
||||
private Path finalPath;
|
||||
|
||||
public DataFileBuilder(String name, Service service) {
|
||||
public ArbitraryDataBuilder(String name, Service service) {
|
||||
this.name = name;
|
||||
this.service = service;
|
||||
this.paths = new ArrayList<>();
|
||||
@ -104,10 +104,10 @@ public class DataFileBuilder {
|
||||
|
||||
// Build the data file, overwriting anything that was previously there
|
||||
String sig58 = Base58.encode(transactionData.getSignature());
|
||||
DataFileReader dataFileReader = new DataFileReader(sig58, ResourceIdType.TRANSACTION_DATA, this.service);
|
||||
dataFileReader.setTransactionData(transactionData);
|
||||
dataFileReader.load(true);
|
||||
Path path = dataFileReader.getFilePath();
|
||||
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(sig58, ResourceIdType.TRANSACTION_DATA, this.service);
|
||||
arbitraryDataReader.setTransactionData(transactionData);
|
||||
arbitraryDataReader.load(true);
|
||||
Path path = arbitraryDataReader.getFilePath();
|
||||
if (path == null) {
|
||||
throw new IllegalStateException(String.format("Null path when building data from transaction %s", sig58));
|
||||
}
|
||||
@ -119,9 +119,9 @@ public class DataFileBuilder {
|
||||
}
|
||||
|
||||
private void buildLatestState() throws IOException, DataException {
|
||||
DataFilePatches dataFilePatches = new DataFilePatches(this.paths);
|
||||
dataFilePatches.applyPatches();
|
||||
this.finalPath = dataFilePatches.getFinalPath();
|
||||
ArbitraryDataPatches arbitraryDataPatches = new ArbitraryDataPatches(this.paths);
|
||||
arbitraryDataPatches.applyPatches();
|
||||
this.finalPath = arbitraryDataPatches.getFinalPath();
|
||||
}
|
||||
|
||||
public Path getFinalPath() {
|
@ -7,15 +7,15 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DataFileCombiner {
|
||||
public class ArbitraryDataCombiner {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileCombiner.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataCombiner.class);
|
||||
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path finalPath;
|
||||
|
||||
public DataFileCombiner(Path pathBefore, Path pathAfter) {
|
||||
public ArbitraryDataCombiner(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
this.pathAfter = pathAfter;
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class DataFileCombiner {
|
||||
}
|
||||
|
||||
private void process() throws IOException {
|
||||
DataFileMerge merge = new DataFileMerge(this.pathBefore, this.pathAfter);
|
||||
ArbitraryDataMerge merge = new ArbitraryDataMerge(this.pathBefore, this.pathAfter);
|
||||
merge.compute();
|
||||
this.finalPath = merge.getMergePath();
|
||||
}
|
@ -8,15 +8,15 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DataFileCreatePatch {
|
||||
public class ArbitraryDataCreatePatch {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileCreatePatch.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataCreatePatch.class);
|
||||
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path finalPath;
|
||||
|
||||
public DataFileCreatePatch(Path pathBefore, Path pathAfter) {
|
||||
public ArbitraryDataCreatePatch(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
this.pathAfter = pathAfter;
|
||||
}
|
||||
@ -46,7 +46,7 @@ public class DataFileCreatePatch {
|
||||
|
||||
private void process() {
|
||||
|
||||
DataFileDiff diff = new DataFileDiff(this.pathBefore, this.pathAfter);
|
||||
ArbitraryDataDiff diff = new ArbitraryDataDiff(this.pathBefore, this.pathAfter);
|
||||
diff.compute();
|
||||
this.finalPath = diff.getDiffPath();
|
||||
}
|
@ -10,15 +10,15 @@ import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DataFileDiff {
|
||||
public class ArbitraryDataDiff {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileDiff.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataDiff.class);
|
||||
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path diffPath;
|
||||
|
||||
public DataFileDiff(Path pathBefore, Path pathAfter) {
|
||||
public ArbitraryDataDiff(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
this.pathAfter = pathAfter;
|
||||
}
|
||||
@ -91,14 +91,14 @@ public class DataFileDiff {
|
||||
LOGGER.info("File size was modified: {}", after.toString());
|
||||
wasModified = true;
|
||||
}
|
||||
else if (!Arrays.equals(DataFileDiff.digestFromPath(after), DataFileDiff.digestFromPath(filePathBefore))) {
|
||||
else if (!Arrays.equals(ArbitraryDataDiff.digestFromPath(after), ArbitraryDataDiff.digestFromPath(filePathBefore))) {
|
||||
// Check hashes as a last resort
|
||||
LOGGER.info("File contents were modified: {}", after.toString());
|
||||
wasModified = true;
|
||||
}
|
||||
|
||||
if (wasAdded | wasModified) {
|
||||
DataFileDiff.copyFilePathToBaseDir(after, diffPathAbsolute, filePathAfter);
|
||||
ArbitraryDataDiff.copyFilePathToBaseDir(after, diffPathAbsolute, filePathAfter);
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
@ -138,7 +138,7 @@ public class DataFileDiff {
|
||||
if (!Files.exists(directoryPathAfter)) {
|
||||
LOGGER.info("Directory was removed: {}", directoryPathAfter.toString());
|
||||
|
||||
DataFileDiff.markFilePathAsRemoved(diffPathAbsolute, directoryPathBefore);
|
||||
ArbitraryDataDiff.markFilePathAsRemoved(diffPathAbsolute, directoryPathBefore);
|
||||
// TODO: we might need to mark directories differently to files
|
||||
// TODO: add path to manifest JSON
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class DataFileDiff {
|
||||
if (!Files.exists(filePathAfter)) {
|
||||
LOGGER.trace("File was removed: {}", before.toString());
|
||||
|
||||
DataFileDiff.markFilePathAsRemoved(diffPathAbsolute, filePathBefore);
|
||||
ArbitraryDataDiff.markFilePathAsRemoved(diffPathAbsolute, filePathBefore);
|
||||
// TODO: add path to manifest JSON
|
||||
}
|
||||
|
@ -12,15 +12,15 @@ import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DataFileMerge {
|
||||
public class ArbitraryDataMerge {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileMerge.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataMerge.class);
|
||||
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path mergePath;
|
||||
|
||||
public DataFileMerge(Path pathBefore, Path pathAfter) {
|
||||
public ArbitraryDataMerge(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
this.pathAfter = pathAfter;
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class DataFileMerge {
|
||||
}
|
||||
|
||||
private void copyPreviousStateToMergePath() throws IOException {
|
||||
DataFileMerge.copyDirPathToBaseDir(this.pathBefore, this.mergePath, Paths.get(""));
|
||||
ArbitraryDataMerge.copyDirPathToBaseDir(this.pathBefore, this.mergePath, Paths.get(""));
|
||||
}
|
||||
|
||||
private void findDifferences() {
|
||||
@ -102,21 +102,21 @@ public class DataFileMerge {
|
||||
LOGGER.trace("File size was modified: {}", after.toString());
|
||||
wasModified = true;
|
||||
}
|
||||
else if (!Arrays.equals(DataFileMerge.digestFromPath(after), DataFileMerge.digestFromPath(filePathBefore))) {
|
||||
else if (!Arrays.equals(ArbitraryDataMerge.digestFromPath(after), ArbitraryDataMerge.digestFromPath(filePathBefore))) {
|
||||
// Check hashes as a last resort
|
||||
LOGGER.trace("File contents were modified: {}", after.toString());
|
||||
wasModified = true;
|
||||
}
|
||||
|
||||
if (wasAdded | wasModified) {
|
||||
DataFileMerge.copyFilePathToBaseDir(after, mergePathAbsolute, filePathAfter);
|
||||
ArbitraryDataMerge.copyFilePathToBaseDir(after, mergePathAbsolute, filePathAfter);
|
||||
}
|
||||
|
||||
if (wasRemoved) {
|
||||
if (filePathAfter.toString().endsWith(".removed")) {
|
||||
// Trim the ".removed"
|
||||
Path filePathAfterTrimmed = Paths.get(filePathAfter.toString().substring(0, filePathAfter.toString().length()-8));
|
||||
DataFileMerge.deletePathInBaseDir(mergePathAbsolute, filePathAfterTrimmed);
|
||||
ArbitraryDataMerge.deletePathInBaseDir(mergePathAbsolute, filePathAfterTrimmed);
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class DataFilePatches {
|
||||
public class ArbitraryDataPatches {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFilePatches.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataPatches.class);
|
||||
|
||||
private List<Path> paths;
|
||||
private Path finalPath;
|
||||
|
||||
public DataFilePatches(List<Path> paths) {
|
||||
public ArbitraryDataPatches(List<Path> paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ public class DataFilePatches {
|
||||
// Loop from the second path onwards
|
||||
for (int i=1; i<paths.size(); i++) {
|
||||
Path pathAfter = this.paths.get(i);
|
||||
DataFileCombiner combiner = new DataFileCombiner(pathBefore, pathAfter);
|
||||
ArbitraryDataCombiner combiner = new ArbitraryDataCombiner(pathBefore, pathAfter);
|
||||
combiner.combine();
|
||||
pathBefore = combiner.getFinalPath(); // TODO: cleanup
|
||||
}
|
@ -28,9 +28,9 @@ import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DataFileReader {
|
||||
public class ArbitraryDataReader {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileReader.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataReader.class);
|
||||
|
||||
private String resourceId;
|
||||
private ResourceIdType resourceIdType;
|
||||
@ -44,7 +44,7 @@ public class DataFileReader {
|
||||
private Path uncompressedPath;
|
||||
private Path unencryptedPath;
|
||||
|
||||
public DataFileReader(String resourceId, ResourceIdType resourceIdType, Service service) {
|
||||
public ArbitraryDataReader(String resourceId, ResourceIdType resourceIdType, Service service) {
|
||||
this.resourceId = resourceId;
|
||||
this.resourceIdType = resourceIdType;
|
||||
this.service = service;
|
||||
@ -173,7 +173,7 @@ public class DataFileReader {
|
||||
private void fetchFromName() throws IllegalStateException, IOException, DataException {
|
||||
|
||||
// Build the existing state using past transactions
|
||||
DataFileBuilder builder = new DataFileBuilder(this.resourceId, this.service);
|
||||
ArbitraryDataBuilder builder = new ArbitraryDataBuilder(this.resourceId, this.service);
|
||||
builder.build();
|
||||
Path builtPath = builder.getFinalPath();
|
||||
if (builtPath == null) {
|
@ -22,9 +22,9 @@ import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class DataFileWriter {
|
||||
public class ArbitraryDataWriter {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DataFileWriter.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataWriter.class);
|
||||
|
||||
private Path filePath;
|
||||
private String name;
|
||||
@ -40,7 +40,7 @@ public class DataFileWriter {
|
||||
private Path compressedPath;
|
||||
private Path encryptedPath;
|
||||
|
||||
public DataFileWriter(Path filePath, String name, Service service, Method method, Compression compression) {
|
||||
public ArbitraryDataWriter(Path filePath, String name, Service service, Method method, Compression compression) {
|
||||
this.filePath = filePath;
|
||||
this.name = name;
|
||||
this.service = service;
|
||||
@ -107,13 +107,13 @@ public class DataFileWriter {
|
||||
private void processPatch() throws DataException, IOException {
|
||||
|
||||
// Build the existing state using past transactions
|
||||
DataFileBuilder builder = new DataFileBuilder(this.name, this.service);
|
||||
ArbitraryDataBuilder builder = new ArbitraryDataBuilder(this.name, this.service);
|
||||
builder.build();
|
||||
Path builtPath = builder.getFinalPath();
|
||||
|
||||
// Compute a diff of the latest changes on top of the previous state
|
||||
// Then use only the differences as our data payload
|
||||
DataFileCreatePatch patch = new DataFileCreatePatch(builtPath, this.filePath);
|
||||
ArbitraryDataCreatePatch patch = new ArbitraryDataCreatePatch(builtPath, this.filePath);
|
||||
patch.create();
|
||||
this.filePath = patch.getFinalPath();
|
||||
}
|
Loading…
Reference in New Issue
Block a user