fix: fix ramdisk readdir inconsistency.
This commit is contained in:
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 108
|
||||
#define MONTAUK_BUILD_NUMBER 109
|
||||
|
||||
@@ -262,6 +262,10 @@ namespace Fs::Ramdisk {
|
||||
}
|
||||
|
||||
int ReadDirAt(const char* path, const char** outNames, int maxEntries, int startIndex) {
|
||||
if (path == nullptr || outNames == nullptr || maxEntries < 0 || startIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Reject outright if path names an existing regular file: without this,
|
||||
// a file with no matching "path/..." children below falls through to
|
||||
// the child-scan loop and returns 0 (empty), which callers that use
|
||||
@@ -269,10 +273,10 @@ namespace Fs::Ramdisk {
|
||||
int selfIdx = FindEntryByPath(path);
|
||||
if (selfIdx >= 0 && !fileTable[selfIdx].isDirectory) return -1;
|
||||
|
||||
// Normalize path: skip leading '/'
|
||||
if (path[0] == '/') path++;
|
||||
|
||||
int pathLen = StrLen(path);
|
||||
char normalized[MaxNameLen];
|
||||
int pathLen = NormalizePath(path, normalized, MaxNameLen);
|
||||
if (pathLen < 0) return -1;
|
||||
path = normalized;
|
||||
int count = 0; // entries written to outNames
|
||||
int seen = 0; // matching direct children scanned so far (for startIndex skip)
|
||||
|
||||
@@ -280,6 +284,7 @@ namespace Fs::Ramdisk {
|
||||
const char* entryName = fileTable[i].name;
|
||||
bool isChild = false;
|
||||
|
||||
const char* childName = entryName;
|
||||
if (pathLen == 0) {
|
||||
// Root directory: find entries without '/' in them (or only trailing '/')
|
||||
bool hasSlash = false;
|
||||
@@ -311,11 +316,14 @@ namespace Fs::Ramdisk {
|
||||
}
|
||||
}
|
||||
isChild = (!hasDeepSlash && restLen > 0);
|
||||
childName = rest;
|
||||
}
|
||||
|
||||
if (!isChild) continue;
|
||||
if (seen++ < startIndex) continue; // skip entries before the requested page
|
||||
outNames[count++] = entryName;
|
||||
// ReadDir follows the same contract as ext2/FAT32: return the
|
||||
// direct child's name, not its archive path relative to root.
|
||||
outNames[count++] = childName;
|
||||
}
|
||||
|
||||
// A path with no directory entry and no children does not exist.
|
||||
|
||||
Reference in New Issue
Block a user