Fix some zipos directory related bugs

This commit is contained in:
Justine Tunney 2023-09-18 22:17:56 -07:00
parent ec480f5aa0
commit ececec4c94
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 114 additions and 30 deletions

View file

@ -404,16 +404,22 @@ static struct dirent *readdir_zipos(DIR *dir) {
s += dir->zip.prefix.len;
n -= dir->zip.prefix.len;
const char *p = memchr(s, '/', n);
if (p) n = p - s;
int d_type;
if (p) {
n = p - s;
d_type = DT_DIR;
} else if (S_ISDIR(GetZipCfileMode(dir->zip.zipos->map +
dir->zip.offset))) {
d_type = DT_DIR;
} else {
d_type = DT_REG;
}
if ((n = MIN(n, sizeof(ent->d_name) - 1)) &&
critbit0_emplace(&dir->zip.found, s, n) == 1) {
ent = &dir->ent;
ent->d_ino = dir->zip.offset;
ent->d_off = dir->tell;
ent->d_type =
S_ISDIR(GetZipCfileMode(dir->zip.zipos->map + dir->zip.offset))
? DT_DIR
: DT_REG;
ent->d_type = d_type;
memcpy(ent->d_name, s, n);
ent->d_name[n] = 0;
}