Skip to content
Snippets Groups Projects
Commit e2d3cd89 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fixup extract_diz() - fallback to external archivers

The fallback to external extractors/archivers didn't really work unless a
libarchive function (called from extract_files_from_archive) actually failed
and the return value was < 0. A return value of 0 would mean the external
file extractor would never be used.

This was discovered when trying to import DIZ from old ZIP files (from 1992)
that used "Implode" compression method for the FILE_ID.DIZ, which is a
compression method *not* supported by libarchive. This is a reason why sysops
might want to leave Info-zip's 'unzip' as a configured Extractable File Type
handler (in SCFG) for 'zip' files.

Don't call the external archiver 3 times for the 3 DIZ filenames supported.
Just call the external archiver once, and pass all 3 filesnames. This also
means that the call to system() can return non-zero (e.g. Info-zip 'unzip'
will return 2 if any of the files aren't present in the archive, even if
one is) - so ignore this return value from system(). This speeds up bulk
import (e.g. using addfiles.js).

Unfortunately, I couldn't really find a nice cross-platform way to suppress
the unzip "caution: filename not matched" message sent to stderr. That's
a bummer and a little annoying.

Ignore 0-length DIZ files.
parent dd2afc92
Branches
Tags
1 merge request!455Update branch with changes from master
Pipeline #6397 passed
......@@ -1064,14 +1064,12 @@ bool extract_diz(scfg_t* cfg, file_t* f, str_list_t diz_fnames, char* path, size
,/* max_files: */strListCount(diz_fnames)
,/* file_list: */diz_fnames
,/* recurse: */nested
,/* error: */NULL, 0) >= 0) {
,/* error: */NULL, 0) > 0) {
for(i = 0; diz_fnames[i] != NULL; i++) {
safe_snprintf(path, maxlen, "%s%s", cfg->temp_dir, diz_fnames[i]); // no slash
if(fexistcase(path))
if(fexistcase(path) && flength(path) > 0)
return true;
}
if(nested)
return false;
}
}
......@@ -1082,12 +1080,15 @@ bool extract_diz(scfg_t* cfg, file_t* f, str_list_t diz_fnames, char* path, size
return false;
fextr_t* fextr = cfg->fextr[i];
char cmd[512];
char files[512];
char cmd[1024];
strListCombine(diz_fnames, files, sizeof files, " ");
// system() might return non-zero and still succeed in extracting *one* of the DIZ files:
if(system(cmdstr(cfg, /* user: */NULL, fextr->cmd, archive, files, cmd, sizeof cmd)) != 0)
;
for(i = 0; diz_fnames[i] != NULL; i++) {
safe_snprintf(path, maxlen, "%s%s", cfg->temp_dir, diz_fnames[i]);
if(system(cmdstr(cfg, /* user: */NULL, fextr->cmd, archive, diz_fnames[i], cmd, sizeof(cmd))) != 0)
continue;
if(fexistcase(path))
if(fexistcase(path) && flength(path) > 0)
return true;
}
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment