From 47fa5ae63e53c08d3c4c760f055378abc0bad091 Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Fri, 10 Feb 2012 01:23:47 +0100 Subject: Add option preventing metastore from omitting .git dirs. --- metaentry.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'metaentry.c') diff --git a/metaentry.c b/metaentry.c index a557a93..79db236 100644 --- a/metaentry.c +++ b/metaentry.c @@ -337,6 +337,52 @@ mentries_recurse(const char *path, struct metahash *mhash) mentry_insert(mentry, mhash); + if (S_ISDIR(sbuf.st_mode)) { + dir = opendir(path); + if (!dir) { + msg(MSG_ERROR, "opendir failed for %s: %s\n", + path, strerror(errno)); + return; + } + + while ((dent = readdir(dir))) { + if (!strcmp(dent->d_name, ".") || + !strcmp(dent->d_name, "..")) + continue; + snprintf(tpath, PATH_MAX, "%s/%s", path, dent->d_name); + tpath[PATH_MAX - 1] = '\0'; + mentries_recurse(tpath, mhash); + } + + closedir(dir); + } +} + +/* Internal function for the recursive path walk ignoring .git dirs */ +static void +mentries_recurse_wo_git(const char *path, struct metahash *mhash) +{ + struct stat sbuf; + struct metaentry *mentry; + char tpath[PATH_MAX]; + DIR *dir; + struct dirent *dent; + + if (!path) + return; + + if (lstat(path, &sbuf)) { + msg(MSG_ERROR, "lstat failed for %s: %s\n", + path, strerror(errno)); + return; + } + + mentry = mentry_create(path); + if (!mentry) + return; + + mentry_insert(mentry, mhash); + if (S_ISDIR(sbuf.st_mode)) { dir = opendir(path); if (!dir) { @@ -352,7 +398,7 @@ mentries_recurse(const char *path, struct metahash *mhash) continue; snprintf(tpath, PATH_MAX, "%s/%s", path, dent->d_name); tpath[PATH_MAX - 1] = '\0'; - mentries_recurse(tpath, mhash); + mentries_recurse_wo_git(tpath, mhash); } closedir(dir); @@ -361,13 +407,16 @@ mentries_recurse(const char *path, struct metahash *mhash) /* Recurses opath and adds metadata entries to the metaentry list */ void -mentries_recurse_path(const char *opath, struct metahash **mhash) +mentries_recurse_path(const char *opath, struct metahash **mhash, bool git) { char *path = normalize_path(opath); if (!(*mhash)) *mhash = mhash_alloc(); - mentries_recurse(path, *mhash); + if (git) + mentries_recurse(path, *mhash); + else + mentries_recurse_wo_git(path, *mhash); free(path); } -- cgit v1.2.1