示例#1
0
/*
 * ab - abort current changes
 */
static NuError AbortFunc(ExerciserState* pState, int argc, char** argv)
{
    (void) pState, (void) argc, (void) argv;    /* shut up, gcc */
    assert(ExerciserState_GetNuArchive(pState) != NULL);
    assert(argc == 1);

    return NuAbort(ExerciserState_GetNuArchive(pState));
}
示例#2
0
void ExerciserState_Free(ExerciserState* pExerState)
{
    if (pExerState == NULL)
        return;

    if (pExerState->pArchive != NULL) {
        printf("Exerciser: aborting open archive\n");
        (void) NuAbort(pExerState->pArchive);
        (void) NuClose(pExerState->pArchive);
    }
    if (pExerState->archivePath != NULL)
        free(pExerState->archivePath);

    free(pExerState);
}
示例#3
0
/*
 * Interpret commands, do clever things.
 */
static NuError
CommandLoop(void)
{
    NuError err = kNuErrNone;
    ExerciserState* pState = ExerciserState_New();
    CommandFunc func;
    char lineBuf[128];
    int argc;
    char** argv = nil;

    while (1) {
        printf("\nEnter command (%s)> ", ExerciserState_GetArchiveFile(pState));
        fflush(stdout);

        if (fgets(lineBuf, sizeof(lineBuf), stdin) == nil) {
            printf("\n");
            break;
        }

        if (argv != nil) {
            free(argv);
            argv = nil;
        }

        func = nil; /* sanity check */

        err = ParseLine(lineBuf, pState, &func, &argc, &argv);
        if (err != kNuErrNone)
            continue;

        assert(func != nil);
        if (func == QuitFunc)
            break;

        err = (*func)(pState, argc, argv);

        if (err < 0)
            printf("Exerciser: received error %d (%s)\n", err, NuStrError(err));
        else if (err > 0)
            printf("Exerciser: received error %d\n", err);

        if (argv != nil) {
            free(argv);
            argv = nil;
        }
    }

    if (ExerciserState_GetNuArchive(pState) != nil) {
        /* ought to query the archive before saying something like this... */
        printf("Exerciser: aborting any un-flushed changes in archive %s\n",
            ExerciserState_GetArchivePath(pState));
        (void) NuAbort(ExerciserState_GetNuArchive(pState));
        err = NuClose(ExerciserState_GetNuArchive(pState));
        if (err != kNuErrNone)
            printf("Exerciser: got error %d closing archive\n", err);
        ExerciserState_SetNuArchive(pState, nil);
    }

    if (pState != nil)
        ExerciserState_Free(pState);
    if (argv != nil)
        free(argv);
    return kNuErrNone;
}
示例#4
0
文件: ArcUtils.c 项目: iKarith/nulib2
/*
 * Open the archive in read-write mode, for purposes of adding, deleting,
 * or updating files.  We don't plan on extracting anything with this.
 *
 * "Streaming mode" isn't allowed.
 */
NuError OpenArchiveReadWrite(NulibState* pState)
{
    NuError err = kNuErrNone;
    NuArchive* pArchive = NULL;
    char* tempName = NULL;

    Assert(pState != NULL);
    Assert(IsFilenameStdin(NState_GetArchiveFilename(pState)) == false);

    tempName = MakeTempArchiveName(pState);
    if (tempName == NULL)
        goto bail;
    DBUG(("TEMP NAME = '%s'\n", tempName));

    err = NuOpenRW(NState_GetArchiveFilename(pState), tempName,
            kNuOpenCreat, &pArchive);
    if (err != kNuErrNone) {
        ReportError(err, "unable to open '%s'",
            NState_GetArchiveFilename(pState));
        goto bail;
    }

    /* introduce them */
    NState_SetNuArchive(pState, pArchive);
    err = NuSetExtraData(pArchive, pState);
    BailError(err);

    NuSetSelectionFilter(pArchive, SelectionFilter);
    NuSetProgressUpdater(pArchive, ProgressUpdater);
    NuSetErrorHandler(pArchive, ErrorHandler);
    /*NuSetErrorMessageHandler(pArchive, ErrorMessageHandler);*/

    /* handle "-0" flag */
    if (NState_GetModNoCompression(pState)) {
        err = NuSetValue(pArchive, kNuValueDataCompression, kNuCompressNone);
        BailError(err);
    }
    /* handle "-z" flag */
    if (NState_GetModCompressDeflate(pState)) {
        err = NuSetValue(pArchive, kNuValueDataCompression, kNuCompressDeflate);
        BailError(err);
    }
    /* handle "-zz" flag */
    if (NState_GetModCompressBzip2(pState)) {
        err = NuSetValue(pArchive, kNuValueDataCompression, kNuCompressBzip2);
        BailError(err);
    }

    /* handle "-f" and "-u" flags */
    /* (BUG: if "-f" is set, creating a new archive is impossible) */
    if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) {
        err = NuSetValue(pArchive, kNuValueOnlyUpdateOlder, true);
        BailError(err);
    }
    if (NState_GetModFreshen(pState)) {
        err = NuSetValue(pArchive, kNuValueHandleExisting, kNuMustOverwrite);
        BailError(err);
    }

    DBUG(("--- enabling ShrinkIt compatibility mode\n"));
    err = NuSetValue(pArchive, kNuValueMimicSHK, true);
    BailError(err);

    /* this probably isn't needed here, but set it anyway */
    if (strcmp(SYSTEM_DEFAULT_EOL, "\r") == 0)
        err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCR);
    else if (strcmp(SYSTEM_DEFAULT_EOL, "\n") == 0)
        err = NuSetValue(pArchive, kNuValueEOL, kNuEOLLF);
    else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0)
        err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF);
    else {
        Assert(0);
        err = kNuErrInternal;
        ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL);
        goto bail;
    }
    BailError(err);

    /*(void) NuSetValue(pArchive, kNuValueAllowDuplicates, true);*/

bail:
    Free(tempName);
    if (err != kNuErrNone && pArchive != NULL) {
        /* clean up */
        NuAbort(pArchive);
        (void) NuClose(pArchive);
        NState_SetNuArchive(pState, NULL);
    }
    return err;
}