Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/extract.c view on Meta::CPAN
/* Function find_compr_idx() */
/*******************************/
unsigned find_compr_idx(compr_methodnum)
unsigned compr_methodnum;
{
unsigned i;
for (i = 0; i < NUM_METHODS; i++) {
if (ComprIDs[i] == compr_methodnum) break;
}
return i;
}
#endif /* !SFX */
/******************************************/
/* Function extract_or_test_entrylist() */
/******************************************/
static int extract_or_test_entrylist(__G__ numchunk,
pfilnum, pnum_bad_pwd, pold_extra_bytes,
#ifdef SET_DIR_ATTRIB
pnum_dirs, pdirlist,
#endif
error_in_archive) /* return PK-type error code */
__GDEF
unsigned numchunk;
ulg *pfilnum;
ulg *pnum_bad_pwd;
zoff_t *pold_extra_bytes;
#ifdef SET_DIR_ATTRIB
unsigned *pnum_dirs;
direntry **pdirlist;
#endif
int error_in_archive;
{
unsigned i;
int renamed, query;
int skip_entry;
zoff_t bufstart, inbuf_offset, request;
int error, errcode;
/* possible values for local skip_entry flag: */
#define SKIP_NO 0 /* do not skip this entry */
#define SKIP_Y_EXISTING 1 /* skip this entry, do not overwrite file */
#define SKIP_Y_NONEXIST 2 /* skip this entry, do not create new file */
/*-----------------------------------------------------------------------
Second loop: process files in current block, extracting or testing
each one.
-----------------------------------------------------------------------*/
for (i = 0; i < numchunk; ++i) {
(*pfilnum)++; /* *pfilnum = i + blknum*DIR_BLKSIZ + 1; */
G.pInfo = &G.info[i];
#ifdef NOVELL_BUG_FAILSAFE
G.dne = FALSE; /* assume file exists until stat() says otherwise */
#endif
/* if the target position is not within the current input buffer
* (either haven't yet read far enough, or (maybe) skipping back-
* ward), skip to the target position and reset readbuf(). */
/* seek_zipf(__G__ pInfo->offset); */
request = G.pInfo->offset + G.extra_bytes;
inbuf_offset = request % INBUFSIZ;
bufstart = request - inbuf_offset;
Trace((stderr, "\ndebug: request = %ld, inbuf_offset = %ld\n",
(long)request, (long)inbuf_offset));
Trace((stderr,
"debug: bufstart = %ld, cur_zipfile_bufstart = %ld\n",
(long)bufstart, (long)G.cur_zipfile_bufstart));
if (request < 0) {
Info(slide, 0x401, ((char *)slide, LoadFarStringSmall(SeekMsg),
G.zipfn, LoadFarString(ReportMsg)));
error_in_archive = PK_ERR;
if (*pfilnum == 1 && G.extra_bytes != 0L) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(AttemptRecompensate)));
*pold_extra_bytes = G.extra_bytes;
G.extra_bytes = 0L;
request = G.pInfo->offset; /* could also check if != 0 */
inbuf_offset = request % INBUFSIZ;
bufstart = request - inbuf_offset;
Trace((stderr, "debug: request = %ld, inbuf_offset = %ld\n",
(long)request, (long)inbuf_offset));
Trace((stderr,
"debug: bufstart = %ld, cur_zipfile_bufstart = %ld\n",
(long)bufstart, (long)G.cur_zipfile_bufstart));
/* try again */
if (request < 0) {
Trace((stderr,
"debug: recompensated request still < 0\n"));
Info(slide, 0x401, ((char *)slide,
LoadFarStringSmall(SeekMsg),
G.zipfn, LoadFarString(ReportMsg)));
error_in_archive = PK_BADERR;
continue;
}
} else {
error_in_archive = PK_BADERR;
continue; /* this one hosed; try next */
}
}
if (bufstart != G.cur_zipfile_bufstart) {
Trace((stderr, "debug: bufstart != cur_zipfile_bufstart\n"));
#ifdef USE_STRM_INPUT
zfseeko(G.zipfd, bufstart, SEEK_SET);
G.cur_zipfile_bufstart = zftello(G.zipfd);
#else /* !USE_STRM_INPUT */
G.cur_zipfile_bufstart =
zlseek(G.zipfd, bufstart, SEEK_SET);
#endif /* ?USE_STRM_INPUT */
if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
{
unzip-6.0/extract.c view on Meta::CPAN
*(p-1) = *p;
} while (*p++ != '\0');
} while (G.filename[0] == '/');
}
}
/* mapname can create dirs if not freshening or if renamed */
error = mapname(__G__ renamed);
if ((errcode = error & ~MPN_MASK) != PK_OK &&
error_in_archive < errcode)
error_in_archive = errcode;
if ((errcode = error & MPN_MASK) > MPN_INF_TRUNC) {
if (errcode == MPN_CREATED_DIR) {
#ifdef SET_DIR_ATTRIB
direntry *d_entry;
error = defer_dir_attribs(__G__ &d_entry);
if (d_entry == (direntry *)NULL) {
/* There may be no dir_attribs info available, or
* we have encountered a mem allocation error.
* In case of an error, report it and set program
* error state to warning level.
*/
if (error) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(DirlistEntryNoMem)));
if (!error_in_archive)
error_in_archive = PK_WARN;
}
} else {
d_entry->next = (*pdirlist);
(*pdirlist) = d_entry;
++(*pnum_dirs);
}
#endif /* SET_DIR_ATTRIB */
} else if (errcode == MPN_VOL_LABEL) {
#ifdef DOS_OS2_W32
Info(slide, 0x401, ((char *)slide,
LoadFarString(SkipVolumeLabel),
FnFilter1(G.filename),
uO.volflag? "hard disk " : ""));
#else
Info(slide, 1, ((char *)slide,
LoadFarString(SkipVolumeLabel),
FnFilter1(G.filename), ""));
#endif
} else if (errcode > MPN_INF_SKIP &&
error_in_archive < PK_ERR)
error_in_archive = PK_ERR;
Trace((stderr, "mapname(%s) returns error code = %d\n",
FnFilter1(G.filename), error));
continue; /* go on to next file */
}
#ifdef QDOS
QFilename(__G__ G.filename);
#endif
switch (check_for_newer(__G__ G.filename)) {
case DOES_NOT_EXIST:
#ifdef NOVELL_BUG_FAILSAFE
G.dne = TRUE; /* stat() says file DOES NOT EXIST */
#endif
/* freshen (no new files): skip unless just renamed */
if (uO.fflag && !renamed)
skip_entry = SKIP_Y_NONEXIST;
break;
case EXISTS_AND_OLDER:
#ifdef UNIXBACKUP
if (!uO.B_flag)
#endif
{
if (IS_OVERWRT_NONE)
/* never overwrite: skip file */
skip_entry = SKIP_Y_EXISTING;
else if (!IS_OVERWRT_ALL)
query = TRUE;
}
break;
case EXISTS_AND_NEWER: /* (or equal) */
#ifdef UNIXBACKUP
if ((!uO.B_flag && IS_OVERWRT_NONE) ||
#else
if (IS_OVERWRT_NONE ||
#endif
(uO.uflag && !renamed)) {
/* skip if update/freshen & orig name */
skip_entry = SKIP_Y_EXISTING;
} else {
#ifdef UNIXBACKUP
if (!IS_OVERWRT_ALL && !uO.B_flag)
#else
if (!IS_OVERWRT_ALL)
#endif
query = TRUE;
}
break;
}
#ifdef VMS
/* 2008-07-24 SMS.
* On VMS, if the file name includes a version number,
* and "-V" ("retain VMS version numbers", V_flag) is in
* effect, then the VMS-specific code will handle any
* conflicts with an existing file, making this query
* redundant. (Implicit "y" response here.)
*/
if (query && uO.V_flag) {
/* Not discarding file versions. Look for one. */
int cndx = strlen(G.filename) - 1;
while ((cndx > 0) && (isdigit(G.filename[cndx])))
cndx--;
if (G.filename[cndx] == ';')
/* File version found; skip the generic query,
* proceeding with its default response "y".
*/
query = FALSE;
}
#endif /* VMS */
if (query) {
#ifdef WINDLL
switch (G.lpUserFunctions->replace != NULL ?
( run in 0.890 second using v1.01-cache-2.11-cpan-e93a5daba3e )