Commit 7cb132aa authored by rswindell's avatar rswindell
Browse files

Truncate *.hash files during maintenance to accomodate max-msgs or max-crcs

number of hash sets (don't let these files grow indefinitely).
parent 346549c2
......@@ -641,6 +641,34 @@ void maint(void)
,beep,i,smb.last_error);
return;
}
if(smb_open_hash(&smb) == SMB_SUCCESS)
{
ulong max_hashes=0;
printf("Maintaining %s hash file\r\n", smb.file);
if((smb.status.attr&(SMB_EMAIL|SMB_NOHASH)) == 0) {
max_hashes = smb.status.max_msgs;
if(smb.status.max_crcs > max_hashes)
max_hashes = smb.status.max_crcs;
}
if(!max_hashes) {
CHSIZE_FP(smb.hash_fp,0);
} else if(filelength(fileno(smb.hash_fp)) > (long)(max_hashes * SMB_HASH_SOURCE_TYPES * sizeof(hash_t))) {
if(fseek(smb.hash_fp, -((long)(max_hashes * SMB_HASH_SOURCE_TYPES * sizeof(hash_t))), SEEK_END) == 0) {
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);
}
free(hashes);
}
}
}
smb_close_hash(&smb);
}
if(!smb.status.total_msgs) {
smb_unlocksmbhdr(&smb);
printf("Empty\n");
......@@ -919,7 +947,7 @@ void packmsgs(ulong packable)
}
if(packable && (m*SDT_BLOCK_LEN)+(n*SHD_BLOCK_LEN)<packable*1024L) {
printf("\rLess than %luk compressible bytes.\n\n",packable);
printf("\r%lu less than %lu compressible bytes.\n\n",(m*SDT_BLOCK_LEN)+(n*SHD_BLOCK_LEN), packable*1024L);
smb_close_ha(&smb);
smb_close_da(&smb);
smb_unlocksmbhdr(&smb);
......@@ -974,7 +1002,7 @@ void packmsgs(ulong packable)
}
if(packable && (n*SDT_BLOCK_LEN)+(m*SHD_BLOCK_LEN)<packable*1024L) {
printf("\rLess than %luk compressible bytes.\n\n",packable);
printf("\r%lu less than %lu compressible bytes.\n\n",(n*SDT_BLOCK_LEN)+(m*SHD_BLOCK_LEN), packable*1024);
smb_unlocksmbhdr(&smb);
return;
}
......
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