This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project iwhd.git.
The branch, master has been updated
via cc80a83104880b098979a27d594734c916497c92 (commit)
via a1e1c061a29a840288a7f072afea1a743c45ee7b (commit)
from 30cfcfe2d708e11f027b3d8f3303680ee15b8e65 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/iwhd.git/commit/cc80a83104880b098979a27d594734c916497c92
commit cc80a83104880b098979a27d594734c916497c92
Author: Jim Meyering <meyering(a)redhat.com>
Date: Fri Nov 5 18:33:54 2010 +0100
convert reserved attribute names to have a leading underscore prefix
Before, they were date, etag, loc, key, bucket, and
now they are _date, _etag, _loc, _key, _bucket.
Add the accidentally omitted "_size" to the new list.
diff --git a/meta.cpp b/meta.cpp
index d467c1e..b7ae903 100644
--- a/meta.cpp
+++ b/meta.cpp
@@ -196,7 +196,7 @@ RepoMeta::DidPut (const char *bucket, const char *key, const char
*loc,
dbl_to_str(&now,now_str);
cout << "now_str = " << now_str << endl;
- q = QUERY("bucket"<<bucket<<"key"<<key);
+ q = QUERY("_bucket"<<bucket<<"_key"<<key);
curs = GetCursor(q);
if (!curs.get()) {
cerr << "DidPut failed for " << bucket << "/"
<< key << endl;
@@ -205,25 +205,25 @@ RepoMeta::DidPut (const char *bucket, const char *key, const char
*loc,
if (curs->more()) {
/* Nice functionality, but what an ugly syntax! */
client.update(MAIN_TBL,q,BSON(
- "$set"<<BSON("loc"<<BSON_ARRAY(loc))
- << "$set"<<BSON("date"<<now)
- << "$set"<<BSON("etag"<<now_str)
- << "$set"<<BSON("size"<<(long long)size)));
+ "$set"<<BSON("_loc"<<BSON_ARRAY(loc))
+ << "$set"<<BSON("_date"<<now)
+ << "$set"<<BSON("_etag"<<now_str)
+ << "$set"<<BSON("_size"<<(long long)size)));
#if 0
client.update(MAIN_TBL,q,
- BSON("$set"<<BSON("loc"<<BSON_ARRAY(loc))));
+ BSON("$set"<<BSON("_loc"<<BSON_ARRAY(loc))));
client.update(MAIN_TBL,q,
- BSON("$set"<<BSON("date"<<now)));
+ BSON("$set"<<BSON("_date"<<now)));
client.update(MAIN_TBL,q,
- BSON("$set"<<BSON("etag"<<now_str)));
+ BSON("$set"<<BSON("_etag"<<now_str)));
client.update(MAIN_TBL,q,
- BSON("$set"<<BSON("size"<<(long long)size)));
+ BSON("$set"<<BSON("_size"<<(long long)size)));
#endif
}
else {
- bb << "bucket" << bucket << "key" << key
- << "loc" << BSON_ARRAY(loc) << "date" <<
now
- << "etag" << now_str << "size" << (long
long)size;
+ bb << "_bucket" << bucket << "_key" << key
+ << "_loc" << BSON_ARRAY(loc) << "_date"
<< now
+ << "_etag" << now_str << "_size" <<
(long long)size;
client.insert(MAIN_TBL,bb.obj());
}
@@ -252,7 +252,7 @@ RepoMeta::GotCopy (const char *bucket, const char *key, const char
*loc)
auto_ptr<DBClientCursor> curs;
Query q;
- q = QUERY("bucket"<<bucket<<"key"<<key);
+ q = QUERY("_bucket"<<bucket<<"_key"<<key);
curs = GetCursor(q);
if (!curs.get()) {
cerr << "GotCopy failed for " << bucket << "/"
<< key << endl;
@@ -260,7 +260,7 @@ RepoMeta::GotCopy (const char *bucket, const char *key, const char
*loc)
}
if (curs->more()) {
/* Nice functionality, but what an ugly syntax! */
- client.update(MAIN_TBL,q,BSON("$addToSet"<<BSON("loc"<<loc)));
+ client.update(MAIN_TBL,q,BSON("$addToSet"<<BSON("_loc"<<loc)));
}
else {
cerr << bucket << "/" << key << " not found in
GotCopy!" << endl;
@@ -283,7 +283,7 @@ RepoMeta::HasCopy (const char *bucket, const char *key, const char
*loc)
Query q;
const char *value;
- q =
QUERY("bucket"<<bucket<<"key"<<key<<"loc"<<loc);
+ q =
QUERY("_bucket"<<bucket<<"_key"<<key<<"_loc"<<loc);
curs = GetCursor(q);
if (!curs.get()) {
cerr << "HasCopy failed for " << bucket << "/"
<< key << endl;
@@ -294,13 +294,13 @@ RepoMeta::HasCopy (const char *bucket, const char *key, const char
*loc)
return (char *)"";
}
- value = curs->next().getStringField("etag");
+ value = curs->next().getStringField("_etag");
if (!value || !*value) {
- cout << bucket << "/" << key << " no etag at
" << loc << endl;
+ cout << bucket << "/" << key << " no _etag at
" << loc << endl;
return (char *)"";
}
- cout << bucket << "/" << key << " etag = "
<< value << endl;
+ cout << bucket << "/" << key << " _etag = "
<< value << endl;
return strdup(value);
}
@@ -320,7 +320,7 @@ int
RepoMeta::SetValue (const char *bucket, const char *key, const char *mkey,
const char * mvalue)
{
- Query q = QUERY("bucket"<<bucket<<"key"<<key);
+ Query q = QUERY("_bucket"<<bucket<<"_key"<<key);
try {
client.update(MAIN_TBL,q,BSON("$set"<<BSON(mkey<<mvalue)),1);
@@ -357,7 +357,7 @@ RepoMeta::GetValue (const char *bucket, const char *key, const char
*mkey,
BSONObj bo;
const char * data;
- q = QUERY("bucket"<<bucket<<"key"<<key);
+ q = QUERY("_bucket"<<bucket<<"_key"<<key);
curs = GetCursor(q);
if (!curs.get()) {
cerr << "GetValue failed for " << bucket << "/"
<< key << ":"
@@ -400,11 +400,11 @@ RepoQuery::RepoQuery (const char *bucket, const char *key, const
char *qstr,
if (bucket) {
cout << "bucket is " << bucket << " and we don't
care" << endl;
- q = QUERY("bucket"<<bucket);
+ q = QUERY("_bucket"<<bucket);
}
else if (key) {
cout << "key is " << key << " and we don't
care" << endl;
- q = QUERY("key"<<key);
+ q = QUERY("_key"<<key);
}
else {
abort();
@@ -481,8 +481,8 @@ RepoQuery::Next (void)
continue;
}
}
- bucket = (char *)bo.getStringField("bucket");
- key = (char *)bo.getStringField("key");
+ bucket = (char *)bo.getStringField("_bucket");
+ key = (char *)bo.getStringField("_key");
return true;
}
@@ -539,7 +539,7 @@ RepoMeta::BucketList (void)
*/
BSONObj repl;
- BSONObj dist =
BSON("distinct"<<"main"<<"key"<<"bucket");
+ BSONObj dist =
BSON("distinct"<<"main"<<"_key"<<"_bucket");
if (client.runCommand("repo",dist,repl)) {
cout << repl.toString() << endl;
BSONObj elem = repl.getField("values").embeddedObject();
@@ -553,7 +553,7 @@ RepoMeta::BucketList (void)
void
RepoMeta::Delete (const char *bucket, const char *key)
{
- Query q = QUERY("bucket"<<bucket<<"key"<<key);
+ Query q = QUERY("_bucket"<<bucket<<"_key"<<key);
try {
client.remove(MAIN_TBL,q);
@@ -582,7 +582,7 @@ RepoMeta::GetSize (const char *bucket, const char *key)
(void)data;
- q = QUERY("bucket"<<bucket<<"key"<<key);
+ q = QUERY("_bucket"<<bucket<<"_key"<<key);
curs = GetCursor(q);
if (!curs->more()) {
@@ -590,7 +590,7 @@ RepoMeta::GetSize (const char *bucket, const char *key)
}
bo = curs->next();
- return bo.getField("size").numberLong();
+ return bo.getField("_size").numberLong();
}
extern "C"
@@ -646,7 +646,7 @@ RepoMeta::GetAttrList (const char *bucket, const char *key)
Query q;
BSONObj bo;
- q = QUERY("bucket"<<bucket<<"key"<<key);
+ q = QUERY("_bucket"<<bucket<<"_key"<<key);
curs = GetCursor(q);
if (!curs->more()) {
diff --git a/rest.c b/rest.c
index f38f5ef..96b8348 100644
--- a/rest.c
+++ b/rest.c
@@ -70,7 +70,7 @@ const char *program_name;
char *cfg_file = NULL;
static const char *const (reserved_name[]) = {"_default", "_new",
"_policy", "_query", NULL};
-static const char *const (reserved_attr[]) = {"bucket", "date",
"etag", "key", "loc", NULL};
+static const char *const (reserved_attr[]) = {"_bucket", "_date",
"_etag", "_key", "_loc", "_size", NULL};
static const char *const (reserved_bucket_name[]) = {"_new",
"_providers", NULL};
void
@@ -1262,10 +1262,10 @@ proxy_bucket_post (void *cctx, struct MHD_Connection *conn, const
char *url,
}
else {
rc = MHD_HTTP_BAD_REQUEST;
- key = g_hash_table_lookup(ms->dict,"key");
+ key = g_hash_table_lookup(ms->dict,"_key");
if (key) {
strncpy(ms->key,key,MAX_FIELD_LEN-1);
- g_hash_table_remove(ms->dict,"key");
+ g_hash_table_remove(ms->dict,"_key");
if (!g_hash_table_find(ms->dict,post_find,ms)) {
g_hash_table_foreach(ms->dict,post_foreach,ms);
DPRINTF("rereplicate (bucket POST)n");
diff --git a/t/basic b/t/basic
index a903648..3d610d9 100644
--- a/t/basic
+++ b/t/basic
@@ -266,7 +266,7 @@ test "$(curl $bucket/attr_put/color)" = blue || fail=1
# Add multiple attributes to an object using the POST method.
# NB use a file which doesn't yet exist (yes, this should work too)
-curl -d key=attr_post -d shape=round -d size=big $bucket || fail=1
+curl -d _key=attr_post -d shape=round -d size=big $bucket || fail=1
test "$(curl $bucket/attr_post/shape)" = round || fail=1
test "$(curl $bucket/attr_post/size)" = big || fail=1
@@ -286,7 +286,7 @@ done
# Ensure that an attempt to add each reserved attribute fails.
# FIXME: keep this list in sync with the one in rest.c:
# grep '^static.*reserved_attr' rest.c
-for attr in bucket key date etag loc; do
+for attr in _bucket _key _date _etag _loc _size; do
printf whatever | curl -f -T - $bucket/rsvd_attr/$attr 2> bad_attr.err
grep ' 400$' bad_attr.err || fail=1
done
http://repo.or.cz/w/iwhd.git/commit/a1e1c061a29a840288a7f072afea1a743c45ee7b
commit a1e1c061a29a840288a7f072afea1a743c45ee7b
Author: Jim Meyering <meyering(a)redhat.com>
Date: Thu Nov 4 19:37:14 2010 +0100
prohibit creation of a bucket with one of the reserved names
diff --git a/rest.c b/rest.c
index 9ff3a54..f38f5ef 100644
--- a/rest.c
+++ b/rest.c
@@ -71,6 +71,7 @@ char *cfg_file = NULL;
static const char *const (reserved_name[]) = {"_default", "_new",
"_policy", "_query", NULL};
static const char *const (reserved_attr[]) = {"bucket", "date",
"etag", "key", "loc", NULL};
+static const char *const (reserved_bucket_name[]) = {"_new",
"_providers", NULL};
void
free_ms (my_state *ms)
@@ -937,6 +938,8 @@ typedef struct {
char *link;
} fake_bucket_t;
+/* FIXME: ensure that the RHS values here stay in sync with those
+ in reserved_bucket_name. */
static const fake_bucket_t fake_bucket_list[] = {
{ "bucket_factory", "_new" },
{ "provider_list", "_providers" },
@@ -1129,7 +1132,8 @@ create_bucket (char *name, my_state *ms)
{
int rc;
- if (is_reserved(name,reserved_name)) {
+ if (is_reserved(name, reserved_name)
+ || is_reserved(name, reserved_bucket_name)) {
return MHD_HTTP_BAD_REQUEST;
}
diff --git a/t/basic b/t/basic
index 7075cf1..a903648 100644
--- a/t/basic
+++ b/t/basic
@@ -291,6 +291,21 @@ for attr in bucket key date etag loc; do
grep ' 400$' bad_attr.err || fail=1
done
+# Ensure that an attempt to create a bucket with a reserved name fails.
+# FIXME: keep this list in sync with the one in rest.c:
+# grep '^static.*reserved_bucket_name' rest.c
+for b in _new _providers; do
+ invalid_bucket=http://localhost:$port/$b
+ curl -f -X PUT $invalid_bucket 2> invalid_bucket.err
+ # FIXME: change the code so that these are the same
+ case $b in
+ _new) exp=400;; # MHD_HTTP_BAD_REQUEST
+ *) exp=404;;
+ esac
+ cat invalid_bucket.err
+ grep " $exp$" invalid_bucket.err || fail=1
+done
+
# Make sure PUTting a file truncates.
echo hello | curl -f -T - $bucket/trunc_test || fail=1
echo bye | curl -f -T - $bucket/trunc_test || fail=1
-----------------------------------------------------------------------
Summary of changes:
meta.cpp | 58 +++++++++++++++++++++++++++++-----------------------------
rest.c | 12 ++++++++----
t/basic | 19 +++++++++++++++++--
3 files changed, 54 insertions(+), 35 deletions(-)
repo.or.cz automatic notification. Contact project admin jim(a)meyering.net
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
iwhd.git ("image warehouse daemon")