summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-08-25 15:13:53 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-08-25 15:13:53 +0800
commit093e88b99f01594ca10618c6bfa03acddf6dcfa4 (patch)
tree42aa670fdf9815df433155db4842b572957b521e
parent66ef2c085317e18a704cfbe7e98f2b448ca58e16 (diff)
downloadpttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar.gz
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar.bz2
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar.lz
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar.xz
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.tar.zst
pttbbs-093e88b99f01594ca10618c6bfa03acddf6dcfa4.zip
edit lock
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@493 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h5
-rw-r--r--mbbsd/bbs.c13
-rw-r--r--mbbsd/edit.c39
3 files changed, 53 insertions, 4 deletions
diff --git a/include/proto.h b/include/proto.h
index 2197427b..e4e910d7 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.28 2002/08/23 18:01:28 in2 Exp $ */
+/* $Id: proto.h,v 1.29 2002/08/25 07:13:53 in2 Exp $ */
#ifndef INCLUDE_PROTO_H
#define INCLUDE_PROTO_H
@@ -193,6 +193,9 @@ void auto_backup();
void restore_backup();
char *ask_tmpbuf(int y);
char *strcasestr(const char* big, const char* little);
+void editlock(char *fpath);
+void editunlock(char *fpath);
+int iseditlocking(char *fpath, char *action);
/* friend */
void friend_edit(int type);
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;
+}