summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
commit1a77a39f25006a3f73b36365220c3168c59f9fd2 (patch)
tree9c4fc1c9715dfeaad11cb8bcc159b6cf23e9c417 /mbbsd
parent5894f7afe1f35469e766a3c3fd6f6b0ee806a31a (diff)
downloadpttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.gz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.bz2
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.lz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.xz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.zst
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.zip
MDCACHE
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@103 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/cache.c46
-rw-r--r--mbbsd/edit.c6
-rw-r--r--mbbsd/more.c21
3 files changed, 67 insertions, 6 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index daef6628..8fceef65 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.8 2002/04/09 20:33:52 in2 Exp $ */
+/* $Id: cache.c,v 1.9 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -826,7 +826,8 @@ int haspostperm(char *bname) {
/* cachefor 動態看版 */
struct pttcache_t *ptt;
-static void reload_pttcache() {
+static void reload_pttcache()
+{
if(ptt->busystate)
safe_sleep(1);
else { /* jochang: temporary workaround */
@@ -895,11 +896,13 @@ static void reload_pttcache() {
}
}
+int *GLOBE;
void resolve_garbage() {
int count=0;
if(ptt == NULL) {
ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
+ GLOBE = ptt->GLOBE;
if(ptt->touchtime == 0)
ptt->touchtime = 1;
}
@@ -1021,3 +1024,42 @@ int hbflcheck(int bid, int uid)
}
return 1;
}
+
+#ifdef MDCACHE
+char *cachepath(const char *fpath)
+{
+ static char cpath[128];
+ char *ptr;
+ snprintf(cpath, sizeof(cpath), "cache/%s", fpath);
+ for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr )
+ if( *ptr == '/' )
+ *ptr = '.';
+ return cpath;
+}
+
+int updatemdcache(const char *CPATH, const char *fpath)
+{
+ /* save file to mdcache with *cpath and *fpath,
+ return: -1 if error
+ else the fd
+ */
+ int len, sourcefd, targetfd;
+ char buf[1024], *cpath;
+ cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH;
+ if( (sourcefd = open(fpath, O_RDONLY)) < 0 )
+ return -1;
+ if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 )
+ /* md is full? */
+ return -1;
+ while( (len = read(sourcefd, buf, sizeof(buf))) > 0 )
+ if( write(targetfd, buf, len) < len ){
+ /* md is full? */
+ close(targetfd);
+ unlink(cpath);
+ return sourcefd;
+ }
+ close(sourcefd);
+ lseek(targetfd, 0, SEEK_SET);
+ return targetfd;
+}
+#endif
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index 19f437af..0c722105 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -1,4 +1,4 @@
-/* $Id: edit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+/* $Id: edit.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1014,6 +1014,10 @@ write_file(char *fpath, int saveheader, int *islocal) {
}
fclose(fp);
+
+#ifdef MDCACHE
+ updatemdcache(NULL, fpath);
+#endif
if(local_article && (currstat == POSTING))
return 0;
return 0;
diff --git a/mbbsd/more.c b/mbbsd/more.c
index f7755874..a65c1ee5 100644
--- a/mbbsd/more.c
+++ b/mbbsd/more.c
@@ -1,4 +1,4 @@
-/* $Id: more.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+/* $Id: more.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -193,7 +193,7 @@ static int readln(FILE *fp, char *buf) {
extern userec_t cuser;
static int more_web(char *fpath, int promptend);
-
+extern int *GLOBE;
int more(char *fpath, int promptend) {
extern char* strcasestr();
static char *head[4] = {"作者", "標題", "時間" ,"轉信"};
@@ -232,8 +232,23 @@ int more(char *fpath, int promptend) {
search_char0 = *search_str;
*search_str = 0;
-
+#ifdef MDCACHE
+ if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){
+ /* we only cache boards/ and etc/ */
+ char *cpath = cachepath(fpath);
+ ++GLOBE[0];
+ if( (fd = open(cpath, O_RDONLY)) < 0 ){
+ if( (fd = updatemdcache(cpath, fpath)) < 0 )
+ return -1;
+ }
+ else
+ ++GLOBE[1];
+ }
+ else
+ fd = open (fpath, O_RDONLY, 0600);
+#else
fd = open (fpath, O_RDONLY, 0600);
+#endif
if (fd < 0) return -1;
if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode))