From df6500349d563f7b771f0b3ef7f8e74acd136271 Mon Sep 17 00:00:00 2001 From: kcwu Date: Fri, 1 Jun 2007 18:10:00 +0000 Subject: * fix bug: "expire" didn't delete files! git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3529 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/expire.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/util/expire.c b/util/expire.c index 12521c8c..d24c29d6 100644 --- a/util/expire.c +++ b/util/expire.c @@ -14,7 +14,6 @@ char safe_delete_only = 0; #endif extern boardheader_t *bcache; -char bpath[256]; int checkmode = 0; typedef struct { @@ -35,7 +34,7 @@ void callsystem(char *s) void callrm(char *s) { if( checkmode ) - printf("in checkmode, skip rm %s\n", s); + printf("\tin checkmode, skip rm %s\n", s); else unlink(s); } @@ -43,16 +42,16 @@ void callrm(char *s) void cleanSR(char *brdname) { DIR *dirp; - char dirf[128], fpath[PATHLEN]; + char dirf[PATHLEN], fpath[PATHLEN]; struct dirent *ent; int nDelete = 0; - sprintf(dirf, "boards/%c/%s", brdname[0], brdname); + setbpath(dirf, brdname); if( (dirp = opendir(dirf)) == NULL ) return; while( (ent = readdir(dirp)) != NULL ) if( strncmp(ent->d_name, "SR.", 3) == 0 ){ - sprintf(fpath, "%s/%s", dirf, ent->d_name); + setbfile(fpath, brdname, ent->d_name); callrm(fpath); ++nDelete; } @@ -93,7 +92,7 @@ void expire(life_t *brd) #endif cleanSR(brd->bname); - sprintf(index, "%s/%s/.DIR", bpath, brd->bname); + setbfile(index, brd->bname, ".DIR"); sprintf(lockfile, "%s.lock", index); if ((fdlock = open(lockfile, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1){ perror("open lock file error"); @@ -146,13 +145,8 @@ void expire(life_t *brd) } else { ++nDelete; - strcpy(fname, head.filename); - if( checkmode ) - printf("\tin checkmode, skip rm %s\n", fname); - else{ - unlink(fname); - printf("\t%s\n", fname); - } + setbfile(fname, brd->bname, head.filename); + callrm(fname); total--; } } @@ -199,6 +193,7 @@ void visitdir(char c) { DIR *dirp; struct dirent *de; + char bpath[PATHLEN]; sprintf(bpath, BBSHOME "/boards/%c", c); if (!(dirp = opendir(bpath))){ @@ -313,7 +308,6 @@ int main(int argc, char **argv) if( argv[i][1] == '*' ) visitdir(argv[i][0]); else{ - sprintf(bpath, BBSHOME "/boards/%c", argv[i][0]); toexpire(argv[i]); } } -- cgit v1.2.3