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"); |
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 |
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 |