From 8757cdfe471d6bbe514b2197e1db7e001aeaaae4 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 13 Feb 2004 13:21:45 +0000 Subject: SAFE_ARTICLE_DELETE for 'D' git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1534 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 1 + mbbsd/bbs.c | 4 ++++ mbbsd/record.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/proto.h b/include/proto.h index 10a9dad1..c36a4b23 100644 --- a/include/proto.h +++ b/include/proto.h @@ -422,6 +422,7 @@ int delete_record(char fpath[], int size, int id); int delete_files(char* dirname, int (*filecheck)(), int record); #ifdef SAFE_ARTICLE_DELETE int safe_article_delete(int ent, fileheader_t *fhdr, char *direct); +int safe_article_delete_range(char *direct, int from, int to); #endif int delete_file(char *dirname, int size, int ent, int (*filecheck)()); int delete_range(char *fpath, int id1, int id2); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 250fa986..3e9972b1 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1810,7 +1810,11 @@ del_range(int ent, fileheader_t * fhdr, char *direct) close(fd); } } +#ifdef SAFE_ARTICLE_DELETE + safe_article_delete_range(direct, inum1, inum2); +#else delete_range(direct, inum1, inum2); +#endif fixkeep(direct, inum1); if (currmode & MODE_BOARD) diff --git a/mbbsd/record.c b/mbbsd/record.c index e1388abe..5e3a4ebe 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -412,6 +412,38 @@ safe_article_delete(int ent, fileheader_t *fhdr, char *direct) substitute_record(direct, &newfhdr, sizeof(newfhdr), ent); return 0; } + +int +safe_article_delete_range(char *direct, int from, int to) +{ + fileheader_t newfhdr; + int fd; + char fn[128], *ptr; + + strlcpy(fn, direct, sizeof(fn)); + if( (ptr = rindex(fn, '/')) == NULL ) + return 0; + + ++ptr; + if( (fd = open(direct, O_RDWR)) != -1 && + lseek(fd, sizeof(fileheader_t) * (from - 1), SEEK_SET) != -1 ){ + + for( ; from <= to ; ++from ){ + read(fd, &newfhdr, sizeof(fileheader_t)); + strlcpy(ptr, newfhdr.filename, sizeof(newfhdr.filename)); + unlink(fn); + + sprintf(newfhdr.title, "(本文已被刪除)"); + strcpy(newfhdr.filename, ".deleted"); + strcpy(newfhdr.owner, "-"); + // because off_t is unsigned, we could NOT seek backward. + lseek(fd, sizeof(fileheader_t) * (from - 1), SEEK_SET); + write(fd, &newfhdr, sizeof(fileheader_t)); + } + close(fd); + } + return 0; +} #endif int -- cgit v1.2.3