From c48b4458a45328bb52a77ffd11bd363c024e791c Mon Sep 17 00:00:00 2001
From: piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Sun, 2 Dec 2007 12:20:42 +0000
Subject: BRV v3: update modified logic

git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3614 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 mbbsd/bbs.c | 33 +++++++++++++++++++++++++--------
 mbbsd/brc.c |  6 ++++--
 2 files changed, 29 insertions(+), 10 deletions(-)

(limited to 'mbbsd')

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 ������ɰ_�A edit_post �w�g���|�� + ���F...
+    // �������O Sysop Edit ����a���C
+    // ���Ѧ��ŧ�ӤH�g�� mode �O��W edit �a
+
+    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 �H�{�b���Ҧ��A�o�O�� 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("��p�A�ɮפw�l���C");
 		    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 )
+	{
 	    // �p�G lseek ���ѴN���| 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;
-- 
cgit v1.2.3