Skip to content
Snippets Groups Projects
Commit 4daafc43 authored by rswindell's avatar rswindell
Browse files

Added new commands:

L (capital 'L'): Lock a message base
U (capital 'U'): Unlock a message base

These commands maybe used to insure that a message base is not modified while
being backed-up (but don't forget to unlock them when you're done!).

Also note: if you back up all the files (including *.lock), then the backed-up
message bases will also be locked and will need to be unlocked (i.e. *.lock
removed) before they may be used again if/when restored.
parent 06177f8e
Branches
Tags
No related merge requests found
......@@ -117,6 +117,8 @@ char *usage=
" 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"
" L = lock a msg base for exclusive-access/backup\n"
" U = unlock a msg base\n"
"opts:\n"
" -c[m] = create message base if it doesn't exist (m=max msgs)\n"
" -a = always pack msg base (disable compression analysis)\n"
......@@ -1678,26 +1680,28 @@ int main(int argc, char **argv)
fprintf(errfp,"\n%s doesn't exist (use -c to create)\n",path);
bail(1);
}
smb.retry_time=30;
fprintf(statfp,"Opening %s\r\n",smb.file);
if((i=smb_open(&smb))!=0) {
fprintf(errfp,"\n%s!Error %d (%s) opening %s message base\n"
,beep,i,smb.last_error,smb.file);
continue;
}
if(!filelength(fileno(smb.shd_fp))) {
if(!create) {
printf("Empty\n");
smb_close(&smb);
if(cmd[0] != 'U') {
smb.retry_time=30;
fprintf(statfp,"Opening %s\r\n",smb.file);
if((i=smb_open(&smb))!=0) {
fprintf(errfp,"\n%s!Error %d (%s) opening %s message base\n"
,beep,i,smb.last_error,smb.file);
continue;
}
smb.status.max_msgs=max_msgs;
smb.status.max_crcs=count;
if((i=smb_create(&smb))!=0) {
smb_close(&smb);
printf("!Error %d (%s) creating %s\n",i,smb.last_error,smb.file);
continue;
}
if(!filelength(fileno(smb.shd_fp))) {
if(!create) {
printf("Empty\n");
smb_close(&smb);
continue;
}
smb.status.max_msgs=max_msgs;
smb.status.max_crcs=count;
if((i=smb_create(&smb))!=0) {
smb_close(&smb);
printf("!Error %d (%s) creating %s\n",i,smb.last_error,smb.file);
continue;
}
}
}
for(y=0;cmd[y];y++)
switch(cmd[y]) {
......@@ -1741,11 +1745,15 @@ int main(int argc, char **argv)
break;
case 'p':
case 'd':
case 'L':
if((i=smb_lock(&smb))!=0) {
fprintf(errfp,"\n%s!smb_lock returned %d: %s\n"
,beep,i,smb.last_error);
return(i);
}
printf("%s locked successfully\n", smb.file);
if(cmd[y] == 'L') // Lock base
break;
switch(toupper(cmd[y])) {
case 'P':
packmsgs(atol(cmd+y+1));
......@@ -1754,8 +1762,13 @@ int main(int argc, char **argv)
delmsgs();
break;
}
smb_unlock(&smb);
y=strlen(cmd)-1;
/* fall-through */
case 'U': // Unlock base
if((i=smb_unlock(&smb)) == SMB_SUCCESS)
printf("%s unlocked successfully\n", smb.file);
else
fprintf(errfp, "\nError %d (%s) unlocking %s\n", i, smb.last_error, smb.file);
break;
case 'r':
readmsgs(atol(cmd+1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment