-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
Writing a file with the same hash leads to a IllegalArgumentException due to the fact that the source directory is empty. Before copying, the MutableOcflRepository should check if the hash is already present in the inventory.json.
java.lang.IllegalArgumentException: Source must exist and be a directory: /tmp/ocfl3291760920107648701/ocfl-work/e03731555a6eece977a708aaf6a3c780-3248953293/content/r1
at io.ocfl.core.util.FileUtil.moveDirectory(FileUtil.java:90)
at io.ocfl.core.storage.filesystem.FileSystemStorage.moveDirectoryInto(FileSystemStorage.java:266)
at io.ocfl.core.storage.DefaultOcflStorage.moveToRevisionDirectory(DefaultOcflStorage.java:756)
at io.ocfl.core.storage.DefaultOcflStorage.storeNewMutableHeadVersion(DefaultOcflStorage.java:694)
at io.ocfl.core.storage.DefaultOcflStorage.storeNewVersion(DefaultOcflStorage.java:253)
...
public class OCFLTestCase {
@Test
public void testMutable() throws IOException {
Path tempDirectory = Files.createTempDirectory("ocfl");
Path repoDirectoryPath = tempDirectory.resolve("ocfl-repo");
Path workDirectoryPath = tempDirectory.resolve("ocfl-work");
Files.createDirectory(repoDirectoryPath);
Files.createDirectory(workDirectoryPath);
MutableOcflRepository repository = new OcflRepositoryBuilder()
.defaultLayoutConfig(new HashedNTupleLayoutConfig())
.storage(storage -> storage.fileSystem(repoDirectoryPath))
.workDir(workDirectoryPath)
.buildMutable();
String objectId = "object_1";
ObjectVersionId head = ObjectVersionId.head(objectId);
repository.stageChanges(head, new VersionInfo(), (updater) -> {
updater.writeFile(new ByteArrayInputStream(new byte[] { 1 }), "info_1.txt");
});
repository.commitStagedChanges(objectId, new VersionInfo());
repository.stageChanges(head, new VersionInfo(), (updater) -> {
updater.writeFile(new ByteArrayInputStream(new byte[] { 1 }), "info_2.txt");
});
repository.commitStagedChanges(objectId, new VersionInfo());
}
}
Changing one of the byte[] { 1 } to byte[] { 2 } will work as expected.
Metadata
Metadata
Assignees
Labels
No labels