get_ref_dir(): return early if directory cannot be read

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2012-04-25 00:45:07 +02:00 committed by Junio C Hamano
parent 5e69491bf2
commit d5fdae6737

13
refs.c
View File

@ -754,6 +754,9 @@ static void get_ref_dir(struct ref_cache *refs, const char *base,
{ {
DIR *d; DIR *d;
const char *path; const char *path;
struct dirent *de;
int baselen;
char *refname;
if (*refs->name) if (*refs->name)
path = git_path_submodule(refs->name, "%s", base); path = git_path_submodule(refs->name, "%s", base);
@ -761,10 +764,11 @@ static void get_ref_dir(struct ref_cache *refs, const char *base,
path = git_path("%s", base); path = git_path("%s", base);
d = opendir(path); d = opendir(path);
if (d) { if (!d)
struct dirent *de; return;
int baselen = strlen(base);
char *refname = xmalloc(baselen + 257); baselen = strlen(base);
refname = xmalloc(baselen + 257);
memcpy(refname, base, baselen); memcpy(refname, base, baselen);
if (baselen && base[baselen-1] != '/') if (baselen && base[baselen-1] != '/')
@ -810,7 +814,6 @@ static void get_ref_dir(struct ref_cache *refs, const char *base,
free(refname); free(refname);
closedir(d); closedir(d);
} }
}
static struct ref_dir *get_loose_refs(struct ref_cache *refs) static struct ref_dir *get_loose_refs(struct ref_cache *refs)
{ {