From 093e88b99f01594ca10618c6bfa03acddf6dcfa4 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 25 Aug 2002 07:13:53 +0000 Subject: edit lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@493 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/bbs.c | 13 +++++++++++-- mbbsd/edit.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index c6615a0c..23d4b4aa 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.67 2002/07/27 13:14:41 kcwu Exp $ */ +/* $Id: bbs.c,v 1.68 2002/08/25 07:13:53 in2 Exp $ */ #include "bbs.h" static void @@ -718,6 +718,9 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) local_article = fhdr->filemode & FILE_LOCAL; strlcpy(save_title, fhdr->title, sizeof(save_title)); + if( iseditlocking(genbuf, "重複編輯") ) + return FULLUPDATE; + editlock(genbuf); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { setbpath(fpath, currboard); @@ -750,6 +753,7 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) /* rocker.011018: 順便更新一下cache */ touchdircache(currbid); } + editunlock(genbuf); return FULLUPDATE; } @@ -1212,6 +1216,10 @@ recommend(int ent, fileheader_t * fhdr, char *direct) pressanykey(); return FULLUPDATE; } + + setdirpath(path, direct, fhdr->filename); + if( iseditlocking(path, "推薦文章") ) + return FULLUPDATE; if (fhdr->recommend > 9 || fhdr->recommend < 0) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; @@ -1233,7 +1241,6 @@ recommend(int ent, fileheader_t * fhdr, char *direct) cuser.userid, path, 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); - setdirpath(path, direct, fhdr->filename); log_file(path, buf); if (fhdr->recommend < 9) { fhdr->recommend++; @@ -1360,6 +1367,8 @@ del_post(int ent, fileheader_t * fhdr, char *direct) strlcpy(currfile, fhdr->filename, sizeof(currfile)); setbfile(genbuf, currboard, fhdr->filename); + if( iseditlocking(genbuf, "刪除文章") ) + return FULLUPDATE; if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { if (currmode & MODE_SELECT) { diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 589be70d..db335241 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.16 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: edit.c,v 1.17 2002/08/25 07:13:53 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -2280,3 +2280,40 @@ vedit(char *fpath, int saveheader, int *islocal) } } } + +void editlock(char *fpath) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "w")) != NULL ){ + fprintf(fp, "%d\n", currpid); + fclose(fp); + } +} + +void editunlock(char *fpath) +{ + char fn[256]; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + unlink(fn); +} + +int iseditlocking(char *fpath, char *action) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "r")) != NULL ){ + int pid; + fscanf(fp, "%d", &pid); + fclose(fp); + if( kill(pid, 0) >= 0 ){ + vmsg("文章編修中, 暫時無法%s", action); + return 1; + } + else + unlink(fn); + } + return 0; +} -- cgit v1.2.3