Skip to content

Commit

Permalink
Fix file traversal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz authored and vabold committed Jan 18, 2024
1 parent 870fb55 commit 506dc41
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions source/abstract/Archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ ArchiveHandle::ArchiveHandle(void *archiveStart) : m_startAddress(archiveStart)
m_currentNode = 0;
}

// NOTE (vabold): If anyone wants to de-spaghetti this, please feel free
// My hope is that I can leave this function alone forever
s32 ArchiveHandle::convertPathToEntryId(const char *path) const {
u32 entryId = m_currentNode;

Expand Down Expand Up @@ -66,35 +64,29 @@ s32 ArchiveHandle::convertPathToEntryId(const char *path) const {

bool found = false;
const u32 anchor = entryId++;
while (entryId < node(anchor)->m_directory.m_next) {
while (true) {
if (node(anchor)->isDirectory() || !endOfPath) {
const char *entryName = m_strings + node(entryId)->stringOffset();

if (entryName[0] == '.' && entryName[1] == '\0') {
entryId++;
continue;
}

if (strcmp(path, entryName) == 0) {
found = true;
break;
}
}
while (entryId < parse<u32>(node(anchor)->m_directory.m_next)) {
if (!node(anchor)->isDirectory() && endOfPath) {
entryId++;
continue;
}

if (node(entryId)->isDirectory()) {
entryId = node(entryId)->m_directory.m_next;
break;
}
const char *entryName = m_strings + node(entryId)->stringOffset();

if (entryName[0] == '.' && entryName[1] == '\0') {
entryId++;
continue;
}

if (!found) {
return -1;
if (strncmp(path, entryName, nameLength) == 0) {
found = true;
break;
}

break;
entryId++;
}

if (!found) {
return -1;
}

if (endOfPath) {
Expand Down

0 comments on commit 506dc41

Please sign in to comment.