summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--include/proto.h1
-rw-r--r--mbbsd/announce.c24
-rw-r--r--mbbsd/record.c34
3 files changed, 47 insertions, 12 deletions
diff --git a/include/proto.h b/include/proto.h
index 96aa0290..a2782513 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -429,6 +429,7 @@ void EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus);
void UnTagger (int locus);
/* record */
int stampfile_u(char *fpath, fileheader_t *fh);
+int stampadir(char *fpath, fileheader_t * fh, int large_set);
int delete_files(const char* dirname, int (*filecheck)(), int record);
void set_safedel_fhdr(fileheader_t *fhdr);
#ifdef SAFE_ARTICLE_DELETE
diff --git a/mbbsd/announce.c b/mbbsd/announce.c
index 733cd74a..6b076b93 100644
--- a/mbbsd/announce.c
+++ b/mbbsd/announce.c
@@ -422,7 +422,11 @@ a_newitem(menu_t * pm, int mode)
break;
case ADDGROUP:
- stampdir(fpath, &item);
+ if (stampadir(fpath, &item, 0) == -1)
+ {
+ vmsg("抱歉,無法在本層建立新目錄。");
+ return;
+ }
strlcpy(item.title, "◆ ", sizeof(item.title)); /* A1BB */
break;
}
@@ -547,8 +551,8 @@ a_pasteitem(menu_t * pm, int mode)
stampfile(newpath, &item);
memcpy(cq->copytitle, "◇", 2);
Copy(cq->copyfile, newpath);
- } else if (dashd(cq->copyfile)) {
- stampdir(newpath, &item);
+ } else if (dashd(cq->copyfile) &&
+ stampadir(newpath, &item, 0) != -1) {
memcpy(cq->copytitle, "◆", 2);
copy_file(cq->copyfile, newpath);
} else {
@@ -842,7 +846,13 @@ a_delete(menu_t * pm)
return;
setapath(buf, save_bn);
- stampdir(buf, &backup);
+ // XXX because this directory will hold folders from entire site,
+ // let's allow it to use a large set of file names.
+ if (stampadir(buf, &backup, 1) != 0)
+ {
+ vmsg("抱歉,系統目前無法刪除資料,請通知站務人員");
+ return;
+ }
snprintf(cmd, sizeof(cmd),
"rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf);
@@ -1815,7 +1825,11 @@ void BlogMain(int num)
fileheader_t item;
char fpath[PATHLEN], adir[PATHLEN], buf[PATHLEN];
setapath(fpath, currboard);
- stampdir(fpath, &item);
+ if (stampadir2(buf, &item, 0) != 0)
+ {
+ vmsg("抱歉,目錄建立失敗。請減少單層目錄數量或通知站務人員協助。");
+ break;
+ }
strlcpy(item.title, "◆ Blog", sizeof(item.title));
strlcpy(item.owner, cuser.userid, sizeof(item.owner));
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),