]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
addblob: Overwrite existing blobs.
authorAndre Noll <maan@systemlinux.org>
Wed, 26 Sep 2007 09:29:07 +0000 (11:29 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 26 Sep 2007 09:29:07 +0000 (11:29 +0200)
Previously, an attempt to add a blob with a name of an already
existing blob failed (siltenly). Just replace the existing blob
with the new contents instead.

blob.c

diff --git a/blob.c b/blob.c
index 74b1c4f5a3bbe8cec2d6df5ebcac477025bb9c18..84dec32ddffbb6bc5777caa79b8599fde4fa5350 100644 (file)
--- 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;