summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-11-01 14:54:10 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-11-01 14:54:10 +0800
commitab7b2c73e4f8901160fe0d111e33ef7db2d3883e (patch)
tree3ee4f3f73ab52809215c1b288141036c98e54aad
parent45981c663c7a8ef3a50176cebf23bcc55102b007 (diff)
downloadpttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar.gz
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar.bz2
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar.lz
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar.xz
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.tar.zst
pttbbs-ab7b2c73e4f8901160fe0d111e33ef7db2d3883e.zip
add expire to timecap
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5196 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/util/Makefile4
-rw-r--r--pttbbs/util/timecap_buildref.c69
-rwxr-xr-xpttbbs/util/timecap_expire.sh36
3 files changed, 107 insertions, 2 deletions
diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile
index 7235b9f6..3d6bb79e 100644
--- a/pttbbs/util/Makefile
+++ b/pttbbs/util/Makefile
@@ -22,7 +22,7 @@ CPROG_WITH_UTIL= \
outmail chkhbf merge_dir \
angel gamblegive \
chesscountry tunepasswd buildir xchatd \
- uhash_loader
+ uhash_loader timecap_buildref
# 下面是 C++ 的程式
CPP_WITH_UTIL= \
@@ -40,7 +40,7 @@ PROGS= ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${CPP_WITH_UTIL}\
openticket.sh topsong.sh weather.sh \
weather.perl toplazyBM.sh \
dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \
- getbackup.pl rebuildaloha.pl
+ getbackup.pl rebuildaloha.pl timecap_expire.sh
LDLIBS+=$(SRCROOT)/common/bbs/libcmbbs.a \
$(SRCROOT)/common/sys/libcmsys.a \
diff --git a/pttbbs/util/timecap_buildref.c b/pttbbs/util/timecap_buildref.c
new file mode 100644
index 00000000..669143ee
--- /dev/null
+++ b/pttbbs/util/timecap_buildref.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+#include "bbs.h"
+
+// check timecap.c
+#ifndef TIME_CAPSULE_ARCHIVE_INDEX_NAME
+#define TIME_CAPSULE_ARCHIVE_INDEX_NAME "archive.idx"
+#endif
+#ifndef TIME_CAPSULE_REVISION_INDEX_NAME
+#define TIME_CAPSULE_REVISION_INDEX_NAME ".rev"
+#endif
+
+int main(int argc, char **argv)
+{
+ const char *dirpath;
+ char archive_path[PATHLEN], tmp_archive_path[PATHLEN];
+ FILE *fin, *fout;
+ fileheader_t fh;
+ int num_keep = 0, num_remove = 0;
+
+ if (argc != 2) {
+ printf("syntax: %s PATH_TO_TIMECAP\n", argv[0]);
+ return 1;
+ }
+
+ dirpath = argv[1];
+ if (!dashd(dirpath)) {
+ fprintf(stderr, "invalid directory: %s\n", dirpath);
+ return 1;
+ }
+
+ snprintf(archive_path, sizeof(archive_path), "%s/%s",
+ dirpath, TIME_CAPSULE_ARCHIVE_INDEX_NAME);
+ if (!dashs(archive_path)) {
+ fprintf(stderr, "missing time capsule archive: %s\n", archive_path);
+ return 1;
+ }
+
+ strlcpy(tmp_archive_path, archive_path, sizeof(tmp_archive_path));
+ strlcat(tmp_archive_path, ".tmp", sizeof(tmp_archive_path));
+
+ fin = fopen(archive_path, "rb");
+ fout = fopen(tmp_archive_path, "wb");
+
+ if (!fin || !fout) {
+ fprintf(stderr, "failed to create temporary index file for output.\n");
+ return 2;
+ }
+
+ while (fread(&fh, sizeof(fh), 1, fin) == 1) {
+ // build file name
+ char rev_index_path[PATHLEN];
+ setdirpath(rev_index_path, archive_path, fh.filename);
+ strlcat(rev_index_path, TIME_CAPSULE_REVISION_INDEX_NAME,
+ sizeof(rev_index_path));
+ if (!dashf(rev_index_path)) {
+ num_remove++;
+ continue;
+ }
+ num_keep++;
+ fwrite(&fh, sizeof(fh), 1, fout);
+ }
+
+ fclose(fin);
+ fclose(fout);
+ printf("%s: %d entries kept, %d entries removed.\n",
+ archive_path, num_keep, num_remove);
+ return Rename(tmp_archive_path, archive_path);
+}
diff --git a/pttbbs/util/timecap_expire.sh b/pttbbs/util/timecap_expire.sh
new file mode 100755
index 00000000..dd5f16cf
--- /dev/null
+++ b/pttbbs/util/timecap_expire.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+# expire rules
+EXPIRE_TIME=103000m
+
+# extract boards
+BBSHOME=$HOME
+BOARDS=$($BBSHOME/bin/showboard $BBSHOME/.BRD | sed 's/^ *[0-9][0-9]* //; s/ .*//')
+BOARD_BASE=$BBSHOME/boards
+
+# check TIME_CAPSULE_BASE_FOLDER_NAME in mbbsd/timecap.c
+TIMECAP_NAME=".timecap"
+
+i=0
+num_boards=$(echo $BOARDS | wc -w)
+date # for loggin
+date >&2 # still for logging
+
+for board in $BOARDS
+do
+ i=$((i + 1))
+ timecap_base=$(
+ printf "%s/%c/%s/%s" "$BOARD_BASE" "$board" "$board" "$TIMECAP_NAME")
+ printf '\r%05d / %05d %-12s ...' $i $num_boards "$board" >&2
+ if [ ! -d "$timecap_base" ]; then
+ continue
+ fi
+
+ # first stage, expire files
+ find "$timecap_base" -mtime "$EXPIRE_TIME" -ls -delete
+
+ # second stage, modify .DIR files
+ # dir_file="$timecap_base/archive.idx"
+ $BBSHOME/bin/timecap_buildref "$timecap_base"
+done
+echo "" >&2