load properties after resource creation

Thu, 14 Nov 2024 22:28:36 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 14 Nov 2024 22:28:36 +0100
changeset 84
57a359c52617
parent 83
a612adaee43d
child 85
44ebbb4c8a13

load properties after resource creation

application/davcontroller.c file | annotate | diff | comparison | revisions
--- a/application/davcontroller.c	Thu Nov 14 17:25:23 2024 +0100
+++ b/application/davcontroller.c	Thu Nov 14 22:28:36 2024 +0100
@@ -1101,6 +1101,10 @@
     int res_index;
     int result;
     char *errormsg;
+    
+    time_t result_lastmodified;
+    uint64_t result_contentlength;
+    char *result_contenttype;
 } DavPathOpResult;
 
 static int uithr_pathop_delete_error(void *data) {
@@ -1152,12 +1156,16 @@
     if (result->browser->current == result->collection && result->browser->res_counter == result->collection_ctn) {
         DavResource *res = dav_resource_new(result->browser->sn, result->path);
         res->iscollection = result->iscollection;
+        res->lastmodified = result->result_lastmodified;
+        res->contentlength = result->result_contentlength;
+        res->contenttype = result->result_contenttype ? dav_session_strdup(res->session, result->result_contenttype) : NULL;
         // TODO: add the resource at the correct position or sort the list after append
         ui_list_append(result->browser->resources, res);
         result->browser->resources->update(result->browser->resources, 0);
     }
 
     free(result->path);
+    free(result->result_contenttype);
     free(result);
     return 0;
 }
@@ -1180,6 +1188,9 @@
             result->res_index = op->list_indices[i];
             result->errormsg = NULL;
             result->iscollection = op->iscollection;
+            result->result_lastmodified = 0;
+            result->result_contentlength = 0;
+            result->result_contenttype = NULL;
     
             if (op->op == DAV_PATH_OP_DELETE) {
                 ui_threadfunc result_callback = uithr_pathop_delete_sucess;
@@ -1194,6 +1205,14 @@
                 if (dav_create(res)) {
                     result->errormsg = op->sn->errorstr ? strdup(op->sn->errorstr) : NULL;
                     result_callback = uithr_pathop_create_resource_error;
+                } else {
+                    // try to load some basic resource properties 
+                    // we don't care about the result, if it fails,
+                    // we just don't have the new properties
+                    dav_load_prop(res, NULL, 0);
+                    result->result_lastmodified = res->lastmodified;
+                    result->result_contentlength = res->contentlength;
+                    result->result_contenttype = res->contenttype ? strdup(res->contenttype) : NULL;
                 }
                 ui_call_mainthread(result_callback, result);
             } 

mercurial