pg: fix proppatch not working for normal dead properties if extensions are enabled

Tue, 01 Nov 2022 15:59:28 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 01 Nov 2022 15:59:28 +0100
changeset 402
712aca08da7f
parent 401
d2bfd11d3f8f
child 403
0f678595d497

pg: fix proppatch not working for normal dead properties if extensions are enabled

src/server/plugins/postgresql/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/webdav.c	Tue Nov 01 15:39:21 2022 +0100
+++ b/src/server/plugins/postgresql/webdav.c	Tue Nov 01 15:59:28 2022 +0100
@@ -897,6 +897,14 @@
     return result;
 }
 
+
+static PgPropertyStoreExt* pg_proppatch_prop_get_ext(PgWebdavBackend *pgdav, WebdavProperty *property) {
+    UcxKey pkey = webdav_property_key((const char*)property->namespace->href, property->name);
+    PgPropertyStoreExt *ext = ucx_map_get(pgdav->repository->prop_ext, pkey);
+    free((void*)pkey.data);
+    return ext;
+}
+
 #define PG_PROPPATCH_EXT_SET 0
 #define PG_PROPPATCH_EXT_REMOVE 1
 
@@ -905,29 +913,25 @@
         PgWebdavBackend *pgdav,
         PgProppatch *proppatch,
         WebdavProperty *property,
+        PgPropertyStoreExt *ext,
         int proppatch_op)
 {
-    UcxKey pkey = webdav_property_key((const char*)property->namespace->href, property->name);
-    PgPropertyStoreExt *ext = ucx_map_get(pgdav->repository->prop_ext, pkey);
-    free((void*)pkey.data);
-    if(ext) {
-        PgProppatchExtProp *ext_prop = pool_malloc(pool, sizeof(PgProppatchExtProp));
-        if(!ext_prop) {
-            return 1;
-        }
-        ext_prop->column = ext;
-        ext_prop->property = property;
+    PgProppatchExtProp *ext_prop = pool_malloc(pool, sizeof(PgProppatchExtProp));
+    if(!ext_prop) {
+        return 1;
+    }
+    ext_prop->column = ext;
+    ext_prop->property = property;
 
-        UcxAllocator a = util_pool_allocator(pool);
-        proppatch->ext[ext->tableindex].isused = TRUE;
-        
-        UcxList **list = proppatch_op == PG_PROPPATCH_EXT_REMOVE
-                            ? &proppatch->ext[ext->tableindex].remove
-                            : &proppatch->ext[ext->tableindex].set;
-        *list = ucx_list_append_a(&a, *list, ext_prop);
+    UcxAllocator a = util_pool_allocator(pool);
+    proppatch->ext[ext->tableindex].isused = TRUE;
 
-        proppatch->extensions_used = TRUE;
-    }
+    UcxList **list = proppatch_op == PG_PROPPATCH_EXT_REMOVE
+                        ? &proppatch->ext[ext->tableindex].remove
+                        : &proppatch->ext[ext->tableindex].set;
+    *list = ucx_list_append_a(&a, *list, ext_prop);
+
+    proppatch->extensions_used = TRUE;
     
     return 0;
 }
@@ -945,7 +949,10 @@
     
     // check if the property belongs to an extension
     if(proppatch->ext && ns) {
-        return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, PG_PROPPATCH_EXT_SET);
+        PgPropertyStoreExt *ext = pg_proppatch_prop_get_ext(pgdav, property);
+        if(ext) {
+            return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, ext, PG_PROPPATCH_EXT_SET);
+        } // else: property is not stored in an extension table, continue with normal property store
     }
     
     char *resource_id_str = userdata;
@@ -1006,7 +1013,10 @@
     
     // check if the property belongs to an extension
     if(proppatch->ext && ns) {
-        return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, PG_PROPPATCH_EXT_REMOVE);
+        PgPropertyStoreExt *ext = pg_proppatch_prop_get_ext(pgdav, property);
+        if(ext) {
+            return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, ext, PG_PROPPATCH_EXT_REMOVE);
+        } // else: property is not stored in an extension table, continue with normal property store
     }
     
     char *resource_id_str = userdata;

mercurial