[iso] speed up scanning of ISOs with lots of deep directory entries

* ISOs with tons of Rock Ridge deep directory entries (such as OPNsense)
  can be very slow to scan due to the nature of deep directory parsing,
  which requires processing the whole ISO9660 fs, for each deep directory
  file, in order to find the relevant LSN entry.
* Since we don't expect much of the content we care about to reside in a
  deep directory entry, we amend the code to cut short the scan of any
  directory that contains such elements.
* Note that this only applies for ISO scan and it does nothing to speed
  up the ISO extraction process.
* Related to issue #1575
This commit is contained in:
Pete Batard 2020-07-06 17:30:20 +01:00
parent 500172a7a3
commit c35a92cd0c
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
2 changed files with 24 additions and 10 deletions

View file

@ -631,7 +631,7 @@ static void update_md5sum(void)
free(md5_data);
}
// Returns 0 on success, nonzero on error
// Returns 0 on success, >0 on error, <0 to ignore current dir
static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
{
HANDLE file_handle = NULL;
@ -668,9 +668,20 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
_CDIO_LIST_FOREACH(p_entnode, p_entlist) {
if (FormatStatus) goto out;
p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode);
if ((p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
if (p_statbuf->rr.u_su_fields & ISO_ROCK_SUF_PL)
if (scan_only && (p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
if (p_statbuf->rr.u_su_fields & ISO_ROCK_SUF_PL) {
img_report.has_deep_directories = TRUE;
// Due to the nature of the parsing of Rock Ridge deep directories
// which requires performing a *very costly* search of the whole
// ISO9660 file system to find the matching LSN, ISOs with loads of
// deep directory entries (e.g. OPNsense) are very slow to parse...
// To speed up the scan process, and since we expect deep directory
// entries to appear below anything we care for, we cut things
// short by telling the parent not to bother any further once we
// find that we are dealing with a deep directory.
r = -1;
goto out;
}
}
// Eliminate . and .. entries
if ( (strcmp(p_statbuf->filename, ".") == 0)
@ -702,15 +713,18 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
}
safe_free(psz_sanpath);
}
if (iso_extract_files(p_iso, psz_iso_name))
r = iso_extract_files(p_iso, psz_iso_name);
if (r > 0)
goto out;
if (r < 0) // Stop processing current dir
break;
} else {
file_length = p_statbuf->total_size;
if (check_iso_props(psz_path, file_length, psz_basename, psz_fullpath, &props)) {
continue;
}
print_extracted_file(psz_fullpath, file_length);
for (i=0; i<NB_OLD_C32; i++) {
for (i = 0; i < NB_OLD_C32; i++) {
if (props.is_old_c32[i] && use_own_c32[i]) {
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
if (CopyFileU(tmp, psz_fullpath, FALSE)) {