diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:05:49 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:05:49 +0800 |
commit | f596ac6e290311dea6c2181816b7d096127696a8 (patch) | |
tree | a16f1ae6de9c7090b91f6524ec2cb00df30ed7f0 /mbbsd | |
parent | 7f978de8ae9803e73a0ac9c3650517341b3f0a76 (diff) | |
download | pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar.gz pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar.bz2 pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar.lz pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar.xz pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.tar.zst pttbbs-f596ac6e290311dea6c2181816b7d096127696a8.zip |
light-weight recommend
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1404 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/bbs.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 6e9aeecb..8d1f4aca 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1461,21 +1461,33 @@ recommend_cancel(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } static int -do_add_recommend(char * direct,fileheader_t * fhdr, int ent, char*buf) +do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf) { - char path[256]; - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); + char path[256]; + int fd; setdirpath(path, direct, fhdr->filename); - log_file(path, buf); - if (!(fhdr->recommend < 100)) - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); - else{ - fhdr->recommend++; - passwd_update(usernum, &cuser); - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); - substitute_check(fhdr); - touchdircache(currbid); - } + if( (fd = open(path, O_WRONLY | O_APPEND)) < 0 ){ // 只 APPEND, 不 CREAT + vmsg("推薦/競標失敗"); + return -1; + } + write(fd, buf, strlen(buf)); + close(fd); + + if( fhdr->recommend < 100 ){ + fileheader_t t; + if( (fd = open(direct, O_WRONLY)) < 0 ) + return -1; + + ++fhdr->recommend; + if( lseek(fd, (off_t)(sizeof(*fhdr) * (ent - 1) + + (int)&t.recommend - (int)&t), + SEEK_SET) < 0 || + write(fd, &fhdr->recommend, sizeof(char)) ) + ; // 如果 lseek 失敗就不會 write + + close(fd); + touchdircache(currbid); + } return 0; } static int |