nulib2/nulib2/Add.c

111 lines
2.7 KiB
C
Raw Normal View History

2000-05-23 01:55:31 +00:00
/*
* Nulib2
2007-02-19 23:11:55 +00:00
* Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved.
2000-05-23 01:55:31 +00:00
* This is free software; you can redistribute it and/or modify it under the
2007-02-19 23:11:55 +00:00
* terms of the BSD License, see the file COPYING.
2000-05-23 01:55:31 +00:00
*
* Add files to or update files in the archive.
*/
#include "Nulib2.h"
static NuError AddToArchive(NulibState* pState, NuArchive* pArchive);
/*
* Add the specified files to a new or existing archive.
*/
NuError DoAdd(NulibState* pState)
2000-05-23 01:55:31 +00:00
{
NuError err;
2014-12-22 02:17:23 +00:00
NuArchive* pArchive = NULL;
long flushStatus;
2000-05-23 01:55:31 +00:00
2014-12-22 02:17:23 +00:00
Assert(pState != NULL);
2000-05-23 01:55:31 +00:00
err = OpenArchiveReadWrite(pState);
if (err != kNuErrNone)
goto bail;
2000-05-23 01:55:31 +00:00
pArchive = NState_GetNuArchive(pState);
2014-12-22 02:17:23 +00:00
Assert(pArchive != NULL);
2000-05-23 01:55:31 +00:00
NState_SetMatchCount(pState, 0);
2000-05-23 01:55:31 +00:00
/* tell them about the list of files */
err = AddToArchive(pState, pArchive);
if (err != kNuErrNone)
goto bail;
2000-05-23 01:55:31 +00:00
/*(void)NuDebugDumpArchive(pArchive);*/
2000-05-23 01:55:31 +00:00
if (!NState_GetMatchCount(pState))
printf("%s: no records matched\n", gProgName);
2000-05-23 01:55:31 +00:00
bail:
2014-12-22 02:17:23 +00:00
if (pArchive != NULL) {
NuError err2;
#if 0
if (err != kNuErrNone) {
printf("Attempting to flush changes in spite of errors...\n");
err = kNuErrNone;
}
#endif
if (err == kNuErrNone) {
err = NuFlush(pArchive, &flushStatus);
if (err != kNuErrNone) {
if (flushStatus & kNuFlushSucceeded) {
ReportError(err,
"Changes were successfully written, but something "
"failed afterward");
} else {
ReportError(err,
"Unable to flush archive changes (status=0x%04lx)",
flushStatus);
}
NuAbort(pArchive);
}
} else {
NuAbort(pArchive);
}
err2 = NuClose(pArchive);
Assert(err2 == kNuErrNone);
}
return err;
2000-05-23 01:55:31 +00:00
}
/*
* Add the requested files to the specified archive.
*
* This just results in NuAddFile calls; the deferred write operation
* isn't initiated.
*/
static NuError AddToArchive(NulibState* pState, NuArchive* pArchive)
2000-05-23 01:55:31 +00:00
{
NuError err = kNuErrNone;
char* const* pSpec;
int i;
2000-05-23 01:55:31 +00:00
2014-12-22 02:17:23 +00:00
Assert(pState != NULL);
Assert(pArchive != NULL);
2000-05-23 01:55:31 +00:00
if (!NState_GetFilespecCount(pState)) {
err = kNuErrSyntax;
ReportError(err, "no files were specified");
}
2000-05-23 01:55:31 +00:00
pSpec = NState_GetFilespecPointer(pState);
for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) {
err = AddFile(pState, pArchive, *pSpec);
if (err != kNuErrNone)
goto bail;
}
2000-05-23 01:55:31 +00:00
bail:
return err;
2000-05-23 01:55:31 +00:00
}