Changing import command to allow AppleSingle data fork to be 0 bytes.

This is explicitly allowed in the AppleSingle standard. #84
This commit is contained in:
Rob Greene 2022-06-21 20:05:41 -05:00
parent 8ca3e27fc4
commit 6468f3af46
3 changed files with 17 additions and 1 deletions

View File

@ -276,9 +276,12 @@ public class ImportCommand extends ReadWriteDiskCommandOptions {
if (as.getProdosFileInfo() == null) {
throw new IOException("This AppleSingle does not contain a ProDOS file.");
}
if (as.getDataFork() == null || as.getDataFork().length == 0) {
if (as.getDataFork() == null) {
throw new IOException("This AppleSingle does not contain a data fork.");
}
if (as.getDataFork().length == 0) {
LOG.warning("This AppleSingle has a 0 byte data fork.");
}
ProdosFileInfo info = as.getProdosFileInfo();
String fileType = ProdosFormatDisk.getFiletype(info.getFileType());

View File

@ -114,8 +114,11 @@ public class FileUtils {
source.getLastModificationDate().ifPresent(target::setLastModificationDate);
if (source.getFileData().isPresent() && source.getResourceData().isPresent()) {
LOG.finest(() -> String.format("Setting data fork to %d bytes and resource fork to %d bytes.",
source.getFileData().get().length, source.getResourceData().get().length));
target.setFileData(source.getFileData().get(), source.getResourceData().get());
} else {
LOG.finest(() -> String.format("Setting data fork to %d bytes.", source.getFileData().get().length));
source.getFileData().ifPresent(target::setFileData);
}
}

View File

@ -190,6 +190,12 @@ public class FileStreamer {
currentDisk = tuple.formattedDisk;
beforeDisk.accept(currentDisk);
}
// Special case when we have a disk with no files
// This allows triggering of the before and after disk events.
if (tuple.fileEntry == null) {
files.remove(tuple);
return hasNext();
}
} else {
if (currentDisk != null) {
afterDisk.accept(currentDisk);
@ -219,6 +225,10 @@ public class FileStreamer {
for (FileEntry fileEntry : tuple.directoryEntry.getFiles()) {
list.add(tuple.of(fileEntry));
}
// Special case? If disk is empty we need to force a tuple as none is generated
if (tuple.directoryEntry == tuple.formattedDisk && tuple.directoryEntry.getFiles().isEmpty()) {
list.add(tuple);
}
} catch (DiskException e) {
if (!ignoreErrorsFlag) {
throw new RuntimeException(e);