Skip to content
Snippets Groups Projects
Commit 2e6d0a27 authored by rswindell's avatar rswindell
Browse files

Bug-fix: don't force timezone to UTC if the "use local timezone" option is

enabled in SCFG->System (the default is enabled).
Added copyright comment header block.
Fixed msvc6 warnings.
parent c006c9c8
No related branches found
No related tags found
No related merge requests found
#line 1 "delfiles.c" /* delfiles.c */
/* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ /* Program to delete expired files from a Synchronet file database */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "sbbs.h" #include "sbbs.h"
...@@ -18,7 +51,7 @@ char *crlf="\r\n"; ...@@ -18,7 +51,7 @@ char *crlf="\r\n";
void bail(int code) void bail(int code)
{ {
exit(code); exit(code);
} }
long lputs(char *str) long lputs(char *str)
...@@ -26,14 +59,14 @@ long lputs(char *str) ...@@ -26,14 +59,14 @@ long lputs(char *str)
char tmp[256]; char tmp[256];
int i,j,k; int i,j,k;
j=strlen(str); j=strlen(str);
for(i=k=0;i<j;i++) /* remove CRs */ for(i=k=0;i<j;i++) /* remove CRs */
if(str[i]==CR && str[i+1]==LF) if(str[i]==CR && str[i+1]==LF)
continue; continue;
else else
tmp[k++]=str[i]; tmp[k++]=str[i];
tmp[k]=0; tmp[k]=0;
return(fputs(tmp,stdout)); return(fputs(tmp,stdout));
} }
/****************************************************************************/ /****************************************************************************/
...@@ -46,18 +79,18 @@ int lprintf(char *fmat, ...) ...@@ -46,18 +79,18 @@ int lprintf(char *fmat, ...)
char sbuf[256]; char sbuf[256];
int chcount; int chcount;
va_start(argptr,fmat); va_start(argptr,fmat);
chcount=vsprintf(sbuf,fmat,argptr); chcount=vsprintf(sbuf,fmat,argptr);
va_end(argptr); va_end(argptr);
lputs(sbuf); lputs(sbuf);
return(chcount); return(chcount);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char str[256],fname[MAX_PATH+1],not[MAX_NOTS][9],nots=0,*p; char str[256],fname[MAX_PATH+1],not[MAX_NOTS][9],nots=0,*p;
int i,j,dirnum,libnum,file; int i,j,dirnum,libnum,file;
ulong l,m,n,length; ulong l,m;
long misc=0; long misc=0;
time_t now; time_t now;
file_t workfile; file_t workfile;
...@@ -65,199 +98,201 @@ int main(int argc, char **argv) ...@@ -65,199 +98,201 @@ int main(int argc, char **argv)
glob_t gl; glob_t gl;
uchar *ixbbuf; uchar *ixbbuf;
putenv("TZ=UCT0"); setvbuf(stdout,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0);
fprintf(stderr,"\nDELFILES Version %s (%s) - Removes files from Synchronet " fprintf(stderr,"\nDELFILES Version %s (%s) - Removes files from Synchronet "
"Filebase\n" ,DELFILES_VER, PLATFORM_DESC ); "Filebase\n" ,DELFILES_VER, PLATFORM_DESC );
if(argc<2) { if(argc<2) {
printf("\n usage: DELFILES <dir_code or * for ALL> [switches]\n"); printf("\n usage: DELFILES <dir_code or * for ALL> [switches]\n");
printf("\nswitches: /LIB name All directories of specified library\n"); printf("\nswitches: -LIB name All directories of specified library\n");
printf(" /NOT code Exclude specific directory\n"); printf(" -NOT code Exclude specific directory\n");
printf(" /OFF Remove files that are offline " printf(" -OFF Remove files that are offline "
"(don't exist on disk)\n"); "(don't exist on disk)\n");
printf(" /NOL Remove files with no link " printf(" -NOL Remove files with no link "
"(don't exist in database)\n"); "(don't exist in database)\n");
printf(" /RPT Report findings only " printf(" -RPT Report findings only "
"(don't delete any files)\n"); "(don't delete any files)\n");
return(0); } return(0); }
p=getenv("SBBSCTRL"); p=getenv("SBBSCTRL");
if(p==NULL) { if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n"); printf("\nSBBSCTRL environment variable not set.\n");
#ifdef __unix__ #ifdef __unix__
printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n"); printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else #else
printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n"); printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif #endif
return(1); } return(1); }
putenv("TZ=UCT0"); memset(&cfg, 0, sizeof(cfg));
cfg.size=sizeof(cfg);
SAFECOPY(cfg.ctrl_dir, p);
backslash(cfg.ctrl_dir);
memset(&cfg, 0, sizeof(cfg)); load_cfg(&cfg, NULL, TRUE, str);
cfg.size=sizeof(cfg); chdir(cfg.ctrl_dir);
SAFECOPY(cfg.ctrl_dir, p);
backslash(cfg.ctrl_dir);
load_cfg(&cfg, NULL, TRUE, str); if(!(cfg.sys_misc&SM_LOCAL_TZ))
chdir(cfg.ctrl_dir); putenv("TZ=UTC0");
dirnum=libnum=-1; dirnum=libnum=-1;
if(argv[1][0]=='*') if(argv[1][0]=='*')
misc|=ALL; misc|=ALL;
else if(argv[1][0]!='/' && argv[1][0]!='-') { else if(argv[1][0]!='/' && argv[1][0]!='-') {
strupr(argv[1]); strupr(argv[1]);
for(i=0;i<cfg.total_dirs;i++) for(i=0;i<cfg.total_dirs;i++)
if(!stricmp(argv[1],cfg.dir[i]->code)) if(!stricmp(argv[1],cfg.dir[i]->code))
break;
if(i>=cfg.total_dirs) {
printf("\nDirectory code '%s' not found.\n",argv[1]);
return(1); }
dirnum=i; }
for(i=1;i<argc;i++) {
if(!stricmp(argv[i]+1,"LIB")) {
if(dirnum!=-1) {
printf("\nBoth directory code and /LIB parameters were used.\n");
return(1); }
i++;
if(i>=argc) {
printf("\nLibrary short name must follow /LIB parameter.\n");
return(1); }
strupr(argv[i]);
for(j=0;j<cfg.total_libs;j++)
if(!stricmp(cfg.lib[j]->sname,argv[i]))
break; break;
if(j>=cfg.total_libs) { if(i>=cfg.total_dirs) {
printf("\nLibrary short name '%s' not found.\n",argv[i]); printf("\nDirectory code '%s' not found.\n",argv[1]);
return(1); } return(1); }
libnum=j; } dirnum=i; }
else if(!stricmp(argv[i]+1,"NOT")) { for(i=1;i<argc;i++) {
if(nots>=MAX_NOTS) { if(!stricmp(argv[i]+1,"LIB")) {
printf("\nMaximum number of /NOT options (%u) exceeded.\n" if(dirnum!=-1) {
,MAX_NOTS); printf("\nBoth directory code and /LIB parameters were used.\n");
return(1); } return(1); }
i++; i++;
if(i>=argc) { if(i>=argc) {
printf("\nDirectory internal code must follow /NOT parameter.\n"); printf("\nLibrary short name must follow /LIB parameter.\n");
return(1); } return(1); }
sprintf(not[nots++],"%.8s",argv[i]); } strupr(argv[i]);
else if(!stricmp(argv[i]+1,"OFF")) for(j=0;j<cfg.total_libs;j++)
misc|=OFFLINE; if(!stricmp(cfg.lib[j]->sname,argv[i]))
else if(!stricmp(argv[i]+1,"NOL")) break;
misc|=NO_LINK; if(j>=cfg.total_libs) {
else if(!stricmp(argv[i]+1,"RPT")) printf("\nLibrary short name '%s' not found.\n",argv[i]);
misc|=REPORT; return(1); }
else if(!stricmp(argv[i]+1,"ALL")) { libnum=j; }
if(dirnum!=-1) { else if(!stricmp(argv[i]+1,"NOT")) {
printf("\nBoth directory code and /ALL parameters were used.\n"); if(nots>=MAX_NOTS) {
return(1); } printf("\nMaximum number of /NOT options (%u) exceeded.\n"
if(libnum!=-1) { ,MAX_NOTS);
printf("\nBoth library name and /ALL parameters were used.\n"); return(1); }
return(1); } i++;
misc|=ALL; } } if(i>=argc) {
printf("\nDirectory internal code must follow /NOT parameter.\n");
return(1); }
sprintf(not[nots++],"%.8s",argv[i]); }
else if(!stricmp(argv[i]+1,"OFF"))
misc|=OFFLINE;
else if(!stricmp(argv[i]+1,"NOL"))
misc|=NO_LINK;
else if(!stricmp(argv[i]+1,"RPT"))
misc|=REPORT;
else if(!stricmp(argv[i]+1,"ALL")) {
if(dirnum!=-1) {
printf("\nBoth directory code and /ALL parameters were used.\n");
return(1); }
if(libnum!=-1) {
printf("\nBoth library name and /ALL parameters were used.\n");
return(1); }
misc|=ALL; } }
for(i=0;i<cfg.total_dirs;i++) { for(i=0;i<cfg.total_dirs;i++) {
if(!(misc&ALL) && i!=dirnum && cfg.dir[i]->lib!=libnum) if(!(misc&ALL) && i!=dirnum && cfg.dir[i]->lib!=libnum)
continue; continue;
for(j=0;j<nots;j++) for(j=0;j<nots;j++)
if(!stricmp(not[j],cfg.dir[i]->code)) if(!stricmp(not[j],cfg.dir[i]->code))
break; break;
if(j<nots) if(j<nots)
continue; continue;
if(misc&NO_LINK && cfg.dir[i]->misc&DIR_FCHK) { if(misc&NO_LINK && cfg.dir[i]->misc&DIR_FCHK) {
strcpy(tmp,cfg.dir[i]->path); strcpy(tmp,cfg.dir[i]->path);
sprintf(str,"%s*.*",tmp); sprintf(str,"%s*.*",tmp);
printf("\nSearching %s for unlinked files\n",str); printf("\nSearching %s for unlinked files\n",str);
if(!glob(str, GLOB_MARK, NULL, &gl)) { if(!glob(str, GLOB_MARK, NULL, &gl)) {
for(j=0; j<gl.gl_pathc; j++) { for(j=0; j<(int)gl.gl_pathc; j++) {
/* emulate _A_NORMAL */ /* emulate _A_NORMAL */
if(isdir(gl.gl_pathv[j])) if(isdir(gl.gl_pathv[j]))
continue; continue;
if(access(gl.gl_pathv[j], R_OK|W_OK)) if(access(gl.gl_pathv[j], R_OK|W_OK))
continue; continue;
padfname(gl.gl_pathv[j],str); padfname(gl.gl_pathv[j],str);
/* strupr(str); */ /* strupr(str); */
if(!findfile(&cfg, i,str)) { if(!findfile(&cfg, i,str)) {
sprintf(str,"%s%s",tmp,gl.gl_pathv[j]); sprintf(str,"%s%s",tmp,gl.gl_pathv[j]);
printf("Removing %s (not in database)\n",gl.gl_pathv); printf("Removing %s (not in database)\n",gl.gl_pathv);
if(!(misc&REPORT) && remove(str)) if(!(misc&REPORT) && remove(str))
printf("Error removing %s\n",str); } } } printf("Error removing %s\n",str); } } }
globfree(&gl); globfree(&gl);
} }
if(!cfg.dir[i]->maxage && !(misc&OFFLINE)) if(!cfg.dir[i]->maxage && !(misc&OFFLINE))
continue; continue;
printf("\nScanning %s %s\n",cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->lname); printf("\nScanning %s %s\n",cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->lname);
sprintf(str,"%s%s.ixb",cfg.dir[i]->data_dir,cfg.dir[i]->code); sprintf(str,"%s%s.ixb",cfg.dir[i]->data_dir,cfg.dir[i]->code);
if((file=nopen(str,O_RDONLY|O_BINARY))==-1) if((file=nopen(str,O_RDONLY|O_BINARY))==-1)
continue; continue;
l=filelength(file); l=filelength(file);
if(!l) { if(!l) {
close(file);
continue; }
if((ixbbuf=(char *)malloc(l))==NULL) {
close(file);
printf("\7ERR_ALLOC %s %lu\n",str,l);
continue; }
if(read(file,ixbbuf,l)!=(int)l) {
close(file);
printf("\7ERR_READ %s %lu\n",str,l);
free((char *)ixbbuf);
continue; }
close(file); close(file);
continue; }
if((ixbbuf=(char *)malloc(l))==NULL) {
close(file);
printf("\7ERR_ALLOC %s %lu\n",str,l);
continue; }
if(read(file,ixbbuf,l)!=l) {
close(file);
printf("\7ERR_READ %s %lu\n",str,l);
free((char *)ixbbuf);
continue; }
close(file);
m=0L; m=0L;
now=time(NULL); now=time(NULL);
while(m<l) { while(m<l) {
memset(&workfile,0,sizeof(file_t)); memset(&workfile,0,sizeof(file_t));
for(j=0;j<12 && m<l;j++) for(j=0;j<12 && m<l;j++)
if(j==8) if(j==8)
fname[j]='.'; fname[j]='.';
else else
fname[j]=ixbbuf[m++]; fname[j]=ixbbuf[m++];
fname[j]=0; fname[j]=0;
strcpy(workfile.name,fname); strcpy(workfile.name,fname);
unpadfname(workfile.name,fname); unpadfname(workfile.name,fname);
workfile.dir=i; workfile.dir=i;
sprintf(str,"%s%s" sprintf(str,"%s%s"
,workfile.altpath>0 && workfile.altpath<=cfg.altpaths ,workfile.altpath>0 && workfile.altpath<=cfg.altpaths
? cfg.altpath[workfile.altpath-1] ? cfg.altpath[workfile.altpath-1]
: cfg.dir[workfile.dir]->path,fname); : cfg.dir[workfile.dir]->path,fname);
workfile.datoffset=ixbbuf[m]|((long)ixbbuf[m+1]<<8) workfile.datoffset=ixbbuf[m]|((long)ixbbuf[m+1]<<8)
|((long)ixbbuf[m+2]<<16); |((long)ixbbuf[m+2]<<16);
workfile.dateuled=(ixbbuf[m+3]|((long)ixbbuf[m+4]<<8) workfile.dateuled=(ixbbuf[m+3]|((long)ixbbuf[m+4]<<8)
|((long)ixbbuf[m+5]<<16)|((long)ixbbuf[m+6]<<24)); |((long)ixbbuf[m+5]<<16)|((long)ixbbuf[m+6]<<24));
workfile.datedled=(ixbbuf[m+7]|((long)ixbbuf[m+8]<<8) workfile.datedled=(ixbbuf[m+7]|((long)ixbbuf[m+8]<<8)
|((long)ixbbuf[m+9]<<16)|((long)ixbbuf[m+10]<<24)); |((long)ixbbuf[m+9]<<16)|((long)ixbbuf[m+10]<<24));
m+=11; m+=11;
if(cfg.dir[i]->maxage && cfg.dir[i]->misc&DIR_SINCEDL && workfile.datedled if(cfg.dir[i]->maxage && cfg.dir[i]->misc&DIR_SINCEDL && workfile.datedled
&& (now-workfile.datedled)/86400L>cfg.dir[i]->maxage) { && (now-workfile.datedled)/86400L>cfg.dir[i]->maxage) {
printf("Deleting %s (%ld days since last download)\n",fname printf("Deleting %s (%ld days since last download)\n",fname
,(now-workfile.datedled)/86400L); ,(now-workfile.datedled)/86400L);
getfiledat(&cfg, &workfile); getfiledat(&cfg, &workfile);
if(!(misc&REPORT)) { if(!(misc&REPORT)) {
removefiledat(&cfg, &workfile); removefiledat(&cfg, &workfile);
if(remove(str)) if(remove(str))
printf("Error removing %s\n",str); } } printf("Error removing %s\n",str); } }
else if(cfg.dir[i]->maxage else if(cfg.dir[i]->maxage
&& !(workfile.datedled && cfg.dir[i]->misc&DIR_SINCEDL) && !(workfile.datedled && cfg.dir[i]->misc&DIR_SINCEDL)
&& (now-workfile.dateuled)/86400L>cfg.dir[i]->maxage) { && (now-workfile.dateuled)/86400L>cfg.dir[i]->maxage) {
printf("Deleting %s (uploaded %ld days ago)\n",fname printf("Deleting %s (uploaded %ld days ago)\n",fname
,(now-workfile.dateuled)/86400L); ,(now-workfile.dateuled)/86400L);
getfiledat(&cfg, &workfile); getfiledat(&cfg, &workfile);
if(!(misc&REPORT)) { if(!(misc&REPORT)) {
removefiledat(&cfg, &workfile); removefiledat(&cfg, &workfile);
if(remove(str)) if(remove(str))
printf("Error removing %s\n",str); } } printf("Error removing %s\n",str); } }
else if(misc&OFFLINE && cfg.dir[i]->misc&DIR_FCHK && !fexist(str)) { else if(misc&OFFLINE && cfg.dir[i]->misc&DIR_FCHK && !fexist(str)) {
printf("Removing %s (doesn't exist)\n",fname); printf("Removing %s (doesn't exist)\n",fname);
getfiledat(&cfg, &workfile); getfiledat(&cfg, &workfile);
if(!(misc&REPORT)) if(!(misc&REPORT))
removefiledat(&cfg, &workfile); } } removefiledat(&cfg, &workfile); } }
free((char *)ixbbuf); }
free((char *)ixbbuf); } return(0);
} }
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