src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 294
277a5896a2ec
parent 292
7c31bcd5b4be
child 295
73a1243fce15
equal deleted inserted replaced
293:d3899857a81d 294:277a5896a2ec
131 // Update resource metadata 131 // Update resource metadata
132 // params: $1: resource_id 132 // params: $1: resource_id
133 // $2: contentlength 133 // $2: contentlength
134 static const char *sql_update_resource = "update Resource set contentlength = $2, lastmodified = now() where resource_id = $1;"; 134 static const char *sql_update_resource = "update Resource set contentlength = $2, lastmodified = now() where resource_id = $1;";
135 135
136 // Delete a resource
137 // params: $1: resource_id
138 static const char *sql_delete_res = "delete from Resource where resource_id = $1;";
139
136 VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) { 140 VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) {
137 // resourcepool is required 141 // resourcepool is required
138 char *resource_pool = pblock_findval("resourcepool", pb); 142 char *resource_pool = pblock_findval("resourcepool", pb);
139 if(!resource_pool) { 143 if(!resource_pool) {
140 log_ereport(LOG_MISCONFIG, "pg_vfs_create: missing resourcepool parameter"); 144 log_ereport(LOG_MISCONFIG, "pg_vfs_create: missing resourcepool parameter");
458 } 462 }
459 463
460 return ret; 464 return ret;
461 } 465 }
462 466
467 int pg_remove_file(
468 VFSContext *ctx,
469 PgVFS *pg,
470 int64_t resource_id,
471 Oid oid)
472 {
473 if(oid > 0) {
474 if(lo_unlink(pg->connection, oid) != 1) {
475 return 1; // error
476 }
477 }
478
479 char resid_str[32];
480 snprintf(resid_str, 32, "%" PRId64, resource_id);
481
482 const char* params[1] = { resid_str };
483 PGresult *result = PQexecParams(
484 pg->connection,
485 sql_delete_res,
486 1, // number of parameters
487 NULL,
488 params, // parameter value
489 NULL,
490 NULL,
491 0); // 0: result in text format
492
493 int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1;
494 PQclear(result);
495 return ret;
496 }
497
463 int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength) { 498 int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength) {
464 char resid_str[32]; 499 char resid_str[32];
465 char ctlen_str[32]; 500 char ctlen_str[32];
466 snprintf(resid_str, 32, "%" PRId64, resource_id); 501 snprintf(resid_str, 32, "%" PRId64, resource_id);
467 snprintf(ctlen_str, 32, "%" PRId64, contentlength); 502 snprintf(ctlen_str, 32, "%" PRId64, contentlength);
620 655
621 return 0; 656 return 0;
622 } 657 }
623 658
624 int pg_vfs_unlink(VFSContext *ctx, const char *path) { 659 int pg_vfs_unlink(VFSContext *ctx, const char *path) {
625 return 1; 660 VFS *vfs = ctx->vfs;
661 PgVFS *pg = vfs->instance;
662
663 const char *resname;
664 int64_t resource_id, parent_id;
665 resource_id = -1;
666 parent_id = -1;
667 WSBool iscollection;
668 Oid oid = 0;
669 if(pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL)) {
670 ctx->vfs_errno = ENOENT;
671 return 1;
672 }
673
674 if(iscollection) {
675 ctx->vfs_errno = EISDIR;
676 return 1;
677 }
678
679 return pg_remove_file(ctx, pg, resource_id, oid);
626 } 680 }
627 681
628 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) { 682 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) {
629 return 1; 683 return 1;
630 } 684 }

mercurial