in is_git_repo(), actually verify presence of git repository dirs and files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/lib/repository.c b/lib/repository.c
index 630a646..c13711c 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -15,6 +15,7 @@
*/
#include <sys/queue.h>
+#include <sys/stat.h>
#include <limits.h>
#include <stdlib.h>
@@ -110,11 +111,30 @@ is_git_repo(struct got_repository *repo)
char *path_objects = got_repo_get_path_objects(repo);
char *path_refs = got_repo_get_path_refs(repo);
char *path_head = get_path_head(repo);
- int ret;
+ int ret = 0;
+ struct stat sb;
- ret = (path_git != NULL) && (path_objects != NULL) &&
- (path_refs != NULL) && (path_head != NULL);
+ if (lstat(path_git, &sb) == -1)
+ goto done;
+ if (!S_ISDIR(sb.st_mode))
+ goto done;
+
+ if (lstat(path_objects, &sb) == -1)
+ goto done;
+ if (!S_ISDIR(sb.st_mode))
+ goto done;
+ if (lstat(path_refs, &sb) == -1)
+ goto done;
+ if (!S_ISDIR(sb.st_mode))
+ goto done;
+
+ if (lstat(path_head, &sb) == -1)
+ goto done;
+ if (!S_ISREG(sb.st_mode))
+ goto done;
+ ret = 1;
+done:
free(path_git);
free(path_objects);
free(path_refs);