MCPcopy Create free account
hub / github.com/RsyncProject/rsync / flist_find

Function flist_find

flist.c:2827–2874  ·  view source on GitHub ↗

Search for an identically-named item in the file list. Note that the * items must agree in their directory-ness, or no match is returned. */

Source from the content-addressed store, hash-verified

2825/* Search for an identically-named item in the file list. Note that the
2826 * items must agree in their directory-ness, or no match is returned. */
2827int flist_find(struct file_list *flist, struct file_struct *f)
2828{
2829 int low = flist->low, high = flist->high;
2830 int diff, mid, mid_up;
2831
2832 while (low <= high) {
2833 mid = (low + high) / 2;
2834 if (F_IS_ACTIVE(flist->sorted[mid]))
2835 mid_up = mid;
2836 else {
2837 /* Scan for the next non-empty entry using the cached
2838 * distance values. If the value isn't fully up-to-
2839 * date, update it. */
2840 mid_up = mid + F_DEPTH(flist->sorted[mid]);
2841 if (!F_IS_ACTIVE(flist->sorted[mid_up])) {
2842 do {
2843 mid_up += F_DEPTH(flist->sorted[mid_up]);
2844 } while (!F_IS_ACTIVE(flist->sorted[mid_up]));
2845 F_DEPTH(flist->sorted[mid]) = mid_up - mid;
2846 }
2847 if (mid_up > high) {
2848 /* If there's nothing left above us, set high to
2849 * a non-empty entry below us and continue. */
2850 high = mid - (int)flist->sorted[mid]->len32;
2851 if (!F_IS_ACTIVE(flist->sorted[high])) {
2852 do {
2853 high -= (int)flist->sorted[high]->len32;
2854 } while (!F_IS_ACTIVE(flist->sorted[high]));
2855 flist->sorted[mid]->len32 = mid - high;
2856 }
2857 continue;
2858 }
2859 }
2860 diff = f_name_cmp(flist->sorted[mid_up], f);
2861 if (diff == 0) {
2862 if (protocol_version < 29
2863 && S_ISDIR(flist->sorted[mid_up]->mode)
2864 != S_ISDIR(f->mode))
2865 return -1;
2866 return mid_up;
2867 }
2868 if (diff < 0)
2869 low = mid_up + 1;
2870 else
2871 high = mid - 1;
2872 }
2873 return -1;
2874}
2875
2876/* Search for a name in the file list. You must specify want_dir_match as:
2877 * 1=match directories, 0=match non-directories, or -1=match either. */

Callers 5

flist_find_nameFunction · 0.85
flist_sort_and_cleanFunction · 0.85
recv_generatorFunction · 0.85
set_current_file_indexFunction · 0.85

Calls 1

f_name_cmpFunction · 0.85

Tested by

no test coverage detected