349:7bf652914e9b | 350:abba342112c2 |
---|---|
428 WSBool collection) | 428 WSBool collection) |
429 { | 429 { |
430 char *parent_path = util_parent_path(path); | 430 char *parent_path = util_parent_path(path); |
431 if(!parent_path) return 1; | 431 if(!parent_path) return 1; |
432 | 432 |
433 size_t pathlen = strlen(path); | |
434 char *pathf = NULL; | |
435 if(pathlen > 1 && path[pathlen-1] == '/') { | |
436 pathf = malloc(pathlen); | |
437 memcpy(pathf, path, pathlen); | |
438 pathf[pathlen-1] = 0; // remove trailing '/' | |
439 path = pathf; | |
440 } | |
441 | |
433 const char *nodename = util_resource_name(path); | 442 const char *nodename = util_resource_name(path); |
434 | 443 |
435 // resolve the parent path | 444 // resolve the parent path |
436 // if the parent path can't be resolved, we are done | 445 // if the parent path can't be resolved, we are done |
437 const char *resname; | 446 const char *resname; |
443 | 452 |
444 int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, NULL, &ctx->vfs_errno); | 453 int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, NULL, &ctx->vfs_errno); |
445 FREE(parent_path); | 454 FREE(parent_path); |
446 if(err) { | 455 if(err) { |
447 ctx->vfs_errno = ENOENT; | 456 ctx->vfs_errno = ENOENT; |
457 if(pathf) free(pathf); | |
448 return 1; | 458 return 1; |
449 } | 459 } |
450 | 460 |
451 // parent path exists, check if it is a collection | 461 // parent path exists, check if it is a collection |
452 if(!iscollection) { | 462 if(!iscollection) { |
463 if(pathf) free(pathf); | |
453 return 1; | 464 return 1; |
454 } | 465 } |
455 | 466 |
456 // create new Resource | 467 // create new Resource |
457 char resid_str[32]; | 468 char resid_str[32]; |
461 if(collection) { | 472 if(collection) { |
462 ret = pg_create_col(pg, resid_str, nodename, new_resource_id, resource_name, s); | 473 ret = pg_create_col(pg, resid_str, nodename, new_resource_id, resource_name, s); |
463 } else { | 474 } else { |
464 ret = pg_create_res(pg, resid_str, nodename, new_resource_id, oid, resource_name, s); | 475 ret = pg_create_res(pg, resid_str, nodename, new_resource_id, oid, resource_name, s); |
465 } | 476 } |
477 | |
478 if(pathf) free(pathf); | |
466 | 479 |
467 if(res_parent_id) { | 480 if(res_parent_id) { |
468 // resource_id is still the id of the parent from previous pg_resolve_path call | 481 // resource_id is still the id of the parent from previous pg_resolve_path call |
469 *res_parent_id = resource_id; | 482 *res_parent_id = resource_id; |
470 } | 483 } |