commit deeca23839609f94e076f97f16d1d7cde09daf3b from: Stefan Sperling date: Mon Mar 12 19:41:51 2018 UTC in is_git_repo(), actually verify presence of git repository dirs and files commit - 22eb897338c1f91ec8dfa725dd84ab38ed2b1aeb commit + deeca23839609f94e076f97f16d1d7cde09daf3b blob - 630a646167f300de74854bdd0b0098adaa34938e blob + c13711cf098cbc488fdb86c373f4b4d4461cb3f5 --- lib/repository.c +++ lib/repository.c @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -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);