# HG changeset patch # User Olaf Wintermann # Date 1650295905 -7200 # Node ID 14cd7137a3a88e927494ad19687ca675c574fd4f # Parent 78e92337fa4ed92e1a93ab11b7a509abc1877d69 handle sql error in pg_remove_res diff -r 78e92337fa4e -r 14cd7137a3a8 src/server/plugins/postgresql/pgtest.c --- a/src/server/plugins/postgresql/pgtest.c Mon Apr 18 13:17:50 2022 +0200 +++ b/src/server/plugins/postgresql/pgtest.c Mon Apr 18 17:31:45 2022 +0200 @@ -314,8 +314,8 @@ r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); UCX_TEST_ASSERT(r == 0, "rmdir failed");; - //r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); - //UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); + r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); + UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); UCX_TEST_ASSERT(r == 0, "unlink failed"); diff -r 78e92337fa4e -r 14cd7137a3a8 src/server/plugins/postgresql/vfs.c --- a/src/server/plugins/postgresql/vfs.c Mon Apr 18 13:17:50 2022 +0200 +++ b/src/server/plugins/postgresql/vfs.c Mon Apr 18 17:31:45 2022 +0200 @@ -470,6 +470,12 @@ int64_t resource_id, Oid oid) { + // create transaction savepoint + PGresult *result = PQexec(pg->connection, "savepoint del_res;"); + if(PQresultStatus(result) != PGRES_COMMAND_OK) { + return 1; + } + if(oid > 0) { if(lo_unlink(pg->connection, oid) != 1) { return 1; // error @@ -480,7 +486,7 @@ snprintf(resid_str, 32, "%" PRId64, resource_id); const char* params[1] = { resid_str }; - PGresult *result = PQexecParams( + result = PQexecParams( pg->connection, sql_delete_res, 1, // number of parameters @@ -490,9 +496,12 @@ NULL, 0); // 0: result in text format - int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; - if(ret == 1) { - fprintf(stdout, "%s", PQerrorMessage(pg->connection)); + int ret = 0; + if(PQresultStatus(result) != PGRES_COMMAND_OK) { + ret = 1; + // restore savepoint + result = PQexec(pg->connection, "rollback to savepoint del_res;"); + PQclear(result); } PQclear(result); return ret; @@ -516,7 +525,7 @@ 0); // 0: result in text format int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; - PQclear(result); + PQclear(result); return ret; }