Fix readdir that doesn't return dt_type
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 23 Feb 2017 09:47:13 +0000 (10:47 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 23 Feb 2017 09:47:13 +0000 (10:47 +0100)
This is an incomplete fix. More readdir calls
exists that should be treated.

Change-Id: Ib80c9f4ac8fe7ce02d22968a9cf37f7841514f57
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/wgtpkg-zip.c

index e450c0f..a182261 100644 (file)
@@ -243,6 +243,7 @@ static int zwr(struct zws *zws, size_t offset)
        zip_int64_t z64;
        struct zip_source *zsrc;
        FILE *fp;
+       struct stat st;
 
        fd = openat(workdirfd, offset ? zws->name : ".", O_DIRECTORY|O_RDONLY);
        if (fd < 0) {
@@ -275,6 +276,13 @@ static int zwr(struct zws *zws, size_t offset)
                                ERROR("invalid name %s", zws->name);
                                goto error;
                        }
+                       if (ent->d_type == DT_UNKNOWN) {
+                               fstatat(fd, ent->d_name, &st, 0);
+                               if (S_ISREG(st.st_mode))
+                                       ent->d_type = DT_REG;
+                               else if (S_ISDIR(st.st_mode))
+                                       ent->d_type = DT_DIR;
+                       }
                        switch (ent->d_type) {
                        case DT_DIR:
                                z64 = zip_dir_add(zws->zip, zws->name, ZIP_FL_ENC_UTF_8);