2936 res->prev_hash = strdup(db_res->hash); |
2936 res->prev_hash = strdup(db_res->hash); |
2937 } |
2937 } |
2938 if(db_res->link_target) { |
2938 if(db_res->link_target) { |
2939 res->link_target_db = db_res->link_target; |
2939 res->link_target_db = db_res->link_target; |
2940 } |
2940 } |
|
2941 res->versioncontrol = db_res->versioncontrol; |
2941 |
2942 |
2942 // if the resource is splitted, copy the part info to the new |
2943 // if the resource is splitted, copy the part info to the new |
2943 // LocalResource obj, because we need it later |
2944 // LocalResource obj, because we need it later |
2944 if(db_res->parts) { |
2945 if(db_res->parts) { |
2945 local_resource_copy_parts(db_res, res); |
2946 local_resource_copy_parts(db_res, res); |
3688 |
3689 |
3689 #define VBEGIN_ERROR_MKCOL 1 |
3690 #define VBEGIN_ERROR_MKCOL 1 |
3690 #define VBEGIN_ERROR_MOVE 2 |
3691 #define VBEGIN_ERROR_MOVE 2 |
3691 #define VBEGIN_ERROR_PROPPATCH 3 |
3692 #define VBEGIN_ERROR_PROPPATCH 3 |
3692 #define VBEGIN_ERROR_CHECKOUT 4 |
3693 #define VBEGIN_ERROR_CHECKOUT 4 |
3693 int versioning_begin(SyncDirectory *dir, DavResource *res, int *exists) { |
3694 int versioning_begin(SyncDirectory *dir, DavResource *res, int *exists, int *versionized) { |
3694 int ret = 0; |
3695 int ret = 0; |
|
3696 *versionized = 0; |
3695 |
3697 |
3696 if(dir->versioning->type == VERSIONING_SIMPLE && res->exists) { |
3698 if(dir->versioning->type == VERSIONING_SIMPLE && res->exists) { |
3697 DavResource *history_collection = dav_resource_new( |
3699 DavResource *history_collection = dav_resource_new( |
3698 res->session, |
3700 res->session, |
3699 dir->versioning->collection); |
3701 dir->versioning->collection); |
3765 *exists = 0; |
3767 *exists = 0; |
3766 } |
3768 } |
3767 } |
3769 } |
3768 |
3770 |
3769 if(!ret) { |
3771 if(!ret) { |
|
3772 *versionized = 1; |
|
3773 |
3770 dav_set_string_property_ns(version_res, DAV_NS, "origin", res->href); |
3774 dav_set_string_property_ns(version_res, DAV_NS, "origin", res->href); |
3771 if(dav_store(version_res)) { |
3775 if(dav_store(version_res)) { |
3772 ret = VBEGIN_ERROR_PROPPATCH; |
3776 ret = VBEGIN_ERROR_PROPPATCH; |
3773 } |
3777 } |
3774 dav_resource_free(version_res); |
3778 dav_resource_free(version_res); |
3785 if(vcol_path != history_href) { |
3789 if(vcol_path != history_href) { |
3786 free(history_href); |
3790 free(history_href); |
3787 } |
3791 } |
3788 |
3792 |
3789 dav_resource_free(history_collection); |
3793 dav_resource_free(history_collection); |
3790 } else if(dir->versioning->type == VERSIONING_DELTAV){ |
3794 } else if(dir->versioning->type == VERSIONING_DELTAV && res->exists){ |
3791 // DeltaV is so much easier :) |
3795 // DeltaV is so much easier :) |
3792 if(dav_checkout(res)) { |
3796 if(dav_checkout(res)) { |
3793 ret = VBEGIN_ERROR_CHECKOUT; |
3797 ret = VBEGIN_ERROR_CHECKOUT; |
3794 } |
3798 } else { |
3795 } |
3799 *versionized = 1; |
3796 |
3800 } |
|
3801 } |
|
3802 |
|
3803 return ret; |
|
3804 } |
|
3805 |
|
3806 int versioning_init(SyncDirectory *dir, LocalResource *local, DavResource *res) { |
|
3807 if(local->versioncontrol) { |
|
3808 return 0; |
|
3809 } |
|
3810 int ret = 0; |
|
3811 if(dir->versioning->type == VERSIONING_DELTAV) { |
|
3812 if(dav_versioncontrol(res)) { |
|
3813 ret = 1; |
|
3814 } else { |
|
3815 local->versioncontrol = 1; |
|
3816 } |
|
3817 } |
3797 return ret; |
3818 return ret; |
3798 } |
3819 } |
3799 |
3820 |
3800 int versioning_end(SyncDirectory *dir, DavResource *res) { |
3821 int versioning_end(SyncDirectory *dir, DavResource *res) { |
3801 if(dir->versioning->type == VERSIONING_DELTAV) { |
3822 if(dir->versioning->type == VERSIONING_DELTAV) { |
3803 } else { |
3824 } else { |
3804 return 0; |
3825 return 0; |
3805 } |
3826 } |
3806 } |
3827 } |
3807 |
3828 |
3808 int versioning_delete_begin(SyncDirectory *dir, DavResource *res, int *exists) { |
3829 int versioning_delete_begin(SyncDirectory *dir, DavResource *res, int *exists, int *versionized) { |
|
3830 *versionized = 0; |
3809 if(dir->versioning->type == VERSIONING_SIMPLE) { |
3831 if(dir->versioning->type == VERSIONING_SIMPLE) { |
3810 versioning_begin(dir, res, exists); |
3832 versioning_begin(dir, res, exists, versionized); |
3811 } else { |
3833 } else { |
3812 // versioning delete with DeltaV currently not supported in dav-sync |
3834 // versioning delete with DeltaV currently not supported in dav-sync |
3813 *exists = 1; |
3835 *exists = 1; |
3814 } |
3836 } |
3815 return 0; |
3837 return 0; |
4152 hashes = sync_set_metadata_properties(dir, res->session, res, local, FALSE); |
4174 hashes = sync_set_metadata_properties(dir, res->session, res, local, FALSE); |
4153 |
4175 |
4154 // before sync_put_resource, remote_resource_is_changed does a propfind |
4176 // before sync_put_resource, remote_resource_is_changed does a propfind |
4155 // and sets res->exists |
4177 // and sets res->exists |
4156 int exists = res->exists; |
4178 int exists = res->exists; |
|
4179 int vend_required = 0; |
4157 if(dir->versioning && dir->versioning->always && !issplit) { |
4180 if(dir->versioning && dir->versioning->always && !issplit) { |
4158 int err = versioning_begin(dir, res, &exists); |
4181 // in case the file exists, we need to put the file under |
4159 if(err) { |
4182 // versioncontrol (DeltaV only, does nothing with simple versioning) |
4160 fprintf(stderr, "Cannot store version for resource: %s\n", res->href); |
4183 if(exists && versioning_init(dir, local, res)) { |
|
4184 // init failed |
|
4185 fprintf(stderr, "Cannot activate versioncontrol for resource: %s\n", res->href); |
4161 free(local_path); |
4186 free(local_path); |
4162 return -1; |
4187 return -1; |
|
4188 } else { |
|
4189 int err = versioning_begin(dir, res, &exists, &vend_required); |
|
4190 if(err) { |
|
4191 fprintf(stderr, "Cannot store version for resource: %s\n", res->href); |
|
4192 free(local_path); |
|
4193 return -1; |
|
4194 } |
4163 } |
4195 } |
4164 } |
4196 } |
4165 |
4197 |
4166 int ret = -1; |
4198 int ret = -1; |
4167 for(int i=0;i<=dir->max_retry;i++) { |
4199 for(int i=0;i<=dir->max_retry;i++) { |
4353 // resource can be deleted |
4385 // resource can be deleted |
4354 printf("delete: %s\n", res->path); |
4386 printf("delete: %s\n", res->path); |
4355 int exists = 1; |
4387 int exists = 1; |
4356 int vend_required = 0; |
4388 int vend_required = 0; |
4357 if(dir->versioning && dir->versioning->always) { |
4389 if(dir->versioning && dir->versioning->always) { |
4358 if(versioning_delete_begin(dir, res, &exists)) { |
4390 if(versioning_delete_begin(dir, res, &exists, &vend_required)) { |
4359 fprintf( |
4391 fprintf( |
4360 stderr, |
4392 stderr, |
4361 "Cannot save resource version before deletion\n"); |
4393 "Cannot save resource version before deletion\n"); |
4362 ret = 1; |
4394 ret = 1; |
4363 } else { |
|
4364 vend_required = 1; |
|
4365 } |
4395 } |
4366 } |
4396 } |
4367 |
4397 |
4368 if(!ret && dav_delete(res) && exists) { |
4398 if(!ret && dav_delete(res) && exists) { |
4369 if(sn->error != DAV_NOT_FOUND) { |
4399 if(sn->error != DAV_NOT_FOUND) { |