652 free(res->tags_hash); |
652 free(res->tags_hash); |
653 } |
653 } |
654 free(res); |
654 free(res); |
655 } |
655 } |
656 |
656 |
|
657 char* nullstrdup(const char *s) { |
|
658 return s ? strdup(s) : NULL; |
|
659 } |
|
660 |
|
661 LocalResource* local_resource_copy(LocalResource *src, const char *new_path) { |
|
662 LocalResource *newres = calloc(1, sizeof(LocalResource)); |
|
663 newres->path = strdup(new_path); |
|
664 newres->etag = nullstrdup(src->etag); |
|
665 newres->hash = nullstrdup(src->hash); |
|
666 newres->last_modified = src->last_modified; |
|
667 newres->mode = src->mode; |
|
668 newres->uid = src->uid; |
|
669 newres->gid = src->gid; |
|
670 newres->size = src->size; |
|
671 newres->isdirectory = src->isdirectory; |
|
672 newres->skipped = src->skipped; |
|
673 |
|
674 if(src->xattr) { |
|
675 XAttributes *xattr = calloc(1, sizeof(XAttributes)); |
|
676 xattr->hash = nullstrdup(src->xattr->hash); |
|
677 xattr->nattr = src->xattr->nattr; |
|
678 xattr->names = calloc(xattr->nattr, sizeof(char*)); |
|
679 xattr->values = calloc(xattr->nattr, sizeof(sstr_t)); |
|
680 for(int i=0;i<xattr->nattr;i++) { |
|
681 xattr->names[i] = strdup(src->xattr->names[i]); |
|
682 xattr->values[i] = sstrdup(src->xattr->values[i]); |
|
683 } |
|
684 newres->xattr = xattr; |
|
685 } |
|
686 |
|
687 newres->tags_hash = nullstrdup(src->tags_hash); |
|
688 newres->xattr_hash = nullstrdup(src->xattr_hash); |
|
689 newres->remote_tags_hash = nullstrdup(src->remote_tags_hash); |
|
690 |
|
691 if(src->parts) { |
|
692 newres->numparts = src->numparts; |
|
693 newres->parts = calloc(src->numparts, sizeof(FilePart)); |
|
694 for(int i=0;i<newres->numparts;i++) { |
|
695 FilePart s = src->parts[i]; |
|
696 FilePart p; |
|
697 p.block = s.block; |
|
698 p.hash = nullstrdup(s.hash); |
|
699 p.etag = nullstrdup(s.etag); |
|
700 newres->parts[i] = p; |
|
701 } |
|
702 } |
|
703 |
|
704 newres->blocksize = src->blocksize; |
|
705 |
|
706 newres->tags_updated = src->tags_updated; |
|
707 newres->finfo_updated = src->finfo_updated; |
|
708 newres->xattr_updated = src->xattr_updated; |
|
709 newres->metadata_updated = src->metadata_updated; |
|
710 |
|
711 return newres; |
|
712 |
|
713 } |
|
714 |
657 void filepart_free(FilePart *part) { |
715 void filepart_free(FilePart *part) { |
658 if(part->etag) { |
716 if(part->etag) { |
659 free(part->etag); |
717 free(part->etag); |
660 } |
718 } |
661 if(part->hash) { |
719 if(part->hash) { |