Fixed behavior when Flush to temp file succeeds but original archive file

can't be removed.

Added two entries to kNuAttr* table.
This commit is contained in:
Andy McFadden 2004-09-20 23:13:28 +00:00
parent 1b1bafb12b
commit 1ba9153d5c
4 changed files with 30 additions and 5 deletions

View File

@ -1,3 +1,14 @@
2004/09/20 fadden
- Corrected behavior after flush when original archive can't be
deleted.
2004/09/09 fadden
- Added header offset and junk offset to NuGetAttr.
2004/08/22 fadden
- Fixed obscure bug when recompressing a GSHK-added zero-length file
when "fake threads" is enabled.
2004/03/10 ***** v2.0.2 shipped *****
2004/03/09 fadden

View File

@ -2407,11 +2407,10 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
*/
if (writeToTemp) {
canAbort = false; /* no going back */
fclose(pArchive->tmpFp);
pArchive->tmpFp = nil;
*pStatusFlags |= kNuFlushSucceeded; /* temp file is fully valid */
fclose(pArchive->archiveFp);
pArchive->archiveFp = nil;
*pStatusFlags |= kNuFlushSucceeded;
err = Nu_DeleteArchiveFile(pArchive);
if (err != kNuErrNone) {
@ -2419,9 +2418,12 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
Nu_ReportError(NU_BLOB, kNuErrNone, "New data is in '%s'",
pArchive->tmpPathname);
*pStatusFlags |= kNuFlushInaccessible;
goto bail;
goto bail_reopen; /* must re-open archiveFp */
}
fclose(pArchive->tmpFp);
pArchive->tmpFp = nil;
err = Nu_RenameTempToArchive(pArchive);
if (err != kNuErrNone) {
Nu_ReportError(NU_BLOB, err, "unable to rename temp file");
@ -2436,6 +2438,7 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
goto bail;
}
bail_reopen:
pArchive->archiveFp = fopen(pArchive->archivePathname,
kNuFileOpenReadWrite);
if (pArchive->archiveFp == nil) {
@ -2446,6 +2449,9 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
*pStatusFlags |= kNuFlushInaccessible;
goto bail; /* the Entry.c funcs will obstruct further use */
}
if (err != kNuErrNone) // earlier failure?
goto bail;
} else {
fflush(pArchive->archiveFp);
if (ferror(pArchive->archiveFp)) {

View File

@ -316,7 +316,9 @@ enum NuValueValue {
typedef enum NuAttrID {
kNuAttrInvalid = 0,
kNuAttrArchiveType = 1,
kNuAttrNumRecords = 2
kNuAttrNumRecords = 2,
kNuAttrHeaderOffset = 3,
kNuAttrJunkOffset = 4,
} NuAttrID;
typedef unsigned long NuAttr;

View File

@ -217,6 +217,12 @@ Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr)
case kNuAttrNumRecords:
*pAttr = pArchive->masterHeader.mhTotalRecords;
break;
case kNuAttrHeaderOffset:
*pAttr = pArchive->headerOffset;
break;
case kNuAttrJunkOffset:
*pAttr = pArchive->junkOffset;
break;
default:
err = kNuErrInvalidArg;
Nu_ReportError(NU_BLOB, err, "Unknown AttrID %d requested", ident);