change pg_resolve_path signature to be useable without VFS webdav

Thu, 21 Apr 2022 17:16:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 21 Apr 2022 17:16:49 +0200
branch
webdav
changeset 305
4db64fe30588
parent 304
33911d44111d
child 306
e03737cea6e2

change pg_resolve_path signature to be useable without VFS

src/server/plugins/postgresql/vfs.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/vfs.h file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/vfs.c	Wed Apr 20 17:48:33 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Thu Apr 21 17:16:49 2022 +0200
@@ -182,14 +182,15 @@
 
 
 int pg_resolve_path(
-        VFSContext *ctx,
+        PGconn *connection,
         const char *path,
         int64_t *parent_id,
         int64_t *resource_id,
         Oid *oid,
         const char **resource_name,
         WSBool *iscollection,
-        struct stat *s)
+        struct stat *s,
+        int *res_errno)
 {
     // basic path validation
     if(!path) return 1;
@@ -210,12 +211,9 @@
     // get last node of path
     *resource_name = util_resource_name(path);
     
-    VFS *vfs = ctx->vfs;
-    PgVFS *pg = vfs->instance;
-    
     const char *sql = pathlen == 1 ? sql_get_root : sql_resolve_path;  
     PGresult *result = PQexecParams(
-            pg->connection,
+            connection,
             sql,
             1,     // number of parameters
             NULL,
@@ -263,8 +261,8 @@
         if(s) {
             pg_set_stat(s, iscol, lastmodified, creationdate, contentlength);
         }
-    } else {
-        ctx->vfs_errno = ENOENT;
+    } else if(res_errno) {
+        *res_errno = ENOENT;
     }
     
     PQclear(result);
@@ -432,7 +430,7 @@
     WSBool iscollection;
     Oid unused_oid = 0;
     
-    int err = pg_resolve_path(ctx, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL);
+    int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, &ctx->vfs_errno);
     FREE(parent_path);
     if(err) {
         return 1;
@@ -552,7 +550,7 @@
     WSBool iscollection;
     struct stat s;
     Oid oid = 0;
-    if(pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s)) {
+    if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, &ctx->vfs_errno)) {
         if((oflags & O_CREAT) == O_CREAT) {
             if(pg_create_file(ctx, pg, path, &resource_id, &parent_id, &oid, &resname, &s, FALSE)) {
                 return NULL;
@@ -605,10 +603,13 @@
 }
 
 int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) {
+    VFS *vfs = ctx->vfs;
+    PgVFS *pg = vfs->instance;
+    
     int64_t parent_id, resource_id;
     const char *resname;
     WSBool iscollection;
-    return pg_resolve_path(ctx, path, &parent_id, &resource_id, NULL, &resname, &iscollection, buf);
+    return pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, buf, &ctx->vfs_errno);
 }
 
 int pg_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) {
@@ -666,7 +667,7 @@
     WSBool iscollection;
     struct stat s;
     Oid oid = 0;
-    if(!pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s)) {
+    if(!pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, &ctx->vfs_errno)) {
         ctx->vfs_errno = EEXIST;
         return 1;
     }
@@ -688,8 +689,7 @@
     parent_id = -1;
     WSBool iscollection;
     Oid oid = 0;
-    if(pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL)) {
-        ctx->vfs_errno = ENOENT;
+    if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL, &ctx->vfs_errno)) {
         return 1;
     }
     
@@ -710,8 +710,7 @@
     resource_id = -1;
     parent_id = -1;
     WSBool iscollection;
-    if(pg_resolve_path(ctx, path, &parent_id, &resource_id, NULL, &resname, &iscollection, NULL)) {
-        ctx->vfs_errno = ENOENT;
+    if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, NULL, &ctx->vfs_errno)) {
         return 1;
     }
     
--- a/src/server/plugins/postgresql/vfs.h	Wed Apr 20 17:48:33 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.h	Thu Apr 21 17:16:49 2022 +0200
@@ -72,17 +72,18 @@
  * 
  * Only absolute paths are supported, therefore path[0] must be '/'
  * 
- * If the resource is not found, ctx->vfs_errno is set to ENOENT
+ * If the resource is not found, res_errno is set to ENOENT
  */
 int pg_resolve_path(
-        VFSContext *ctx,
+        PGconn *connection,
         const char *path,
         int64_t *parent_id,
         int64_t *resource_id,
         Oid *oid,
         const char **resource_name,
         WSBool *iscollection,
-        struct stat *s);
+        struct stat *s,
+        int *res_errno);
 
 void pg_set_stat(
         struct stat *s,

mercurial