Commit 3394ba4b authored by Per Cederqvist's avatar Per Cederqvist

When the file is lyskomd-data file has been saved, reopen it and check

that the lenght is correct.
parent b1553cbc
Tue Mar 24 18:05:18 1992 Per Cederqvist (ceder@robert)
* simple-cache.c (save_one_text): Check that the entire file made
it to the disk (compare wath ftell() says after fclose() and
fopen()).
Mon Mar 23 08:51:13 1992 Per Cederqvist (ceder@robin)
* dbck.c (truncated_texts): New variable.
......
/*
* $Id: simple-cache.c,v 0.20 1992/02/26 18:44:58 ceder Exp $
* $Id: simple-cache.c,v 0.21 1992/03/24 17:41:05 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +33,7 @@
* New save algorithm by ceder.
*/
static char *rcsid = "$Id: simple-cache.c,v 0.20 1992/02/26 18:44:58 ceder Exp $";
static char *rcsid = "$Id: simple-cache.c,v 0.21 1992/03/24 17:41:05 ceder Exp $";
......@@ -1506,6 +1506,8 @@ static void
save_one_text(void)
{
Cache_node *cn;
long offset;
long offset2;
if (sync_next < highest_text_no)
{
......@@ -1550,6 +1552,18 @@ save_one_text(void)
sync_state = sync_error;
return;
}
offset = ftell(file_b); /* Make sure that the entire file resides
on disk. This test seems to be necessary.
The data file has been corrupted at least
once. */
if (offset == -1)
{
log ("save_one_text(): ftell returned -1.\n");
sync_state = sync_error;
return;
}
rewind(file_b);
if ( ferror(file_b) != 0 )
......@@ -1560,6 +1574,7 @@ save_one_text(void)
}
fprintf(file_b, "CLEAN");
if ( ferror(file_b) != 0 )
{
log ("save_one_text(): fprintf(CLEAN) failed.\n");
......@@ -1567,6 +1582,20 @@ save_one_text(void)
return;
}
if (fflush(file_b) != 0)
{
log ("save_one_text(): fflush failed.\n");
sync_state = sync_error;
return;
}
if ( ferror(file_b) != 0 )
{
log ("save_one_text(): ferror after fflush failed.\n");
sync_state = sync_error;
return;
}
if ( fclose(file_b) != 0 )
{
file_b = NULL;
......@@ -1578,6 +1607,32 @@ save_one_text(void)
return;
}
file_b = fopen(datafilename, "rb");
if (file_b == NULL)
{
log("save_one_text(): failed to reopen file.\n");
remove (datafilename);
sync_state = sync_wait;
return;
}
if (fseek(file_b, 0, SEEK_END) != 0)
{
log("save_one_text(): fseek failed.\n");
sync_state = sync_error;
return;
}
offset2 = ftell (file_b);
if ( offset2 != offset )
{
log ("save_one_text(): ftell returns different offsets"
"(%l and %l).\n", offset, offset2);
sync_state = sync_error;
return;
}
fclose (file_b);
file_b = NULL;
sync_state = sync_ready;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment