summaryrefslogtreecommitdiffstats
path: root/mbbsd/record.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-18 18:50:02 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-18 18:50:02 +0800
commitdb954b44399033c47b1a2cf3f680561c9a770781 (patch)
treec87feb9a719c846f2d892bb09b5b752304d7444c /mbbsd/record.c
parent39190232807f87402391b240281ec1f36954071a (diff)
downloadpttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar.gz
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar.bz2
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar.lz
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar.xz
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.tar.zst
pttbbs-db954b44399033c47b1a2cf3f680561c9a770781.zip
* refine stampdir behavior
* we don't want massive user to use man(announce) as blog/home, so restrict folder number back to 4096 * for deleted/junk boards, they need to use large set (65535) because they may contain all boards from entire site git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4750 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/record.c')
-rw-r--r--mbbsd/record.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 6422253b..348c4d8d 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -360,6 +360,8 @@ stampfile_u(char *fpath, fileheader_t * fh)
return 0;
}
+// XXX 小心... 目前實際的 stampfile 似乎是 common/bbs/fhdr_stamp.c 打架,
+// 也就是不會去用 _u.
inline int
stampfile(char *fpath, fileheader_t * fh)
{
@@ -367,25 +369,43 @@ stampfile(char *fpath, fileheader_t * fh)
return stampfile_u(fpath, fh);
}
+// XXX announce(man) directory uses a smaller range of file names.
int
-stampdir(char *fpath, fileheader_t * fh)
+stampadir(char *fpath, fileheader_t * fh, int large_set)
{
register char *ip = fpath;
- time4_t dtime = COMMON_TIME;
- struct tm ptime;
+ time4_t dtime = COMMON_TIME;
+ struct tm ptime;
+ const int mask_small = 0xFFF, // basic (4096)
+ mask_large = 0xFFFF; // large (65536)
+ int mask = mask_small;
int retries = 0;
- if (access(fpath, X_OK | R_OK | W_OK))
+ // try to create root path
+ if (access(fpath, X_OK | R_OK | W_OK) != 0)
mkdir(fpath, 0755);
+ // find tail
while (*(++ip));
*ip++ = '/';
+
+ // loop to create file
+ memset(fh, 0, sizeof(fileheader_t));
do {
- // XXX if directories exceed 4096(0xFFF), use 65536.
- int mask = (++retries < 0xFFF) ? 0xFFF : 0xFFFF;
+ if (++retries > mask_small && mask == mask_small)
+ {
+ if (!large_set)
+ return -1;
+ mask = mask_large;
+ }
+ if (retries > mask_large)
+ return -1;
+
+ // create minimal length file name.
sprintf(ip, "D%X", (int)++dtime & mask);
+
} while (mkdir(fpath, 0755) == -1);
- memset(fh, 0, sizeof(fileheader_t));
+
strlcpy(fh->filename, ip, sizeof(fh->filename));
localtime4_r(&dtime, &ptime);
snprintf(fh->date, sizeof(fh->date),