src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 296
78e92337fa4e
parent 295
73a1243fce15
child 297
14cd7137a3a8
--- a/src/server/plugins/postgresql/vfs.c	Mon Apr 18 11:49:37 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Mon Apr 18 13:17:50 2022 +0200
@@ -135,7 +135,7 @@
 
 // Delete a resource
 // params: $1: resource_id
-static const char *sql_delete_res = "delete from Resource where resource_id = $1;";
+static const char *sql_delete_res = "delete from Resource where parent_id is not null and resource_id = $1;";
 
 VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) {
     // resourcepool is required
@@ -464,7 +464,7 @@
     return ret;
 }
 
-int pg_remove_file(
+int pg_remove_res(
         VFSContext *ctx,
         PgVFS *pg,
         int64_t resource_id,
@@ -489,9 +489,12 @@
             NULL,
             NULL,
             0);    // 0: result in text format
-    
+      
     int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1;
-    PQclear(result);
+    if(ret == 1) {
+        fprintf(stdout, "%s", PQerrorMessage(pg->connection));
+    }
+    PQclear(result); 
     return ret;
 }
 
@@ -676,11 +679,29 @@
         return 1;
     }
     
-    return pg_remove_file(ctx, pg, resource_id, oid);
+    return pg_remove_res(ctx, pg, resource_id, oid);
 }
 
 int pg_vfs_rmdir(VFSContext *ctx, const char *path) {
+    VFS *vfs = ctx->vfs;
+    PgVFS *pg = vfs->instance;
     
+    const char *resname;
+    int64_t resource_id, parent_id;
+    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;
+        return 1;
+    }
+    
+    if(!iscollection) {
+        ctx->vfs_errno = ENOTDIR;
+        return 1;
+    }
+    
+    return pg_remove_res(ctx, pg, resource_id, 0);
 }
 
 

mercurial