clean: only lstat files in pathspec
authorDavid Turner <dturner@twopensource.com>
Mon, 18 May 2015 18:08:46 +0000 (14:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 May 2015 21:04:15 +0000 (14:04 -0700)
Even though "git clean" takes pathspec to limit the part of the
working tree to be cleaned, it checked the paths it encounters
during its directory traversal with lstat(2), before checking if
the path is within the pathspec.

Ignore paths outside pathspec and proceed without checking with
lstat(2). Even if such a path is unreadable due to e.g. EPERM,
"git clean" should not care.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clean.c
index 1032563e5fae880df9256c9eafaa96d60462ecd2..3c1f4b0908c22d025cbb90b9a0d6ced9f0c9a6c4 100644 (file)
@@ -940,15 +940,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                if (!cache_name_is_other(ent->name, ent->len))
                        continue;
 
-               if (lstat(ent->name, &st))
-                       die_errno("Cannot lstat '%s'", ent->name);
-
                if (pathspec.nr)
                        matches = dir_path_match(ent, &pathspec, 0, NULL);
 
                if (pathspec.nr && !matches)
                        continue;
 
+               if (lstat(ent->name, &st))
+                       die_errno("Cannot lstat '%s'", ent->name);
+
                if (S_ISDIR(st.st_mode) && !remove_directories &&
                    matches != MATCHED_EXACTLY)
                        continue;