[PATCH v2 4/9] dir: add method to check if a dir_entry lexically contains another
- From
Samuel Lijin <sxlijin@gmail.com>
- Date
- May 5, 2017, 10:46 UTC
- Message-ID
- <20170505104611.17845-5-sxlijin@gmail.com>
- In-Reply-To
- <20170505104611.17845-1-sxlijin@gmail.com>
Introduce a method that allows us to check if one dir_entry corresponds to a path which contains the path corresponding to another dir_entry.
Signed-off-by: Samuel Lijin <sxlijin@gmail.com> --- dir.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/dir.c b/dir.c index 6bd0350e9..4739087f4 100644 --- a/dir.c +++ b/dir.c @@ -1852,6 +1852,14 @@ static int cmp_name(const void *p1, const void *p2) return name_compare(e1->name, e1->len, e2->name, e2->len); } +/* check if *out lexically contains *in */ +static int check_contains(const struct dir_entry *out, const struct dir_entry *in) +{ + return (out->len < in->len) && + (out->name[out->len - 1] == '/') && + !memcmp(out->name, in->name, out->len); +} + static int treat_leading_path(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec)
-- 2.12.2