X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=blob.c;h=031f6ae3a76c2e29cd429135f3b73e60c8bc38d8;hb=f3c29f0f4c000f3d860c0da31d4387afc798a77a;hp=617e94f1edd03113d8d194b32c07af2bc25b9b3b;hpb=a08d65fa0cbc5f79632be742b818f621f3dc48d0;p=paraslash.git diff --git a/blob.c b/blob.c index 617e94f1..031f6ae3 100644 --- a/blob.c +++ b/blob.c @@ -336,9 +336,21 @@ static int com_addblob_callback(struct osl_table *table, ret = osl_add_row(table, objs); if (ret < 0) return ret; - } else { /* get id of the dummy row and increment it */ + } else { + /* check if name already exists */ struct osl_row *row; - struct osl_object obj = {.data = "", .size = 1}; + struct osl_object obj = {.data = name, .size = name_len}; + ret = osl_get_row(table, BLOBCOL_NAME, &obj, &row); + if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND) + return ret; + if (ret >= 0) { /* we already have a blob with this name */ + obj.data = name + name_len; + obj.size = query->size - name_len; + return osl_update_object(table, row, BLOBCOL_DEF, &obj); + } + /* new blob, get id of the dummy row and increment it */ + obj.data = ""; + obj.size = 1; ret = osl_get_row(table, BLOBCOL_NAME, &obj, &row); if (ret < 0) return ret; @@ -440,8 +452,8 @@ static int blob_get_name_by_id(struct osl_table *table, uint32_t id, return blob_get_name_by_id(table_name ## _table, id, name); \ } -static int blob_get_name_and_def_by_row(struct osl_table *table, struct osl_row *row, - char **name, struct osl_object *def) +static int blob_get_name_and_def_by_row(struct osl_table *table, + const struct osl_row *row, char **name, struct osl_object *def) { struct osl_object obj; int ret = osl_get_object(table, row, BLOBCOL_NAME, &obj); @@ -452,7 +464,7 @@ static int blob_get_name_and_def_by_row(struct osl_table *table, struct osl_row } /** Define the \p get_name_and_def_by_row function for this blob type. */ #define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \ - int cmd_prefix ## _get_name_and_def_by_row(struct osl_row *row, \ + int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \ char **name, struct osl_object *def) \ { \ return blob_get_name_and_def_by_row(table_name ## _table, \ @@ -474,11 +486,9 @@ static int blob_init(struct osl_table **table, int ret; desc->dir = db; ti->desc = desc; - ret = osl_open_table(ti->desc, &ti->table); - if (ret >= 0) { - *table = ti->table; + ret = osl_open_table(ti->desc, table); + if (ret >= 0) return ret; - } *table = NULL; return ret == -E_NOENT? 1 : ret; }