mirror of
https://github.com/fadden/nulib2.git
synced 2025-03-05 16:30:07 +00:00
Remove the trailing ".QQ" from squeezed files before extracting.
Fail if the user tries to extract comments from a Binary II archive (with the "-c flag).
This commit is contained in:
parent
550ff22758
commit
21c4d9027a
103
nulib2/Binary2.c
103
nulib2/Binary2.c
@ -1114,43 +1114,19 @@ BNYListDebug(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* quick enum to simplify our lives a bit */
|
||||
typedef enum { kBNYExtNormal, kBNYExtPipe, kBNYExtTest } ExtMode;
|
||||
|
||||
/*
|
||||
* Handle "extract", "extract to pipe", and "test".
|
||||
* Handle "extraction" of a directory.
|
||||
*/
|
||||
static NuError
|
||||
BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
BNYExtractDirectory(BNYArchive* pBny, BNYEntry* pEntry, ExtMode extMode)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NulibState* pState;
|
||||
enum { kBNYExtNormal, kBNYExtPipe, kBNYExtTest } extMode;
|
||||
const char* actionStr = "HOSED";
|
||||
FILE* outfp = nil;
|
||||
Boolean eolConv;
|
||||
|
||||
pState = pBny->pState;
|
||||
|
||||
switch (NState_GetCommand(pState)) {
|
||||
case kCommandExtract: extMode = kBNYExtNormal; break;
|
||||
case kCommandExtractToPipe: extMode = kBNYExtPipe; break;
|
||||
case kCommandTest: extMode = kBNYExtTest; break;
|
||||
default:
|
||||
err = kNuErrInternal;
|
||||
ReportError(err, "unexpected command %d in BNYExtract",
|
||||
NState_GetCommand(pState));
|
||||
Assert(0);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*eolConv = NState_GetModConvertAll(pState);*/
|
||||
eolConv = false;
|
||||
|
||||
/*
|
||||
* Binary II requires that all directories be listed explicitly.
|
||||
* If we see one, create it.
|
||||
*/
|
||||
if (IsDir(pEntry)) {
|
||||
const char* newName;
|
||||
Boolean isDir;
|
||||
const char* actionStr = "HOSED";
|
||||
|
||||
if (extMode == kBNYExtTest) {
|
||||
actionStr = "skipping ";
|
||||
@ -1193,9 +1169,51 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
}
|
||||
}
|
||||
|
||||
if (!NState_GetSuppressOutput(pState)) {
|
||||
if (!NState_GetSuppressOutput(pBny->pState)) {
|
||||
printf("\rDONE %s %s (directory)\n", actionStr, pEntry->fileName);
|
||||
}
|
||||
|
||||
bail:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle "extract", "extract to pipe", and "test".
|
||||
*/
|
||||
static NuError
|
||||
BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NulibState* pState;
|
||||
ExtMode extMode;
|
||||
const char* actionStr = "HOSED";
|
||||
FILE* outfp = nil;
|
||||
Boolean eolConv;
|
||||
|
||||
pState = pBny->pState;
|
||||
|
||||
switch (NState_GetCommand(pState)) {
|
||||
case kCommandExtract: extMode = kBNYExtNormal; break;
|
||||
case kCommandExtractToPipe: extMode = kBNYExtPipe; break;
|
||||
case kCommandTest: extMode = kBNYExtTest; break;
|
||||
default:
|
||||
err = kNuErrInternal;
|
||||
ReportError(err, "unexpected command %d in BNYExtract",
|
||||
NState_GetCommand(pState));
|
||||
Assert(0);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*eolConv = NState_GetModConvertAll(pState);*/
|
||||
eolConv = false; /* maybe someday */
|
||||
|
||||
/*
|
||||
* Binary II requires that all directories be listed explicitly.
|
||||
* If we see one, create it.
|
||||
*/
|
||||
if (IsDir(pEntry)) {
|
||||
err = BNYExtractDirectory(pBny, pEntry, extMode);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
@ -1216,6 +1234,17 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
*/
|
||||
const char* newName;
|
||||
Boolean isDir;
|
||||
char* ext;
|
||||
|
||||
/* if we find .qq on a squeezed file, just stomp the copy in pEntry */
|
||||
if (strlen(pEntry->fileName) > 3) {
|
||||
ext = pEntry->fileName + strlen(pEntry->fileName) -3;
|
||||
if (IsSqueezed(pEntry->blockBuf[0], pEntry->blockBuf[1]) &&
|
||||
strcasecmp(ext, ".qq") == 0)
|
||||
{
|
||||
*ext = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
newName = BNYNormalizePath(pBny, pEntry);
|
||||
if (newName == nil)
|
||||
@ -1239,6 +1268,9 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
} else if (err != kNuErrFileNotFound) {
|
||||
ReportError(err, "stat failed on '%s'", newName);
|
||||
goto bail;
|
||||
} else {
|
||||
Assert(err == kNuErrFileNotFound);
|
||||
err = kNuErrNone;
|
||||
}
|
||||
|
||||
/* open it, overwriting anything present */
|
||||
@ -1271,7 +1303,7 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
||||
* Extract the file. Send the output, perhaps with EOL conversion,
|
||||
* to the output file.
|
||||
*
|
||||
* Thought for the day: assuming a file is Squeezed just based on
|
||||
* Thought for the day: assuming a file is Squeezed based only on
|
||||
* the magic number is bogus. If we get certain classes of failures,
|
||||
* and this isn't a streaming archive, we should back up and just
|
||||
* extract it as a plain file.
|
||||
@ -1329,6 +1361,13 @@ BNYDoExtract(NulibState* pState)
|
||||
gProgName);
|
||||
return kNuErrSyntax;
|
||||
}
|
||||
if (NState_GetModComments(pState))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: Binary II extraction doesn't support '-c'\n",
|
||||
gProgName);
|
||||
return kNuErrSyntax;
|
||||
}
|
||||
|
||||
if (NState_GetCommand(pState) == kCommandExtractToPipe)
|
||||
NState_SetSuppressOutput(pState, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user