dav/sync.c

changeset 629
bc2cdbf5e68f
parent 626
2f735b0e87fa
child 630
046b869a1c49
equal deleted inserted replaced
628:1f76d9624db8 629:bc2cdbf5e68f
2519 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) { 2519 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) {
2520 continue; 2520 continue;
2521 } 2521 }
2522 2522
2523 char *new_path = util_concat_path(p, ent->name); 2523 char *new_path = util_concat_path(p, ent->name);
2524 DavBool free_new_path = TRUE;
2524 LocalResource *res = local_resource_new(dir, db, new_path); 2525 LocalResource *res = local_resource_new(dir, db, new_path);
2525 if(res->isdirectory) { 2526 if(res) {
2526 resources = ucx_list_append(resources, res); 2527 if(res->isdirectory) {
2527 stack = ucx_list_prepend(stack, new_path); 2528 resources = ucx_list_append(resources, res);
2528 } else if(res) { 2529 stack = ucx_list_prepend(stack, new_path);
2529 resources = ucx_list_append(resources, res); 2530 free_new_path = FALSE;
2530 free(new_path); 2531 } else {
2531 } else { 2532 resources = ucx_list_append(resources, res);
2533 }
2534 }
2535 if(free_new_path) {
2532 free(new_path); 2536 free(new_path);
2533 } 2537 }
2534 } 2538 }
2535 sys_closedir(local_dir); 2539 sys_closedir(local_dir);
2536 2540
2607 } else { 2611 } else {
2608 res->path = util_concat_path(path, "/"); 2612 res->path = util_concat_path(path, "/");
2609 res->isdirectory = 1; 2613 res->isdirectory = 1;
2610 } 2614 }
2611 2615
2616 int skip_file = 0;
2612 if(SYS_ISLINK(file_path, s)) { 2617 if(SYS_ISLINK(file_path, s)) {
2613 char *lnkbuf = sys_readlink(file_path, &s); 2618 char *lnkbuf = sys_readlink(file_path, &s);
2614 #ifdef SYS_LINK_EXT 2619 #ifdef SYS_LINK_EXT
2615 // on Windows, we interpret .lnk files as links 2620 // on Windows, we interpret .lnk files as links
2616 // we dont want resource names with this extension 2621 // we dont want resource names with this extension
2651 } else { 2656 } else {
2652 normalized = util_path_normalize(lnkbuf); 2657 normalized = util_path_normalize(lnkbuf);
2653 } 2658 }
2654 2659
2655 char *dirpath = util_path_normalize(dir->path); 2660 char *dirpath = util_path_normalize(dir->path);
2656 if(util_path_isrelated(dirpath, normalized)) { 2661 int isintern = util_path_isrelated(dirpath, normalized);
2662
2663
2664 if(SYNC_SYMLINK(dir) && isintern) {
2657 // the link points to a file inside the syncdir 2665 // the link points to a file inside the syncdir
2658 char *rel = util_create_relative_path(normalized, file_path); 2666 char *rel = util_create_relative_path(normalized, file_path);
2659 res->link_target = rel; 2667 res->link_target = rel;
2668 } else {
2669 #ifndef SYS_LINK_EXT // if not windows
2670 SYS_STAT targetstat;
2671 if(!sys_stat(file_path, &targetstat)) {
2672 res->isdirectory = S_ISDIR(targetstat.st_mode);
2673
2674 int nofollowextern = (dir->symlink & SYNC_SYMLINK_EXTERN_NOFOLLOW) == SYNC_SYMLINK_EXTERN_NOFOLLOW;
2675 int nofollowintern = (dir->symlink & SYNC_SYMLINK_INTERN_NOFOLLOW) == SYNC_SYMLINK_INTERN_NOFOLLOW;
2676 if(isintern && nofollowintern) {
2677 skip_file = TRUE;
2678 } else if(!isintern && nofollowextern) {
2679 skip_file = TRUE;
2680 }
2681 } else {
2682 // can't access target, therefore we skip this link
2683 skip_file = TRUE;
2684 }
2685 #endif
2660 } 2686 }
2661 free(dirpath); 2687 free(dirpath);
2662 free(normalized); 2688 free(normalized);
2663 free(lnkbuf); 2689 free(lnkbuf);
2664 } 2690 }
2665 } 2691 }
2666 2692
2667 free(file_path); 2693 free(file_path);
2694
2695 if(skip_file) {
2696 local_resource_free(res);
2697 res = NULL;
2698 }
2668 2699
2669 return res; 2700 return res;
2670 } 2701 }
2671 2702
2672 char* local_resource_path(LocalResource *res) { 2703 char* local_resource_path(LocalResource *res) {
2806 2837
2807 if(res->restore) { 2838 if(res->restore) {
2808 return 0; 2839 return 0;
2809 } 2840 }
2810 2841
2842 if(remote->iscollection) {
2843 return 1;
2844 }
2845
2811 int ret = 0; 2846 int ret = 0;
2812 if(err == 0) { 2847 if(err == 0) {
2813 char *etag = dav_get_string_property(remote, "D:getetag"); 2848 char *etag = dav_get_string_property(remote, "D:getetag");
2814 char *hash = sync_get_content_hash(remote); 2849 char *hash = sync_get_content_hash(remote);
2815 if(hash && res->hash) { 2850 if(hash && res->hash) {
3195 if(update) { 3230 if(update) {
3196 ret = xattr_set(path, dir->tagconfig->xattr_name, data->space, data->pos); 3231 ret = xattr_set(path, dir->tagconfig->xattr_name, data->space, data->pos);
3197 if(local) { 3232 if(local) {
3198 if(local->tags_hash) { 3233 if(local->tags_hash) {
3199 free(local->tags_hash); 3234 free(local->tags_hash);
3235 local->tags_hash = NULL;
3200 } 3236 }
3201 local->tags_hash = data_hash; 3237 local->tags_hash = data_hash;
3202 } 3238 }
3203 } else { 3239 } else {
3204 free(data_hash); 3240 free(data_hash);
3274 if(res->tags_hash) { 3310 if(res->tags_hash) {
3275 if(changed && strcmp(res->tags_hash, new_hash)) { 3311 if(changed && strcmp(res->tags_hash, new_hash)) {
3276 *changed = TRUE; 3312 *changed = TRUE;
3277 } 3313 }
3278 free(res->tags_hash); 3314 free(res->tags_hash);
3315 res->tags_hash = NULL;
3279 } else { 3316 } else {
3280 if(changed) *changed = TRUE; 3317 if(changed) *changed = TRUE;
3281 } 3318 }
3282 if(newhash) { 3319 if(newhash) {
3283 *newhash = new_hash; 3320 *newhash = new_hash;
3458 3495
3459 static void update_metadata_hashes(LocalResource *local, MetadataHashes hashes) { 3496 static void update_metadata_hashes(LocalResource *local, MetadataHashes hashes) {
3460 if(hashes.tags) { 3497 if(hashes.tags) {
3461 if(local->tags_hash) { 3498 if(local->tags_hash) {
3462 free(local->tags_hash); 3499 free(local->tags_hash);
3500 local->tags_hash = NULL;
3463 } 3501 }
3464 local->tags_hash = hashes.tags; 3502 local->tags_hash = hashes.tags;
3465 } 3503 }
3466 if(hashes.tags_remote) { 3504 if(hashes.tags_remote) {
3467 if(local->remote_tags_hash) { 3505 if(local->remote_tags_hash) {
4762 if(localres) { 4800 if(localres) {
4763 localres->tags_updated = TRUE; 4801 localres->tags_updated = TRUE;
4764 if(!tags) { 4802 if(!tags) {
4765 if(localres->tags_hash) { 4803 if(localres->tags_hash) {
4766 free(localres->tags_hash); 4804 free(localres->tags_hash);
4805 localres->tags_hash = NULL;
4767 } 4806 }
4768 localres->tags_hash = NULL; 4807 localres->tags_hash = NULL;
4769 } 4808 }
4770 } 4809 }
4771 } 4810 }

mercurial