[dovecot-cvs] dovecot/src/lib-dict dict-private.h, 1.4, 1.5 dict-sql.c, 1.10, 1.11 dict.c, 1.8, 1.9
cras at dovecot.org
cras at dovecot.org
Sun Jul 30 21:06:12 EEST 2006
Update of /var/lib/cvs/dovecot/src/lib-dict
In directory talvi:/tmp/cvs-serv9312
Modified Files:
dict-private.h dict-sql.c dict.c
Log Message:
If invalid key is given to dict_set() or dict_atomic_inc() fail the whole
transaction in commit. Keep track of changes that are actually done, so if
nothing has changed in transaction don't even bother to commit it.
Index: dict-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict-private.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dict-private.h 31 Jan 2006 06:05:22 -0000 1.4
+++ dict-private.h 30 Jul 2006 18:06:09 -0000 1.5
@@ -40,6 +40,8 @@
struct dict_transaction_context {
struct dict *dict;
+
+ unsigned int changed:1;
};
#endif
Index: dict-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict-sql.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dict-sql.c 16 Jun 2006 09:54:14 -0000 1.10
+++ dict-sql.c 30 Jul 2006 18:06:09 -0000 1.11
@@ -31,6 +31,9 @@
struct dict_transaction_context ctx;
struct sql_transaction_context *sql_ctx;
+
+ unsigned int failed:1;
+ unsigned int changed:1;
};
static int sql_dict_read_config(struct sql_dict *dict, const char *path)
@@ -275,9 +278,17 @@
const char *error;
int ret;
- ret = sql_transaction_commit_s(&ctx->sql_ctx, &error);
- if (ret < 0)
- i_error("sql dict: commit failed: %s", error);
+ if (ctx->failed) {
+ sql_transaction_rollback(&ctx->sql_ctx);
+ ret = -1;
+ } else if (_ctx->changed) {
+ ret = sql_transaction_commit_s(&ctx->sql_ctx, &error);
+ if (ret < 0)
+ i_error("sql dict: commit failed: %s", error);
+ } else {
+ /* nothing to be done */
+ ret = 0;
+ }
i_free(ctx);
return ret;
}
@@ -287,7 +298,8 @@
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
- sql_transaction_rollback(&ctx->sql_ctx);
+ if (_ctx->changed)
+ sql_transaction_rollback(&ctx->sql_ctx);
i_free(ctx);
}
@@ -300,8 +312,11 @@
const char *query;
bool priv;
- if (sql_path_fix(&key, &priv) < 0)
+ if (sql_path_fix(&key, &priv) < 0) {
+ i_error("sql dict: Invalid key: %s", key);
+ ctx->failed = TRUE;
return;
+ }
t_push();
if (priv) {
@@ -338,8 +353,11 @@
const char *query;
bool priv;
- if (sql_path_fix(&key, &priv) < 0)
+ if (sql_path_fix(&key, &priv) < 0) {
+ i_error("sql dict: Invalid key: %s", key);
+ ctx->failed = TRUE;
return;
+ }
t_push();
if (priv) {
Index: dict.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dict.c 30 Jul 2006 18:03:18 -0000 1.8
+++ dict.c 30 Jul 2006 18:06:09 -0000 1.9
@@ -125,11 +125,14 @@
const char *key, const char *value)
{
ctx->dict->v.set(ctx, key, value);
+ ctx->changed = TRUE;
}
void dict_atomic_inc(struct dict_transaction_context *ctx,
const char *key, long long diff)
{
- if (diff != 0)
+ if (diff != 0) {
ctx->dict->v.atomic_inc(ctx, key, diff);
+ ctx->changed = TRUE;
+ }
}
More information about the dovecot-cvs
mailing list