diff options
-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 |