summaryrefslogtreecommitdiff
path: root/metaentry.c
diff options
context:
space:
mode:
authorPrzemyslaw Pawelczyk <przemoc@gmail.com>2012-02-10 01:23:47 +0100
committerPrzemyslaw Pawelczyk <przemoc@gmail.com>2012-02-10 01:23:47 +0100
commit47fa5ae63e53c08d3c4c760f055378abc0bad091 (patch)
treed92d52c397447a76458303bd1f4f8b456f5f3714 /metaentry.c
parent1cb509ed61006cfee243ba209dda584a1abca1cc (diff)
Add option preventing metastore from omitting .git dirs.
Diffstat (limited to 'metaentry.c')
-rw-r--r--metaentry.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/metaentry.c b/metaentry.c
index a557a93..79db236 100644
--- a/metaentry.c
+++ b/metaentry.c
@@ -347,12 +347,58 @@ mentries_recurse(const char *path, struct metahash *mhash)
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) {
+ 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, "..") ||
!strcmp(dent->d_name, ".git"))
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);
}