src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 350
abba342112c2
parent 347
b6d71e504294
child 353
382d6c221807
--- a/src/server/plugins/postgresql/vfs.c	Mon May 09 20:56:44 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Tue May 10 19:13:01 2022 +0200
@@ -430,6 +430,15 @@
     char *parent_path = util_parent_path(path);
     if(!parent_path) return 1;
     
+    size_t pathlen = strlen(path);
+    char *pathf = NULL;
+    if(pathlen > 1 && path[pathlen-1] == '/') {
+        pathf = malloc(pathlen);
+        memcpy(pathf, path, pathlen);
+        pathf[pathlen-1] = 0; // remove trailing '/'
+        path = pathf;
+    }
+    
     const char *nodename = util_resource_name(path);
     
     // resolve the parent path
@@ -445,11 +454,13 @@
     FREE(parent_path);
     if(err) {
         ctx->vfs_errno = ENOENT;
+        if(pathf) free(pathf);
         return 1;
     }
     
     // parent path exists, check if it is a collection
     if(!iscollection) {
+        if(pathf) free(pathf);
         return 1;
     }
     
@@ -464,6 +475,8 @@
         ret = pg_create_res(pg, resid_str, nodename, new_resource_id, oid, resource_name, s);
     }
     
+    if(pathf) free(pathf);
+    
     if(res_parent_id) {
         // resource_id is still the id of the parent from previous pg_resolve_path call
         *res_parent_id = resource_id;

mercurial