diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-13 21:21:45 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-13 21:21:45 +0800 |
commit | 8757cdfe471d6bbe514b2197e1db7e001aeaaae4 (patch) | |
tree | 723d7920b2ba7ab48afdd8c1b3e0528207b729ce | |
parent | f306175ad4da53773f8458ca88e3dd6cd8ab760a (diff) | |
download | pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar.gz pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar.bz2 pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar.lz pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar.xz pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.tar.zst pttbbs-8757cdfe471d6bbe514b2197e1db7e001aeaaae4.zip |
SAFE_ARTICLE_DELETE for 'D'
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1534 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 1 | ||||
-rw-r--r-- | mbbsd/bbs.c | 4 | ||||
-rw-r--r-- | mbbsd/record.c | 32 |
3 files changed, 37 insertions, 0 deletions
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 |