summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-01-18 17:13:53 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-01-18 17:13:53 +0800
commit5a0e612ca4825c5b35acf82d142fd7d7e745e1d0 (patch)
tree0f13deee81f1f569c8dc13cc3f686299c41f2ed3 /mbbsd
parent519c7a330f916c29c21ef80d2fc20326e7ba96e2 (diff)
downloadpttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar.gz
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar.bz2
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar.lz
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar.xz
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.tar.zst
pttbbs-5a0e612ca4825c5b35acf82d142fd7d7e745e1d0.zip
fix the bug of the cost of deleting post
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3475 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/bbs.c22
-rw-r--r--mbbsd/record.c67
2 files changed, 52 insertions, 37 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 4dbae34b..a5d72bd5 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -545,10 +545,11 @@ cancelpost(const fileheader_t *fh, int by_BM, char *newpath)
}
static void
-do_deleteCrossPost(fileheader_t *fh, char bname[])
+do_deleteCrossPost(const fileheader_t *fh, char bname[])
{
char bdir[MAXPATHLEN]="", file[MAXPATHLEN]="";
- if(!bname) return;
+ fileheader_t newfh;
+ if(!bname || !fh) return;
int i, bid = getbnum(bname);
if(bid <=0 || !fh->filename[0]) return;
@@ -558,11 +559,14 @@ do_deleteCrossPost(fileheader_t *fh, char bname[])
setbdir(bdir, bname);
setbfile(file, bname, fh->filename);
- if( (i=getindex(bdir, fh, 0))>0)
+ memcpy(&newfh, fh, sizeof(fileheader_t));
+ // Ptt: protect original fh
+ // because getindex safe_article_delete will change fh in some case
+ if( (i=getindex(bdir, &newfh, 0))>0)
{
#ifdef SAFE_ARTICLE_DELETE
if(bp && !(currmode & MODE_DIGEST) && bp->nuser > 30 )
- safe_article_delete(i, fh, bdir);
+ safe_article_delete(i, &newfh, bdir);
else
#endif
delete_record(bdir, sizeof(fileheader_t), i);
@@ -572,17 +576,21 @@ do_deleteCrossPost(fileheader_t *fh, char bname[])
}
static void
-deleteCrossPost(fileheader_t *fh, char *bname)
+deleteCrossPost(const fileheader_t *fh, char *bname)
{
if(!fh || !fh->filename[0]) return;
if(!strcmp(bname, ALLPOST) || !strcmp(bname, "NEWIDPOST") ||
!strcmp(bname, ALLHIDPOST) || !strcmp(bname, "UnAnonymous"))
{
+ int len=0;
char xbname[TTLEN + 1], *po = strrchr(fh->title, '.');
if(!po) return;
-
- sprintf(xbname, "%.*s", (int) strlen(po)-3, po+1);
+ po++;
+ len = (int) strlen(po)-2;
+
+ if(len > TTLEN) return;
+ sprintf(xbname, "%.*s", len, po);
do_deleteCrossPost(fh, xbname);
}
else
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 7a2fc429..c58b7ecc 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -132,41 +132,13 @@ substitute_record(const char *fpath, const void *rptr, int size, int id)
return 0;
}
-int
-substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent)
-{
- fileheader_t hdr;
- char fname[PATHLEN];
- int num = 0;
-
- /* rocker.011018: 串接模式用reference增進效率 */
- if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) &&
- (num = fhdr->multi.refer.ref)){
- setdirpath(fname, direct, ".DIR");
- get_record(fname, &hdr, sizeof(hdr), num);
- if (strcmp(hdr.filename, fhdr->filename)) {
- if((num = getindex(fname, fhdr, num))>0) {
- substitute_record(fname, fhdr, sizeof(*fhdr), num);
- }
- }
- else if(num>0) {
- fhdr->multi.money = hdr.multi.money;
- substitute_record(fname, fhdr, sizeof(*fhdr), num);
- }
- fhdr->multi.refer.flag = 1;
- fhdr->multi.refer.ref = num; // Ptt: update now!
- }
- substitute_record(direct, fhdr, sizeof(*fhdr), ent);
- return num;
-}
-
/* return index>0 if thisstamp==stamp[index],
* return -index<0 if stamp[index-1]<thisstamp<stamp[index+1], XXX thisstamp ?<>? stamp[index]
* or XXX filename[index]=""
* return 0 if error
*/
int
-getindex(const char *direct, fileheader_t *fhdr, int end)
+getindex_m(const char *direct, fileheader_t *fhdr, int end, int isloadmoney)
{ // Ptt: 從前面找很費力 太暴力
int fd = -1, begin = 1, i, s, times, stamp;
fileheader_t fh;
@@ -186,7 +158,8 @@ getindex(const char *direct, fileheader_t *fhdr, int end)
end = i - 1;
else if( s == stamp ){
close(fd);
- fhdr->multi.money = fh.multi.money;
+ if(isloadmoney)
+ fhdr->multi.money = fh.multi.money;
return i;
}
else
@@ -203,6 +176,40 @@ getindex(const char *direct, fileheader_t *fhdr, int end)
return 0;
}
+inline int
+getindex(const char *direct, fileheader_t *fhdr, int end)
+{
+ return getindex_m(direct, fhdr, end, 0);
+}
+
+int
+substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent)
+{
+ fileheader_t hdr;
+ char fname[PATHLEN];
+ int num = 0;
+
+ /* rocker.011018: 串接模式用reference增進效率 */
+ if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) &&
+ (num = fhdr->multi.refer.ref)){
+ setdirpath(fname, direct, ".DIR");
+ get_record(fname, &hdr, sizeof(hdr), num);
+ if (strcmp(hdr.filename, fhdr->filename)) {
+ if((num = getindex_m(fname, fhdr, num, 1))>0) {
+ substitute_record(fname, fhdr, sizeof(*fhdr), num);
+ }
+ }
+ else if(num>0) {
+ fhdr->multi.money = hdr.multi.money;
+ substitute_record(fname, fhdr, sizeof(*fhdr), num);
+ }
+ fhdr->multi.refer.flag = 1;
+ fhdr->multi.refer.ref = num; // Ptt: update now!
+ }
+ substitute_record(direct, fhdr, sizeof(*fhdr), ent);
+ return num;
+}
+
/* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */
#ifndef _BBS_UTIL_C_