Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 77027966 authored by rswindell's avatar rswindell

Created the "smbutil d" command to delete all msgs in a msgbase (without

effecting message numbering, pointer files, etc.).
parent 2d155112
......@@ -35,7 +35,7 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#define SMBUTIL_VER "2.32"
#define SMBUTIL_VER "2.33"
char revision[16];
char compiler[32];
......@@ -76,6 +76,8 @@ char compiler[32];
/* gets is dangerous */
#define gets(str) fgets((str), sizeof(str), stdin)
#define CHSIZE_FP(fp,size) if(chsize(fileno(fp),size)) printf("chsize failed!\n");
/********************/
/* Global variables */
/********************/
......@@ -100,6 +102,7 @@ char *usage=
" n[f] = import netmail from text file f (or use stdin)\n"
" s = display msg base status\n"
" c = change msg base status\n"
" d = delete all msgs\n"
" m = maintain msg base - delete old msgs and msgs over max\n"
" p[k] = pack msg base (k specifies minimum packable Kbytes)\n"
"opts:\n"
......@@ -821,8 +824,7 @@ void maint(void)
printf("Re-writing index...\n");
rewind(smb.sid_fp);
if(chsize(fileno(smb.sid_fp),0L))
printf("chsize failed!\n");
CHSIZE_FP(smb.sid_fp,0);
for(m=n=0;m<l;m++) {
if(idx[m].attr&MSG_DELETE)
continue;
......@@ -890,16 +892,16 @@ void packmsgs(ulong packable)
if(!smb.status.total_msgs) {
printf("Empty\n");
rewind(smb.shd_fp);
chsize(fileno(smb.shd_fp),smb.status.header_offset);
CHSIZE_FP(smb.shd_fp,smb.status.header_offset);
rewind(smb.sdt_fp);
chsize(fileno(smb.sdt_fp),0L);
CHSIZE_FP(smb.sdt_fp,0);
rewind(smb.sid_fp);
chsize(fileno(smb.sid_fp),0L);
CHSIZE_FP(smb.sid_fp,0);
if(!(smb.status.attr&SMB_HYPERALLOC)) {
rewind(smb.sha_fp);
chsize(fileno(smb.sha_fp),0L);
CHSIZE_FP(smb.sha_fp,0);
rewind(smb.sda_fp);
chsize(fileno(smb.sda_fp),0L);
CHSIZE_FP(smb.sda_fp,0);
smb_close_ha(&smb);
smb_close_da(&smb);
}
......@@ -960,9 +962,9 @@ void packmsgs(ulong packable)
if(!(smb.status.attr&SMB_HYPERALLOC)) {
rewind(smb.sha_fp);
chsize(fileno(smb.sha_fp),0L); /* Reset both allocation tables */
CHSIZE_FP(smb.sha_fp,0); /* Reset both allocation tables */
rewind(smb.sda_fp);
chsize(fileno(smb.sda_fp),0L);
CHSIZE_FP(smb.sda_fp,0);
}
if(smb.status.attr&SMB_HYPERALLOC && !(mode&NOANALYSIS)) {
......@@ -1242,6 +1244,54 @@ void packmsgs(ulong packable)
printf("\nDone.\n\n");
}
void delmsgs(void)
{
int i;
printf("Deleting %s\n",smb.file);
i=smb_locksmbhdr(&smb);
if(i) {
fprintf(stderr,"\n\7!smb_locksmbhdr returned %d: %s\n",i,smb.last_error);
return;
}
i=smb_getstatus(&smb);
if(i) {
smb_unlocksmbhdr(&smb);
fprintf(stderr,"\n\7!smb_getstatus returned %d: %s\n",i,smb.last_error);
return;
}
if(!(smb.status.attr&SMB_HYPERALLOC)) {
i=smb_open_da(&smb);
if(i) {
smb_unlocksmbhdr(&smb);
fprintf(stderr,"\n\7!smb_open_da returned %d: %s\n",i,smb.last_error);
exit(1);
}
i=smb_open_ha(&smb);
if(i) {
smb_unlocksmbhdr(&smb);
fprintf(stderr,"\n\7!smb_open_ha returned %d: %s\n",i,smb.last_error);
exit(1);
}
/* Reset both allocation tables */
CHSIZE_FP(smb.sha_fp,0);
CHSIZE_FP(smb.sda_fp,0);
smb_close_ha(&smb);
smb_close_da(&smb);
}
CHSIZE_FP(smb.sid_fp,0);
CHSIZE_FP(smb.shd_fp,smb.status.header_offset);
CHSIZE_FP(smb.sdt_fp,0);
/* re-write status header */
smb.status.total_msgs=0;
if((i=smb_putstatus(&smb))!=0)
fprintf(stderr,"\n\7!smb_putstatus returned %d: %s\n",i,smb.last_error);
smb_unlocksmbhdr(&smb);
printf("\nDone.\n\n");
}
/****************************************************************************/
/* Read messages in message base */
......@@ -1566,11 +1616,19 @@ int main(int argc, char **argv)
y=strlen(cmd)-1;
break;
case 'P':
case 'D':
if((i=smb_lock(&smb))!=0) {
fprintf(stderr,"\n\7!smb_lock returned %d: %s\n",i,smb.last_error);
return(i);
}
packmsgs(atol(cmd+y+1));
switch(toupper(cmd[y])) {
case 'P':
packmsgs(atol(cmd+y+1));
break;
case 'D':
delmsgs();
break;
}
smb_unlock(&smb);
y=strlen(cmd)-1;
break;
......
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