Fixing listing for empty disks to display header and footer in acx; otherwise output is empty. Inspired by this PR: https://github.com/AppleCommander/AppleCommander/pull/95

This commit is contained in:
Rob Greene 2023-10-25 18:29:17 -05:00
parent a91bcec4a9
commit 5da84ae082
2 changed files with 18 additions and 2 deletions

View File

@ -173,7 +173,7 @@ public class FileStreamer {
private FileTupleIterator() {
for (FormattedDisk formattedDisk : formattedDisks) {
files.addAll(toTupleList(FileTuple.of(formattedDisk)));
files.add(FileTuple.of(formattedDisk));
}
}
@ -190,6 +190,12 @@ public class FileStreamer {
currentDisk = tuple.formattedDisk;
beforeDisk.accept(currentDisk);
}
// Handle disks independently and guarantee disk events fire for empty disks
if (tuple.isDisk()) {
tuple = files.removeFirst();
files.addAll(0, toTupleList(tuple));
return hasNext();
}
} else {
if (currentDisk != null) {
afterDisk.accept(currentDisk);
@ -203,7 +209,7 @@ public class FileStreamer {
public FileTuple next() {
if (hasNext()) {
FileTuple tuple = files.removeFirst();
if (recursiveFlag && tuple.fileEntry.isDirectory()) {
if (recursiveFlag && tuple.isDirectory()) {
FileTuple newTuple = tuple.pushd(tuple.fileEntry);
files.addAll(0, toTupleList(newTuple));
}

View File

@ -52,6 +52,16 @@ public class FileTuple {
newPaths.add(directoryEntry.getFilename());
return new FileTuple(formattedDisk, newPaths, (DirectoryEntry)directoryEntry, null);
}
public boolean isDisk() {
// Just in case directoryEntry is unset or is a disk - looks like either cna occur!
return fileEntry == null && (directoryEntry == null || directoryEntry == formattedDisk);
}
public boolean isDirectory() {
return !isDisk() && (fileEntry == null || fileEntry.isDirectory());
}
public boolean isFile() {
return fileEntry != null && !fileEntry.isDirectory();
}
public FileTuple of(FileEntry fileEntry) {
return new FileTuple(formattedDisk, paths, directoryEntry, fileEntry);
}