summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--scan-tree.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/scan-tree.c b/scan-tree.c
index dbca797..ebfd41e 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -38,97 +38,97 @@ static int is_git_dir(const char *path)
38 38
39struct cgit_repo *repo; 39struct cgit_repo *repo;
40repo_config_fn config_fn; 40repo_config_fn config_fn;
41 41
42static void repo_config(const char *name, const char *value) 42static void repo_config(const char *name, const char *value)
43{ 43{
44 config_fn(repo, name, value); 44 config_fn(repo, name, value);
45} 45}
46 46
47static void add_repo(const char *base, const char *path, repo_config_fn fn) 47static void add_repo(const char *base, const char *path, repo_config_fn fn)
48{ 48{
49 struct stat st; 49 struct stat st;
50 struct passwd *pwd; 50 struct passwd *pwd;
51 char *p; 51 char *p;
52 size_t size; 52 size_t size;
53 53
54 if (stat(path, &st)) { 54 if (stat(path, &st)) {
55 fprintf(stderr, "Error accessing %s: %s (%d)\n", 55 fprintf(stderr, "Error accessing %s: %s (%d)\n",
56 path, strerror(errno), errno); 56 path, strerror(errno), errno);
57 return; 57 return;
58 } 58 }
59 if ((pwd = getpwuid(st.st_uid)) == NULL) { 59 if ((pwd = getpwuid(st.st_uid)) == NULL) {
60 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", 60 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
61 path, strerror(errno), errno); 61 path, strerror(errno), errno);
62 return; 62 return;
63 } 63 }
64 if (base == path) 64 if (base == path)
65 p = fmt("%s", path); 65 p = fmt("%s", path);
66 else 66 else
67 p = fmt("%s", path + strlen(base) + 1); 67 p = fmt("%s", path + strlen(base) + 1);
68 68
69 if (!strcmp(p + strlen(p) - 5, "/.git")) 69 if (!strcmp(p + strlen(p) - 5, "/.git"))
70 p[strlen(p) - 5] = '\0'; 70 p[strlen(p) - 5] = '\0';
71 71
72 repo = cgit_add_repo(xstrdup(p)); 72 repo = cgit_add_repo(xstrdup(p));
73 repo->name = repo->url; 73 repo->name = repo->url;
74 repo->path = xstrdup(path); 74 repo->path = xstrdup(path);
75 p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; 75 p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
76 if (p) 76 if (p)
77 *p = '\0'; 77 *p = '\0';
78 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); 78 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
79 79
80 p = fmt("%s/description", path); 80 p = fmt("%s/description", path);
81 if (!stat(p, &st)) 81 if (!stat(p, &st))
82 readfile(p, &repo->desc, &size); 82 readfile(p, &repo->desc, &size);
83 83
84 p = fmt("%s/README.html", path); 84 p = fmt("%s/README.html", path);
85 if (!stat(p, &st)) 85 if (!stat(p, &st))
86 repo->readme = "README.html"; 86 repo->readme = xstrdup(p);
87 87
88 p = fmt("%s/cgitrc", path); 88 p = fmt("%s/cgitrc", path);
89 if (!stat(p, &st)) { 89 if (!stat(p, &st)) {
90 config_fn = fn; 90 config_fn = fn;
91 parse_configfile(xstrdup(p), &repo_config); 91 parse_configfile(xstrdup(p), &repo_config);
92 } 92 }
93} 93}
94 94
95static void scan_path(const char *base, const char *path, repo_config_fn fn) 95static void scan_path(const char *base, const char *path, repo_config_fn fn)
96{ 96{
97 DIR *dir; 97 DIR *dir;
98 struct dirent *ent; 98 struct dirent *ent;
99 char *buf; 99 char *buf;
100 struct stat st; 100 struct stat st;
101 101
102 if (is_git_dir(path)) { 102 if (is_git_dir(path)) {
103 add_repo(base, path, fn); 103 add_repo(base, path, fn);
104 return; 104 return;
105 } 105 }
106 if (is_git_dir(fmt("%s/.git", path))) { 106 if (is_git_dir(fmt("%s/.git", path))) {
107 add_repo(base, fmt("%s/.git", path), fn); 107 add_repo(base, fmt("%s/.git", path), fn);
108 return; 108 return;
109 } 109 }
110 dir = opendir(path); 110 dir = opendir(path);
111 if (!dir) { 111 if (!dir) {
112 fprintf(stderr, "Error opening directory %s: %s (%d)\n", 112 fprintf(stderr, "Error opening directory %s: %s (%d)\n",
113 path, strerror(errno), errno); 113 path, strerror(errno), errno);
114 return; 114 return;
115 } 115 }
116 while((ent = readdir(dir)) != NULL) { 116 while((ent = readdir(dir)) != NULL) {
117 if (ent->d_name[0] == '.') { 117 if (ent->d_name[0] == '.') {
118 if (ent->d_name[1] == '\0') 118 if (ent->d_name[1] == '\0')
119 continue; 119 continue;
120 if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') 120 if (ent->d_name[1] == '.' && ent->d_name[2] == '\0')
121 continue; 121 continue;
122 } 122 }
123 buf = malloc(strlen(path) + strlen(ent->d_name) + 2); 123 buf = malloc(strlen(path) + strlen(ent->d_name) + 2);
124 if (!buf) { 124 if (!buf) {
125 fprintf(stderr, "Alloc error on %s: %s (%d)\n", 125 fprintf(stderr, "Alloc error on %s: %s (%d)\n",
126 path, strerror(errno), errno); 126 path, strerror(errno), errno);
127 exit(1); 127 exit(1);
128 } 128 }
129 sprintf(buf, "%s/%s", path, ent->d_name); 129 sprintf(buf, "%s/%s", path, ent->d_name);
130 if (stat(buf, &st)) { 130 if (stat(buf, &st)) {
131 fprintf(stderr, "Error checking path %s: %s (%d)\n", 131 fprintf(stderr, "Error checking path %s: %s (%d)\n",
132 buf, strerror(errno), errno); 132 buf, strerror(errno), errno);
133 free(buf); 133 free(buf);
134 continue; 134 continue;