diff options
-rw-r--r-- | mbbsd/bbs.c | 33 | ||||
-rw-r--r-- | mbbsd/brc.c | 6 |
2 files changed, 29 insertions, 10 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 80a7bec2..5a60a533 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1266,15 +1266,17 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) char genbuf[200]; fileheader_t postfile; boardheader_t *bp = getbcache(currbid); - int isSysop = 0, recordTouched = 0; + int recordTouched = 0; assert(0<=currbid-1 && currbid-1<MAX_BOARD); if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; - if (HasUserPerm(PERM_SYSOP)) - isSysop = 1; - else if ((bp->brdattr & BRD_VOTEBOARD) || + // XXX 不知何時起, edit_post 已經不會有 + 號了... + // 全部都是 Sysop Edit 的原地形式。 + // 哪天有空找個人寫個 mode 是改名 edit 吧 + + if ((bp->brdattr & BRD_VOTEBOARD) || (fhdr->filemode & FILE_VOTE) || !CheckPostPerm() || strcmp(fhdr->owner, cuser.userid) != EQUSTR || @@ -1291,6 +1293,8 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) setutmpmode(REEDIT); setbpath(fpath, currboard); + + // XXX 以現在的模式,這是個 temp file stampfile(fpath, &postfile); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; @@ -1326,6 +1330,7 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) { vmsg("抱歉,檔案已損毀。"); if(src) fclose(src); + unlink(fpath); // fpath is a temp file return FULLUPDATE; } @@ -1351,6 +1356,8 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) } } + // force to remove file first? + // unlink(genbuf); Rename(fpath, genbuf); // this is almost always true... @@ -1358,7 +1365,7 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) { time4_t oldm = fhdr->modified; fhdr->modified = dasht(genbuf); - recordTouched = (oldm == fhdr->modified) ? 1 : 0; + recordTouched = (oldm != fhdr->modified) ? 1 : 0; } if(strcmp(save_title, fhdr->title)){ @@ -1369,7 +1376,11 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) } if(recordTouched) + { substitute_ref_record(direct, fhdr, ent); + // mark my self as "read this file". + brc_addlist(fhdr->filename, fhdr->modified); + } break; } while (1); @@ -2081,15 +2092,18 @@ do_add_recommend(const char *direct, fileheader_t *fhdr, return -1; if (lseek(fd, (sizeof(fileheader_t) * (ent-1) + - (char*)&fhdr->modified - (char*)fhdr), SEEK_SET) >= 0) + (char*)&fhdr->modified - (char*)fhdr), SEEK_SET) < 0) { - write(fd, &fhdr->modified, sizeof(fhdr->modified)); + close(fd); + return -1; } + write(fd, &fhdr->modified, sizeof(fhdr->modified)); if( update && lseek(fd, (sizeof(fileheader_t) * (ent - 1) + (char *)&fhdr->recommend - (char *)fhdr), - SEEK_SET) >= 0 ){ + SEEK_SET) >= 0 ) + { // 如果 lseek 失敗就不會 write read(fd, &fhdr->recommend, sizeof(fhdr->recommend)); fhdr->recommend += update; @@ -2097,6 +2111,9 @@ do_add_recommend(const char *direct, fileheader_t *fhdr, write(fd, &fhdr->recommend, sizeof(fhdr->recommend)); } close(fd); + + // mark my self as "read this file". + brc_addlist(fhdr->filename, fhdr->modified); } return 0; } diff --git a/mbbsd/brc.c b/mbbsd/brc.c index 6b78f205..7a965e33 100644 --- a/mbbsd/brc.c +++ b/mbbsd/brc.c @@ -507,7 +507,7 @@ brc_addlist(const char *fname, time4_t modified) return; for (n = 0; n < brc_num; n++) { /* using linear search */ if (frec.create == brc_list[n].create) { - if (brc_list[n].modified < modified) + if (brc_list[n].modified != modified) { brc_list[n].modified = modified; brc_changed = 1; @@ -558,10 +558,12 @@ brc_unread_time(int bid, time4_t ftime, time4_t modified) time4_t brcm = blist[i].modified; if (modified == 0 || brcm == 0) return 0; + // bad case... seems like that someone is making -1. if (modified == (time4_t)-1 || brcm == (time4_t)-1) return 0; - return modified > brcm ? 2 : 0; + + return modified != brcm ? 2 : 0; } } return 0; |