add support for O_TRUNC in pg_vfs_open webdav

Sun, 08 May 2022 10:46:56 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 08 May 2022 10:46:56 +0200
branch
webdav
changeset 341
52831b82b3fd
parent 340
03c052d9a097
child 342
ebd1e67c3d5f

add support for O_TRUNC in pg_vfs_open

src/server/plugins/postgresql/vfs.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/vfs.c	Sun May 08 10:41:27 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Sun May 08 10:46:56 2022 +0200
@@ -584,6 +584,21 @@
             lo_mode = INV_WRITE;
         }
         fd = lo_open(pg->connection, oid, lo_mode);
+        int err = 0;
+        if(fd < 0) {
+            err = 1;
+        } else if((oflags & O_TRUNC) == O_TRUNC) {
+            if(lo_truncate(pg->connection, fd, 0)) {
+                lo_close(pg->connection, fd);
+                err = 1;
+            }
+        }
+        
+        if(err) {
+            pool_free(ctx->pool, file);
+            pool_free(ctx->pool, pgfile);
+            return NULL;
+        }
     }
     
     pgfile->iscollection = iscollection;

mercurial