If the filesystem where the scan file resides got full while the scanner is

running, you can end up with an incomplete scan file because there was no
error checking done. Then sup will happily delete all the files that are
missing from the scan file. Make sure we have written a good scan file before
renaming.
This commit is contained in:
christos 2007-12-20 20:15:59 +00:00
parent 55dfe21e44
commit d5abced1d5
1 changed files with 26 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: scan.c,v 1.25 2007/10/07 05:25:19 taca Exp $ */ /* $NetBSD: scan.c,v 1.26 2007/12/20 20:15:59 christos Exp $ */
/* /*
* Copyright (c) 1992 Carnegie Mellon University * Copyright (c) 1992 Carnegie Mellon University
@ -83,8 +83,6 @@
********************************************************************** **********************************************************************
*/ */
#include "libc.h"
#include "c.h"
#ifdef HAS_VIS #ifdef HAS_VIS
#include <vis.h> #include <vis.h>
#endif #endif
@ -102,6 +100,8 @@
#include <unistd.h> #include <unistd.h>
#include "supcdefs.h" #include "supcdefs.h"
#include "supextern.h" #include "supextern.h"
#include "libc.h"
#include "c.h"
/************************* /*************************
*** M A C R O S *** *** M A C R O S ***
@ -966,18 +966,25 @@ makescanfile(char *scanfile)
(void) sprintf(tname, "%s.temp", fname); (void) sprintf(tname, "%s.temp", fname);
scanF = fopen(tname, "w"); scanF = fopen(tname, "w");
if (scanF == NULL) if (scanF == NULL)
goaway("Can't write scan file temp %s for %s", tname, collname); goto out;
fprintf(scanF, "V%d\n", SCANVERSION); if (fprintf(scanF, "V%d\n", SCANVERSION) < 0)
(void) Tprocess(listT, recordone, scanF); goto out;
(void) fclose(scanF); if (Tprocess(listT, recordone, scanF) != SCMOK)
if (rename(tname, fname) < 0) goto out;
goaway("Can't change %s to %s", tname, fname); if (fclose(scanF) != 0)
goto out;
if (rename(tname, fname) < 0) {
(void)unlink(tname); (void)unlink(tname);
goaway("Can't change %s to %s", tname, fname);
}
tbuf[0].tv_sec = time((time_t *) NULL); tbuf[0].tv_sec = time((time_t *) NULL);
tbuf[0].tv_usec = 0; tbuf[0].tv_usec = 0;
tbuf[1].tv_sec = scantime; tbuf[1].tv_sec = scantime;
tbuf[1].tv_usec = 0; tbuf[1].tv_usec = 0;
(void) utimes(fname, tbuf); (void) utimes(fname, tbuf);
return;
out:
goaway("Can't write scan file temp %s for %s", tname, collname);
} }
static int static int
@ -992,13 +999,15 @@ recordone(TREE * t, void *v)
#endif #endif
if (t->Tflags & FBACKUP) if (t->Tflags & FBACKUP)
fprintf(scanF, "B"); if (fprintf(scanF, "B") < 0)
return SCMERR;
if (t->Tflags & FNOACCT) if (t->Tflags & FNOACCT)
fprintf(scanF, "N"); if (fprintf(scanF, "N") < 0)
fprintf(scanF, "%o %d %d %s\n", return SCMERR;
t->Tmode, t->Tctime, t->Tmtime, fname); if (fprintf(scanF, "%o %d %d %s\n",
(void) Tprocess(t->Texec, recordexec, scanF); t->Tmode, t->Tctime, t->Tmtime, fname) < 0)
return (SCMOK); return SCMERR;
return Tprocess(t->Texec, recordexec, scanF);
} }
static int static int
@ -1011,7 +1020,8 @@ recordexec(TREE * t, void *v)
#else #else
char *fname = t->Tname; char *fname = t->Tname;
#endif #endif
fprintf(scanF, "X%s\n", fname); if (fprintf(scanF, "X%s\n", fname) < 0)
return SCMERR;
return (SCMOK); return (SCMOK);
} }