fix path join '/'
add joinpath() function to handle this.
This commit is contained in:
parent
c13c411950
commit
fc60d78d89
|
@ -140,13 +140,25 @@ err:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = snprintf(buf, bufsiz, "%s%s%s",
|
||||||
|
repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
|
||||||
|
if (r == -1 || (size_t)r >= bufsiz)
|
||||||
|
errx(1, "path truncated: '%s%s%s'",
|
||||||
|
path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const git_error *e = NULL;
|
const git_error *e = NULL;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[PATH_MAX], repodirabs[PATH_MAX + 1];
|
char path[PATH_MAX], repodirabs[PATH_MAX + 1];
|
||||||
int i, r, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "%s [repodir...]\n", argv[0]);
|
fprintf(stderr, "%s [repodir...]\n", argv[0]);
|
||||||
|
@ -176,20 +188,12 @@ main(int argc, char *argv[])
|
||||||
name = "";
|
name = "";
|
||||||
|
|
||||||
/* read description or .git/description */
|
/* read description or .git/description */
|
||||||
description[0] = '\0';
|
joinpath(path, sizeof(path), repodir, "description");
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
|
|
||||||
if (!(fp = fopen(path, "r"))) {
|
if (!(fp = fopen(path, "r"))) {
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, ".git/description");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
|
|
||||||
fp = fopen(path, "r");
|
fp = fopen(path, "r");
|
||||||
}
|
}
|
||||||
|
description[0] = '\0';
|
||||||
if (fp) {
|
if (fp) {
|
||||||
if (!fgets(description, sizeof(description), fp))
|
if (!fgets(description, sizeof(description), fp))
|
||||||
description[0] = '\0';
|
description[0] = '\0';
|
||||||
|
@ -197,20 +201,12 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read owner or .git/owner */
|
/* read owner or .git/owner */
|
||||||
owner[0] = '\0';
|
joinpath(path, sizeof(path), repodir, "owner");
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "owner");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "owner");
|
|
||||||
if (!(fp = fopen(path, "r"))) {
|
if (!(fp = fopen(path, "r"))) {
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, ".git/owner");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/owner");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/owner");
|
|
||||||
fp = fopen(path, "r");
|
fp = fopen(path, "r");
|
||||||
}
|
}
|
||||||
|
owner[0] = '\0';
|
||||||
if (fp) {
|
if (fp) {
|
||||||
if (!fgets(owner, sizeof(owner), fp))
|
if (!fgets(owner, sizeof(owner), fp))
|
||||||
owner[0] = '\0';
|
owner[0] = '\0';
|
||||||
|
|
39
stagit.c
39
stagit.c
|
@ -970,6 +970,18 @@ err:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = snprintf(buf, bufsiz, "%s%s%s",
|
||||||
|
repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
|
||||||
|
if (r == -1 || (size_t)r >= bufsiz)
|
||||||
|
errx(1, "path truncated: '%s%s%s'",
|
||||||
|
path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -978,13 +990,14 @@ main(int argc, char *argv[])
|
||||||
const git_error *e = NULL;
|
const git_error *e = NULL;
|
||||||
FILE *fp, *fpread;
|
FILE *fp, *fpread;
|
||||||
char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
|
char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
|
||||||
int r, status;
|
int status;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr, "%s <repodir>\n", argv[0]);
|
fprintf(stderr, "%s <repodir>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
repodir = argv[1];
|
repodir = argv[1];
|
||||||
|
|
||||||
if (!realpath(repodir, repodirabs))
|
if (!realpath(repodir, repodirabs))
|
||||||
err(1, "realpath");
|
err(1, "realpath");
|
||||||
|
|
||||||
|
@ -1017,17 +1030,9 @@ main(int argc, char *argv[])
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
/* read description or .git/description */
|
/* read description or .git/description */
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, "description");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
|
|
||||||
if (!(fpread = fopen(path, "r"))) {
|
if (!(fpread = fopen(path, "r"))) {
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, ".git/description");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
|
|
||||||
fpread = fopen(path, "r");
|
fpread = fopen(path, "r");
|
||||||
}
|
}
|
||||||
if (fpread) {
|
if (fpread) {
|
||||||
|
@ -1037,17 +1042,9 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read url or .git/url */
|
/* read url or .git/url */
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, "url");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
|
|
||||||
if (!(fpread = fopen(path, "r"))) {
|
if (!(fpread = fopen(path, "r"))) {
|
||||||
r = snprintf(path, sizeof(path), "%s%s%s",
|
joinpath(path, sizeof(path), repodir, ".git/url");
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
|
|
||||||
if (r == -1 || (size_t)r >= sizeof(path))
|
|
||||||
errx(1, "path truncated: '%s%s%s'",
|
|
||||||
repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
|
|
||||||
fpread = fopen(path, "r");
|
fpread = fopen(path, "r");
|
||||||
}
|
}
|
||||||
if (fpread) {
|
if (fpread) {
|
||||||
|
|
Loading…
Reference in a new issue