Skip to content
Snippets Groups Projects
Commit 805c497d authored by rswindell's avatar rswindell
Browse files

maint(): don't truncate the .sid and .hash files to 0-bytes before writing their

new contents,
Instead truncate to the new length after writing the new contents. This should
make the files more tolerant of "out of disk space" situations and reduce
the risk of lost data (0-byte files) due to low/no free disk space.
parent e29085cb
No related branches found
No related tags found
No related merge requests found
......@@ -708,9 +708,10 @@ void maint(void)
hash_t* hashes = malloc(max_hashes * SMB_HASH_SOURCE_TYPES * sizeof(hash_t));
if(hashes != NULL) {
if(fread(hashes, sizeof(hash_t), max_hashes * SMB_HASH_SOURCE_TYPES, smb.hash_fp) == max_hashes * SMB_HASH_SOURCE_TYPES) {
CHSIZE_FP(smb.hash_fp,0);
rewind(smb.hash_fp);
fwrite(hashes, sizeof(hash_t), max_hashes * SMB_HASH_SOURCE_TYPES, smb.hash_fp);
fflush(smb.hash_fp);
CHSIZE_FP(smb.hash_fp, sizeof(hash_t) * max_hashes * SMB_HASH_SOURCE_TYPES);
}
free(hashes);
}
......@@ -860,15 +861,16 @@ void maint(void)
printf("Re-writing index...\n");
rewind(smb.sid_fp);
CHSIZE_FP(smb.sid_fp,0);
for(m=n=0;m<l;m++) {
if(idx[m].attr&MSG_DELETE)
continue;
printf("%lu of %lu\r",++n,l-flagged);
n++;
printf("%lu of %lu\r", n, l-flagged);
fwrite(&idx[m],sizeof(idxrec_t),1,smb.sid_fp);
}
printf("\nDone.\n\n");
fflush(smb.sid_fp);
CHSIZE_FP(smb.sid_fp, n * sizeof(idxrec_t));
printf("\nDone.\n\n");
free(idx);
smb.status.total_msgs-=flagged;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment