dav/main.c

changeset 201
8e5856182668
parent 200
cc474cf2c2f5
child 204
4f0207044837
equal deleted inserted replaced
200:cc474cf2c2f5 201:8e5856182668
572 572
573 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; 573 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
574 DavResource *res; 574 DavResource *res;
575 575
576 int depth = recursive ? -1 : 1; 576 int depth = recursive ? -1 : 1;
577 res = dav_query( 577 for(int i=0;i<2;i++) {
578 sn, 578 res = dav_query(
579 "select - from %s with depth = %d where lastmodified > %t", 579 sn,
580 path, 580 "select - from %s with depth = %d where lastmodified > %t",
581 depth, 581 path,
582 t); 582 depth,
583 583 t);
584 if(!res && sn->error == DAV_UNAUTHORIZED) {
585 if(request_auth(repo, sn)) {
586 continue;
587 }
588 }
589 break;
590 }
591
584 if(!res) { 592 if(!res) {
585 print_resource_error(sn, path); 593 print_resource_error(sn, path);
586 return -1; 594 return -1;
587 } 595 }
588 if(!recursive && res->iscollection) { 596 if(!recursive && res->iscollection) {
766 774
767 return ret; 775 return ret;
768 } 776 }
769 777
770 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { 778 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) {
771 DavResource *res = dav_query(sn, "select - from %s", path); 779 DavResource *res = NULL;
780 for(int i=0;i<2;i++) {
781 res = dav_query(sn, "select - from %s", path);
782 if(!res && sn->error == DAV_UNAUTHORIZED) {
783 if(request_auth(repo, sn)) {
784 continue;
785 }
786 }
787 break;
788 }
789
772 if(!res) { 790 if(!res) {
773 if(sn->error == DAV_NOT_FOUND) { 791 if(sn->error == DAV_NOT_FOUND) {
774 res = dav_resource_new(sn, path); 792 res = dav_resource_new(sn, path);
775 if(dav_create(res)) { 793 if(dav_create(res)) {
776 fprintf(stderr, "Cannot create resource.\n"); 794 fprintf(stderr, "Cannot create resource.\n");
815 return -1; 833 return -1;
816 } 834 }
817 835
818 char *url = a->argv[0]; 836 char *url = a->argv[0];
819 char *path = NULL; 837 char *path = NULL;
820 DavSession *sn = connect_to_repo(url2repo(url, &path), a); 838 Repository *repo = url2repo(url, &path);
839 DavSession *sn = connect_to_repo(repo, a);
821 840
822 if(set_session_config(sn, a)) { 841 if(set_session_config(sn, a)) {
823 return -1; 842 return -1;
824 } 843 }
825 844
827 if(!res) { 846 if(!res) {
828 fprintf(stderr, "error\n"); 847 fprintf(stderr, "error\n");
829 return -1; 848 return -1;
830 } 849 }
831 850
832 if(dav_delete(res)) { 851 int err = 0;
852 for(int i=0;i<2;i++) {
853 err = dav_delete(res);
854 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) {
855 continue;
856 } else {
857 break;
858 }
859 }
860
861 if(err) {
833 print_resource_error(sn, res->path); 862 print_resource_error(sn, res->path);
834 fprintf(stderr, "Cannot delete resource.\n"); 863 fprintf(stderr, "Cannot delete resource.\n");
835 return -1; 864 return -1;
836 } 865 }
837 866
846 return -1; 875 return -1;
847 } 876 }
848 877
849 char *url = a->argv[0]; 878 char *url = a->argv[0];
850 char *path = NULL; 879 char *path = NULL;
851 DavSession *sn = connect_to_repo(url2repo(url, &path), a); 880 Repository *repo = url2repo(url, &path);
881 DavSession *sn = connect_to_repo(repo, a);
852 882
853 if(set_session_config(sn, a)) { 883 if(set_session_config(sn, a)) {
854 return -1; 884 return -1;
855 } 885 }
856 886
872 fprintf(stderr, "error\n"); 902 fprintf(stderr, "error\n");
873 return -1; 903 return -1;
874 } 904 }
875 res->iscollection = 1; 905 res->iscollection = 1;
876 906
877 if(dav_create(res)) { 907 int err = 0;
908 for(int i=0;i<2;i++) {
909 err = dav_create(res);
910 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) {
911 continue;
912 } else {
913 break;
914 }
915 }
916
917 if(err) {
878 print_resource_error(sn, res->path); 918 print_resource_error(sn, res->path);
879 fprintf(stderr, "Cannot create collection.\n"); 919 fprintf(stderr, "Cannot create collection.\n");
880 return -1; 920 return -1;
881 } 921 }
882 922

mercurial