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

Function rule_matches

exclude.c:903–982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901}
902
903static int rule_matches(const char *fname, filter_rule *ex, int name_flags)
904{
905 int slash_handling, str_cnt = 0, anchored_match = 0;
906 int ret_match = ex->rflags & FILTRULE_NEGATE ? 0 : 1;
907 const char *p, *pattern = ex->pattern;
908 const char *strings[16]; /* more than enough */
909 const char *name = fname + (*fname == '/');
910
911 if (!*name || ex->elide == cur_elide_value)
912 return 0;
913
914 if (!(name_flags & NAME_IS_XATTR) ^ !(ex->rflags & FILTRULE_XATTR))
915 return 0;
916
917 if (!ex->u.slash_cnt && !(ex->rflags & FILTRULE_WILD2)) {
918 /* If the pattern does not have any slashes AND it does
919 * not have a "**" (which could match a slash), then we
920 * just match the name portion of the path. */
921 if ((p = strrchr(name,'/')) != NULL)
922 name = p+1;
923 } else if (ex->rflags & FILTRULE_ABS_PATH && *fname != '/'
924 && curr_dir_len > module_dirlen + 1) {
925 /* If we're matching against an absolute-path pattern,
926 * we need to prepend our full path info. */
927 strings[str_cnt++] = curr_dir + module_dirlen + 1;
928 strings[str_cnt++] = "/";
929 } else if (ex->rflags & FILTRULE_WILD2_PREFIX && *fname != '/') {
930 /* Allow "**"+"/" to match at the start of the string. */
931 strings[str_cnt++] = "/";
932 }
933 strings[str_cnt++] = name;
934 if (name_flags & NAME_IS_DIR) {
935 /* Allow a trailing "/"+"***" to match the directory. */
936 if (ex->rflags & FILTRULE_WILD3_SUFFIX)
937 strings[str_cnt++] = "/";
938 } else if (ex->rflags & FILTRULE_DIRECTORY)
939 return !ret_match;
940 strings[str_cnt] = NULL;
941
942 if (*pattern == '/') {
943 anchored_match = 1;
944 pattern++;
945 }
946
947 if (!anchored_match && ex->u.slash_cnt
948 && !(ex->rflags & FILTRULE_WILD2)) {
949 /* A non-anchored match with an infix slash and no "**"
950 * needs to match the last slash_cnt+1 name elements. */
951 slash_handling = ex->u.slash_cnt + 1;
952 } else if (!anchored_match && !(ex->rflags & FILTRULE_WILD2_PREFIX)
953 && ex->rflags & FILTRULE_WILD2) {
954 /* A non-anchored match with an infix or trailing "**" (but not
955 * a prefixed "**") needs to try matching after every slash. */
956 slash_handling = -1;
957 } else {
958 /* The pattern matches only at the start of the path or name. */
959 slash_handling = 0;
960 }

Callers 1

check_filterFunction · 0.85

Calls 2

wildmatch_arrayFunction · 0.85
litmatch_arrayFunction · 0.85

Tested by

no test coverage detected