set error status code directly in vfs_* calls webdav

Fri, 04 Feb 2022 18:41:40 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 04 Feb 2022 18:41:40 +0100
branch
webdav
changeset 286
864e2d701dd4
parent 285
96e53bd94958
child 287
a171da778817

set error status code directly in vfs_* calls

src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
src/server/public/vfs.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/vfs.c	Fri Feb 04 18:12:23 2022 +0100
+++ b/src/server/daemon/vfs.c	Fri Feb 04 18:41:40 2022 +0100
@@ -124,6 +124,7 @@
     ctx->aclreqaccess = rq->aclreqaccess;
     ctx->pool = sn->pool;
     ctx->vfs_errno = 0;
+    ctx->error_response_set = 0;
     return ctx;
 }
 
@@ -144,7 +145,10 @@
         }
     }
     SYS_FILE file = ctx->vfs->open(ctx, path, oflags);
-    ctx->aclreqaccess = m; // restore original access mask
+    ctx->aclreqaccess = m; // restore original access mask 
+    if(!file && ctx) {
+        sys_set_error_status(ctx);
+    }
     return file;
 }
 
@@ -178,6 +182,9 @@
     }
     int ret = ctx->vfs->stat(ctx, path, buf);
     ctx->aclreqaccess = m; // restore original access mask
+    if(ret && ctx) {
+        sys_set_error_status(ctx);
+    }
     return ret;
 }
 
@@ -186,7 +193,11 @@
     WS_ASSERT(fd);
     WS_ASSERT(buf);
     
-    return ctx->vfs->fstat(ctx, fd, buf);
+    int ret = ctx->vfs->fstat(ctx, fd, buf);
+    if(ret && ctx) {
+        sys_set_error_status(ctx);
+    }
+    return ret;
 }
 
 void vfs_close(SYS_FILE fd) {
@@ -218,6 +229,9 @@
     }
     VFS_DIR dir = ctx->vfs->opendir(ctx, path);
     ctx->aclreqaccess = m; // restore original access mask
+    if(!dir && ctx) {
+        sys_set_error_status(ctx);
+    }
     return dir;
 }
 
@@ -239,6 +253,9 @@
     }
     VFS_DIR dir = ctx->vfs->fdopendir(ctx, fd);
     ctx->aclreqaccess = m; // restore original access mask
+    if(!dir && ctx) {
+        sys_set_error_status(ctx);
+    }
     return dir;
 }
 
@@ -305,6 +322,9 @@
     }
     int ret = op(ctx, path);
     ctx->aclreqaccess = m; // restore original access mask
+    if(ret && ctx) {
+        sys_set_error_status(ctx);
+    }
     return ret;
 }
 
@@ -593,9 +613,10 @@
 }
 
 void sys_set_error_status(VFSContext *ctx) {
-    if(ctx->sn && ctx->rq) {
+    if(ctx->sn && ctx->rq && !ctx->error_response_set) {
         int status = util_errno2status(ctx->vfs_errno);
         protocol_status(ctx->sn, ctx->rq, status, NULL);
+        ctx->error_response_set = TRUE;
     }
 }
 
--- a/src/server/public/vfs.h	Fri Feb 04 18:12:23 2022 +0100
+++ b/src/server/public/vfs.h	Fri Feb 04 18:41:40 2022 +0100
@@ -69,6 +69,7 @@
     ACLListHandle *acllist;
     uint32_t aclreqaccess;
     int vfs_errno;
+    WSBool error_response_set;
 };
 
 struct VFSFile {

mercurial