src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 282
cfb588e27198
parent 281
e9dc53661df4
child 283
25e5b771677d
--- a/src/server/plugins/postgresql/vfs.c	Tue Feb 01 17:47:50 2022 +0100
+++ b/src/server/plugins/postgresql/vfs.c	Tue Feb 01 20:07:42 2022 +0100
@@ -221,24 +221,7 @@
         }
         
         if(s) {
-            memset(s, 0, sizeof(struct stat));
-            
-            s->st_ino = *resource_id;
-            if(iscol) {
-                s->st_mode |= 0x4000;
-            }
-            if(lastmodified) {
-                // TODO
-            }
-            if(creationdate) {
-                // TODO
-            }
-            if(contentlength) {
-                int64_t len;
-                if(util_strtoint(contentlength, &len)) {
-                    s->st_size = len;
-                }
-            }
+            pg_set_stat(s, iscol, lastmodified, creationdate, contentlength);
         }
     } else {
         ctx->vfs_errno = ENOENT;
@@ -250,6 +233,29 @@
 }
 
 
+void pg_set_stat(
+        struct stat *s,
+        const char *iscollection,
+        const char *lastmodified,
+        const char *creationdate,
+        const char *contentlength)
+{
+    memset(s, 0, sizeof(struct stat));
+    if(iscollection) {
+        WSBool iscol = iscollection[0] == 't' ? TRUE : FALSE;
+        if(iscol) {
+            s->st_mode |= 0x4000;
+        }
+    }
+    // TODO: lastmodified, creationdate
+    if(contentlength) {
+        int64_t len;
+        if(util_strtoint(contentlength, &len)) {
+            s->st_size = len;
+        }
+    }
+}
+
 /* -------------------------- VFS functions -------------------------- */
 
 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) {
@@ -338,42 +344,46 @@
 }
 
 int pg_vfs_mkdir(VFSContext *ctx, const char *path) {
-    
+    return 1;
 }
 
 int pg_vfs_unlink(VFSContext *ctx, const char *path) {
-    
+    return 1;
 }
 
 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) {
-    
+    return 1;
 }
 
 
 /* -------------------------- VFS_IO functions -------------------------- */
 
 ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) {
-    
+    return 0;
 }
 
 off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) {
-    
+    return 0;
 }
 
 void pg_vfs_io_close(SYS_FILE fd) {
+    pool_handle_t *pool = fd->ctx->pool;
+    PgFile *pg = fd->data;
     
+    pool_free(pool, pg);
+    pool_free(pool, fd);
 }
 
 
@@ -420,7 +430,15 @@
     
     entry->name = PQgetvalue(pg->result, pg->row, 1);
         
-    // TODO: stat
+    if(getstat) {
+        memset(&entry->stat, 0, sizeof(struct stat));
+        
+        char *iscollection = PQgetvalue(pg->result, pg->row, 2);
+        char *lastmodified = PQgetvalue(pg->result, pg->row, 3);
+        char *creationdate = PQgetvalue(pg->result, pg->row, 4);
+        char *contentlength = PQgetvalue(pg->result, pg->row, 5);
+        pg_set_stat(&entry->stat, iscollection, lastmodified, creationdate, contentlength);
+    }
 
     pg->row++;
     return 1;

mercurial