Thu, 08 Sep 2022 17:34:16 +0200
disable pg large object IO functions for collections
--- a/src/server/plugins/postgresql/resource.c Sat Aug 27 11:57:27 2022 +0200 +++ b/src/server/plugins/postgresql/resource.c Thu Sep 08 17:34:16 2022 +0200 @@ -126,7 +126,10 @@ int pg_resourcepool_finish(PgResourcePool *pg, PgResource *res) { PGresult *result = PQexec(res->connection, "COMMIT"); - PQclear(result); // TODO: handle error + if(PQresultStatus(result) != PGRES_COMMAND_OK) { + log_ereport(LOG_FAILURE, "pg_dav_proppatch_finish: COMMIT failed failed: %s", PQerrorMessage(res->connection)); + } + PQclear(result); return 0; }
--- a/src/server/plugins/postgresql/vfs.c Sat Aug 27 11:57:27 2022 +0200 +++ b/src/server/plugins/postgresql/vfs.c Thu Sep 08 17:34:16 2022 +0200 @@ -812,18 +812,21 @@ ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; return lo_read(pgvfs->connection, pg->fd, buf, nbyte); } ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; return lo_write(pgvfs->connection, pg->fd, buf, nbyte); } ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; if(lo_lseek64(pgvfs->connection, pg->fd, offset, SEEK_SET) == -1) { return -1; } @@ -833,6 +836,7 @@ ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; if(lo_lseek64(pgvfs->connection, pg->fd, offset, SEEK_SET) == -1) { return -1; } @@ -842,12 +846,14 @@ off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; return lo_lseek64(pgvfs->connection, pg->fd, offset, whence); } off_t pg_vfs_io_tell(SYS_FILE fd) { PgVFS *pgvfs = fd->ctx->vfs->instance; PgFile *pg = fd->data; + if(pg->fd < 0) return-1; return lo_tell64(pgvfs->connection, pg->fd); }
--- a/src/server/plugins/postgresql/webdav.c Sat Aug 27 11:57:27 2022 +0200 +++ b/src/server/plugins/postgresql/webdav.c Thu Sep 08 17:34:16 2022 +0200 @@ -1197,6 +1197,11 @@ snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); params[0] = resource_id_str; + printf("insert\n\n"); + printf("arg0: %s\narg1: %s\n", params[0], params[1]); + printf("%s\n\n", sql->space); + + PGresult *result = PQexecParams( pgdav->connection, sql->space, @@ -1213,6 +1218,7 @@ if(PQresultStatus(result) == PGRES_COMMAND_OK) { // command ok, check if any row was updated char *nrows_affected = PQcmdTuples(result); + printf("insert nrows: %s\n", nrows_affected); if(nrows_affected[0] == '1') { ret = 0; } else { @@ -1222,7 +1228,6 @@ log_ereport(LOG_FAILURE, "pg: extension row insert failed: %s", PQresultErrorMessage(result)); } - PQclear(result); return ret; @@ -1247,6 +1252,8 @@ snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); params[0] = resource_id_str; + printf("update\n"); + PGresult *result = PQexecParams( pgdav->connection, sql->space, @@ -1263,6 +1270,7 @@ if(PQresultStatus(result) == PGRES_COMMAND_OK) { // command ok, check if any row was updated char *nrows_affected = PQcmdTuples(result); + printf("nrows: %s\n", nrows_affected); if(nrows_affected[0] == '1') { ret = 0; } else if(nrows_affected[0] == '0') { @@ -1415,6 +1423,7 @@ PgWebdavBackend *pgdav = request->dav->instance; int ret = 0; if(!commit) { + log_ereport(LOG_VERBOSE, "proppatch: rollback"); PGresult *result = PQexec(pgdav->connection, "rollback to savepoint proppatch;"); if(PQresultStatus(result) != PGRES_COMMAND_OK) { log_ereport(LOG_FAILURE, "pg_dav_proppatch_finish: rollback failed: %s", PQerrorMessage(pgdav->connection));
--- a/src/server/util/util.c Sat Aug 27 11:57:27 2022 +0200 +++ b/src/server/util/util.c Thu Sep 08 17:34:16 2022 +0200 @@ -462,6 +462,18 @@ return parent; } +NSAPI_PUBLIC char* util_parent_path_pool(pool_handle_t *pool, const char *path) { + // maybe we can unify this function with util_parent_path + char *name = (char*)util_resource_name((char*)path); + size_t namelen = strlen(name); + size_t pathlen = strlen(path); + size_t parentlen = pathlen - namelen; + char *parent = pool_malloc(pool, parentlen + 1); + memcpy(parent, path, parentlen); + parent[parentlen] = '\0'; + return parent; +} + /* ------------------------------ util_itoa ------------------------------- */ /* NSAPI_PUBLIC int util_itoa(int i, char *a)
--- a/src/server/util/util.h Sat Aug 27 11:57:27 2022 +0200 +++ b/src/server/util/util.h Thu Sep 08 17:34:16 2022 +0200 @@ -208,6 +208,7 @@ NSAPI_PUBLIC int util_strtoint(const char *str, int64_t *value); NSAPI_PUBLIC const char* util_resource_name(const char *url); NSAPI_PUBLIC char* util_parent_path(const char *path); +NSAPI_PUBLIC char* util_parent_path_pool(pool_handle_t *pool, const char *path); // TODO //NSAPI_PUBLIC PRIntervalTime INTutil_getinterval(const char *v, PRIntervalTime def);