src/server/webdav/operation.c

branch
webdav
changeset 247
1df803e06076
parent 246
155bdef7fe7e
child 249
3b302093945c
equal deleted inserted replaced
246:155bdef7fe7e 247:1df803e06076
442 op->path = path; 442 op->path = path;
443 443
444 return op; 444 return op;
445 } 445 }
446 446
447 WebdavVFSOperation webdav_vfs_sub_op(
448 WebdavVFSOperation *op,
449 char *path,
450 struct stat *s)
451 {
452 WebdavVFSOperation sub;
453 sub.dav = op->dav;
454 sub.path = path;
455 sub.sn = op->sn;
456 sub.vfs = op->vfs;
457 sub.path = op->path;
458 sub.stat = s;
459 sub.stat_errno = 0;
460 return sub;
461 }
462
447 int webdav_op_iterate_children( 463 int webdav_op_iterate_children(
448 VFSContext *vfs, 464 VFSContext *vfs,
449 int depth, 465 int depth,
450 const char *href, 466 const char *href,
451 const char *path, 467 const char *path,
454 { 470 {
455 UcxAllocator *a = session_get_allocator(vfs->sn); 471 UcxAllocator *a = session_get_allocator(vfs->sn);
456 pool_handle_t *pool = vfs->sn->pool; 472 pool_handle_t *pool = vfs->sn->pool;
457 473
458 PathSearchElm *start_elm = pool_malloc(pool, sizeof(PathSearchElm)); 474 PathSearchElm *start_elm = pool_malloc(pool, sizeof(PathSearchElm));
459 start_elm->href = pool_strdup(pool, href); 475 start_elm->href = pool_strdup(pool, href ? href : "");
460 start_elm->path = pool_strdup(pool, path); 476 start_elm->path = pool_strdup(pool, path ? path : "");
461 start_elm->hreflen = strlen(href); 477 start_elm->hreflen = href ? strlen(href) : 0;
462 start_elm->pathlen = strlen(path); 478 start_elm->pathlen = path ? strlen(path) : 0;
463 479
464 UcxList *stack = ucx_list_prepend_a(a, NULL, start_elm); 480 UcxList *stack = ucx_list_prepend_a(a, NULL, start_elm);
465 UcxList *stack_end = stack; 481 UcxList *stack_end = stack;
466 if(!stack) { 482 if(!stack) {
467 return 1; 483 return 1;
722 return ret; 738 return ret;
723 } 739 }
724 740
725 int webdav_vfs_unlink(WebdavVFSOperation *op) { 741 int webdav_vfs_unlink(WebdavVFSOperation *op) {
726 // stat the file first, to check if the file is a directory 742 // stat the file first, to check if the file is a directory
727 // deletion of simple files can be done just here,
728 // whereas deleting directories is more complicated
729 if(webdav_vfs_stat(op)) { 743 if(webdav_vfs_stat(op)) {
730 return 1; // error 744 return 1; // error
731 } else { 745 } else {
732 int r = 0;
733 if(!S_ISDIR(op->stat->st_mode)) { 746 if(!S_ISDIR(op->stat->st_mode)) {
734 return vfs_unlink(op->vfs, op->path); 747 return vfs_unlink(op->vfs, op->path);
735 } 748 } else {
736 } 749 return vfs_rmdir(op->vfs, op->path);
737 750 }
738 // delete directory: 751 }
739
740
741 752
742 return 0; 753 return 0;
743 } 754 }

mercurial