MCPcopy Index your code
hub / github.com/RsyncProject/rsync / find_fuzzy

Function find_fuzzy

generator.c:831–909  ·  view source on GitHub ↗

Try to find a filename in the same dir as "fname" with a similar name. */

Source from the content-addressed store, hash-verified

829
830/* Try to find a filename in the same dir as "fname" with a similar name. */
831static struct file_struct *find_fuzzy(struct file_struct *file, struct file_list *dirlist_array[], uchar *fnamecmp_type_ptr)
832{
833 int fname_len, fname_suf_len;
834 const char *fname_suf, *fname = file->basename;
835 uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */
836 int i, j;
837 struct file_struct *lowest_fp = NULL;
838
839 fname_len = strlen(fname);
840 fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len);
841
842 /* Try to find an exact size+mtime match first. */
843 for (i = 0; i < fuzzy_basis; i++) {
844 struct file_list *dirlist = dirlist_array[i];
845
846 if (!dirlist)
847 continue;
848
849 for (j = 0; j < dirlist->used; j++) {
850 struct file_struct *fp = dirlist->files[j];
851
852 if (!F_IS_ACTIVE(fp))
853 continue;
854
855 if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT)
856 continue;
857
858 if (F_LENGTH(fp) == F_LENGTH(file) && same_time(fp->modtime, 0, file->modtime, 0)) {
859 if (DEBUG_GTE(FUZZY, 2))
860 rprintf(FINFO, "fuzzy size/modtime match for %s\n", f_name(fp, NULL));
861 *fnamecmp_type_ptr = FNAMECMP_FUZZY + i;
862 return fp;
863 }
864
865 }
866 }
867
868 for (i = 0; i < fuzzy_basis; i++) {
869 struct file_list *dirlist = dirlist_array[i];
870
871 if (!dirlist)
872 continue;
873
874 for (j = 0; j < dirlist->used; j++) {
875 struct file_struct *fp = dirlist->files[j];
876 const char *suf, *name;
877 int len, suf_len;
878 uint32 dist;
879
880 if (!F_IS_ACTIVE(fp))
881 continue;
882
883 if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT)
884 continue;
885
886 name = fp->basename;
887 len = strlen(name);
888 suf = find_filename_suffix(name, len, &suf_len);

Callers 1

recv_generatorFunction · 0.85

Calls 5

find_filename_suffixFunction · 0.85
same_timeFunction · 0.85
f_nameFunction · 0.85
fuzzy_distanceFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected