archivers/zip.c
changeset 379 d0c4ae4a302f
parent 376 1e71c1ca196b
child 399 02dd53688315
equal deleted inserted replaced
378:41cda991e23a 379:d0c4ae4a302f
  1228                 rc = -1;
  1228                 rc = -1;
  1229             else if (ch > '/')
  1229             else if (ch > '/')
  1230                 rc = 1;
  1230                 rc = 1;
  1231             else 
  1231             else 
  1232             {
  1232             {
  1233                 if ((name[dlen + 1] == '\0') || (stop_on_first_find))
  1233                 
       
  1234                 if (stop_on_first_find) /* Just checking dir's existance? */
  1234                     return(middle);
  1235                     return(middle);
       
  1236 
       
  1237                 if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
       
  1238                     return(middle + 1);
  1235 
  1239 
  1236                 /* there might be more entries earlier in the list. */
  1240                 /* there might be more entries earlier in the list. */
  1237                 retval = middle;
  1241                 retval = middle;
  1238                 hi = middle - 1;
  1242                 hi = middle - 1;
  1239             } /* else */
  1243             } /* else */
  1251 
  1255 
  1252 static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
  1256 static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
  1253                                             const char *dirname,
  1257                                             const char *dirname,
  1254                                             int omitSymLinks)
  1258                                             int omitSymLinks)
  1255 {
  1259 {
  1256 #if 1
       
  1257     return(NULL);  /* !!! FIXME */
       
  1258 #else
       
  1259     ZIPinfo *info = ((ZIPinfo *) h->opaque);
  1260     ZIPinfo *info = ((ZIPinfo *) h->opaque);
  1260     PHYSFS_sint32 i, tmp, max;
       
  1261     LinkedStringList *retval = NULL, *p = NULL;
  1261     LinkedStringList *retval = NULL, *p = NULL;
  1262     PHYSFS_uint32 dlen = strlen(dirname);
  1262     PHYSFS_sint32 dlen, dlen_inc, max, i;
  1263 
       
  1264     if ((dlen > 0) && (dirname[dlen - 1] == '/'))
       
  1265         dlen--;
       
  1266 
  1263 
  1267     i = zip_find_start_of_dir(info, dirname, 0);
  1264     i = zip_find_start_of_dir(info, dirname, 0);
  1268     BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  1265     BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  1269 
  1266 
  1270     for (max = (PHYSFS_sint32) info->entryCount; i < max; i++)
  1267     dlen = strlen(dirname);
  1271     {
  1268     if ((dlen > 0) && (dirname[dlen - 1] == '/')) /* ignore trailing slash. */
  1272         ZIPentry *entry = &info->entries[i];
  1269         dlen--;
  1273         const char *add_file;
  1270 
  1274         size_t strsize;
  1271     dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
  1275         char *slash;
  1272     max = (PHYSFS_sint32) info->entryCount;
  1276 
  1273     while (i < max)
  1277         if ((dlen > 0) && (strncmp(entry->name, dirname, dlen) != 0))
  1274     {
  1278             break; /* we're past this dir's entries. */
  1275         char *e = info->entries[i].name;
  1279 
  1276         if ((dlen) && ((strncmp(e, dirname, dlen) != 0) || (e[dlen] != '/')))
  1280         add_file = entry->name + dlen + ((dlen > 0) ? 1 : 0);
  1277             break;  /* past end of this dir; we're done. */
  1281         if ( ((omitSymLinks) && (zip_entry_is_symlink(entry))) ||
  1278 
  1282              (*add_file == '\0') ) /* skip links and the dir entry itself. */
  1279         if ((omitSymLinks) && (zip_entry_is_symlink(&info->entries[i])))
  1283         {
  1280             i++;
  1284             continue;
  1281         else
  1285         } /* if */
  1282         {
  1286 
  1283             char *add = e + dlen_inc;
  1287         slash = strchr(add_file, '/'); /* handle subdirs under dirname... */
  1284             char *ptr = strchr(add, '/');
  1288         strsize = (size_t) ((slash) ? (slash - add_file) : strlen(add_file));
  1285             PHYSFS_sint32 ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
  1289         retval = __PHYSFS_addToLinkedStringList(retval, &p, add_file, strsize);
  1286             retval = __PHYSFS_addToLinkedStringList(retval, &p, add, ln);
  1290 
  1287             ln += dlen_inc;  /* point past entry to children... */
  1291         tmp = i;
  1288 
  1292         /* We added a subdir? Skip its children. */
  1289             /* increment counter and skip children of subdirs... */
  1293         while ((slash != NULL) && (i < max))
  1290             while ((++i < max) && (ptr != NULL))
  1294         {
       
  1295             if (strncmp(info->entries[i].name, info->entries[tmp].name, dlen + strsize + 1) == 0)
       
  1296             {
  1291             {
  1297                 if (info->entries[i].name[dlen + strsize + 1] == '/')
  1292                 char *e_new = info->entries[i].name;
  1298                 {
  1293                 if ((strncmp(e, e_new, ln) == 0) && (e_new[ln] == '/'))
  1299                     i++;
       
  1300                     continue;
  1294                     continue;
  1301                 } /* if */
  1295                 ptr = NULL;
  1302             } /* if */
  1296             } /* while */
  1303             i--;  /* for loop will increment. */
  1297         } /* else */
  1304             slash = NULL;
       
  1305         } /* while */
       
  1306     } /* while */
  1298     } /* while */
  1307 
  1299 
  1308     return(retval);
  1300     return(retval);
  1309 #endif
       
  1310 } /* ZIP_enumerateFiles */
  1301 } /* ZIP_enumerateFiles */
  1311 
  1302 
  1312 
  1303 
  1313 static int ZIP_exists(DirHandle *h, const char *name)
  1304 static int ZIP_exists(DirHandle *h, const char *name)
  1314 {
  1305 {