src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 305
4db64fe30588
parent 304
33911d44111d
child 311
e676ed461b5b
equal deleted inserted replaced
304:33911d44111d 305:4db64fe30588
180 return vfs; 180 return vfs;
181 } 181 }
182 182
183 183
184 int pg_resolve_path( 184 int pg_resolve_path(
185 VFSContext *ctx, 185 PGconn *connection,
186 const char *path, 186 const char *path,
187 int64_t *parent_id, 187 int64_t *parent_id,
188 int64_t *resource_id, 188 int64_t *resource_id,
189 Oid *oid, 189 Oid *oid,
190 const char **resource_name, 190 const char **resource_name,
191 WSBool *iscollection, 191 WSBool *iscollection,
192 struct stat *s) 192 struct stat *s,
193 int *res_errno)
193 { 194 {
194 // basic path validation 195 // basic path validation
195 if(!path) return 1; 196 if(!path) return 1;
196 size_t pathlen = strlen(path); 197 size_t pathlen = strlen(path);
197 if(pathlen == 0) return 1; 198 if(pathlen == 0) return 1;
208 } 209 }
209 210
210 // get last node of path 211 // get last node of path
211 *resource_name = util_resource_name(path); 212 *resource_name = util_resource_name(path);
212 213
213 VFS *vfs = ctx->vfs;
214 PgVFS *pg = vfs->instance;
215
216 const char *sql = pathlen == 1 ? sql_get_root : sql_resolve_path; 214 const char *sql = pathlen == 1 ? sql_get_root : sql_resolve_path;
217 PGresult *result = PQexecParams( 215 PGresult *result = PQexecParams(
218 pg->connection, 216 connection,
219 sql, 217 sql,
220 1, // number of parameters 218 1, // number of parameters
221 NULL, 219 NULL,
222 &path, // parameter value 220 &path, // parameter value
223 NULL, 221 NULL,
261 } 259 }
262 260
263 if(s) { 261 if(s) {
264 pg_set_stat(s, iscol, lastmodified, creationdate, contentlength); 262 pg_set_stat(s, iscol, lastmodified, creationdate, contentlength);
265 } 263 }
266 } else { 264 } else if(res_errno) {
267 ctx->vfs_errno = ENOENT; 265 *res_errno = ENOENT;
268 } 266 }
269 267
270 PQclear(result); 268 PQclear(result);
271 269
272 return ret; 270 return ret;
430 resource_id = -1; 428 resource_id = -1;
431 parent_id = -1; 429 parent_id = -1;
432 WSBool iscollection; 430 WSBool iscollection;
433 Oid unused_oid = 0; 431 Oid unused_oid = 0;
434 432
435 int err = pg_resolve_path(ctx, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL); 433 int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, &ctx->vfs_errno);
436 FREE(parent_path); 434 FREE(parent_path);
437 if(err) { 435 if(err) {
438 return 1; 436 return 1;
439 } 437 }
440 438
550 resource_id = -1; 548 resource_id = -1;
551 parent_id = -1; 549 parent_id = -1;
552 WSBool iscollection; 550 WSBool iscollection;
553 struct stat s; 551 struct stat s;
554 Oid oid = 0; 552 Oid oid = 0;
555 if(pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s)) { 553 if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, &ctx->vfs_errno)) {
556 if((oflags & O_CREAT) == O_CREAT) { 554 if((oflags & O_CREAT) == O_CREAT) {
557 if(pg_create_file(ctx, pg, path, &resource_id, &parent_id, &oid, &resname, &s, FALSE)) { 555 if(pg_create_file(ctx, pg, path, &resource_id, &parent_id, &oid, &resname, &s, FALSE)) {
558 return NULL; 556 return NULL;
559 } 557 }
560 iscollection = 0; 558 iscollection = 0;
603 601
604 return file; 602 return file;
605 } 603 }
606 604
607 int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { 605 int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) {
606 VFS *vfs = ctx->vfs;
607 PgVFS *pg = vfs->instance;
608
608 int64_t parent_id, resource_id; 609 int64_t parent_id, resource_id;
609 const char *resname; 610 const char *resname;
610 WSBool iscollection; 611 WSBool iscollection;
611 return pg_resolve_path(ctx, path, &parent_id, &resource_id, NULL, &resname, &iscollection, buf); 612 return pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, buf, &ctx->vfs_errno);
612 } 613 }
613 614
614 int pg_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { 615 int pg_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) {
615 PgFile *pgfile = fd->data; 616 PgFile *pgfile = fd->data;
616 memcpy(buf, &pgfile->s, sizeof(struct stat)); 617 memcpy(buf, &pgfile->s, sizeof(struct stat));
664 resource_id = -1; 665 resource_id = -1;
665 parent_id = -1; 666 parent_id = -1;
666 WSBool iscollection; 667 WSBool iscollection;
667 struct stat s; 668 struct stat s;
668 Oid oid = 0; 669 Oid oid = 0;
669 if(!pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s)) { 670 if(!pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, &s, &ctx->vfs_errno)) {
670 ctx->vfs_errno = EEXIST; 671 ctx->vfs_errno = EEXIST;
671 return 1; 672 return 1;
672 } 673 }
673 674
674 if(pg_create_file(ctx, pg, path, NULL, NULL, NULL, NULL, NULL, TRUE)) { 675 if(pg_create_file(ctx, pg, path, NULL, NULL, NULL, NULL, NULL, TRUE)) {
686 int64_t resource_id, parent_id; 687 int64_t resource_id, parent_id;
687 resource_id = -1; 688 resource_id = -1;
688 parent_id = -1; 689 parent_id = -1;
689 WSBool iscollection; 690 WSBool iscollection;
690 Oid oid = 0; 691 Oid oid = 0;
691 if(pg_resolve_path(ctx, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL)) { 692 if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, &oid, &resname, &iscollection, NULL, &ctx->vfs_errno)) {
692 ctx->vfs_errno = ENOENT;
693 return 1; 693 return 1;
694 } 694 }
695 695
696 if(iscollection) { 696 if(iscollection) {
697 ctx->vfs_errno = EISDIR; 697 ctx->vfs_errno = EISDIR;
708 const char *resname; 708 const char *resname;
709 int64_t resource_id, parent_id; 709 int64_t resource_id, parent_id;
710 resource_id = -1; 710 resource_id = -1;
711 parent_id = -1; 711 parent_id = -1;
712 WSBool iscollection; 712 WSBool iscollection;
713 if(pg_resolve_path(ctx, path, &parent_id, &resource_id, NULL, &resname, &iscollection, NULL)) { 713 if(pg_resolve_path(pg->connection, path, &parent_id, &resource_id, NULL, &resname, &iscollection, NULL, &ctx->vfs_errno)) {
714 ctx->vfs_errno = ENOENT;
715 return 1; 714 return 1;
716 } 715 }
717 716
718 if(!iscollection) { 717 if(!iscollection) {
719 ctx->vfs_errno = ENOTDIR; 718 ctx->vfs_errno = ENOTDIR;

mercurial