Allow add_path() to add non-existent directories to the path
This function had used make_absolute_path(); but this function dies if the directory that contains the entry whose relative path was supplied in the argument does not exist. This is a problem if the argument is, for example, "../libexec/git-core", and that "../libexec" does not exist. Since the resolution of symbolic links is not required for elements in PATH, we can fall back to using make_nonrelative_path(), which simply prepends $PWD to the path. We have to move make_nonrelative_path() alongside make_absolute_path() in abspath.c so that git-shell can be linked. See 5b8e6f85f. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jul 21, 2008 at 21:19 UTC
10c4c881c4d2cb0ece0508e7142e189e68445257
3 files changed
+37
-37
abspath.c
+36
@@ -66,3 +66,39 @@ const char *make_absolute_path(const char *path)
66
67
return buf;
68
}
69
+
70
+static const char *get_pwd_cwd(void)
71
+{
72
+ static char cwd[PATH_MAX + 1];
73
+ char *pwd;
74
+ struct stat cwd_stat, pwd_stat;
75
+ if (getcwd(cwd, PATH_MAX) == NULL)
76
+ return NULL;
77
+ pwd = getenv("PWD");
78
+ if (pwd && strcmp(pwd, cwd)) {
79
+ stat(cwd, &cwd_stat);
80
+ if (!stat(pwd, &pwd_stat) &&
81
+ pwd_stat.st_dev == cwd_stat.st_dev &&
82
+ pwd_stat.st_ino == cwd_stat.st_ino) {
83
+ strlcpy(cwd, pwd, PATH_MAX);
84
+ }
85
+ }
86
+ return cwd;
87
+}
88
+
89
+const char *make_nonrelative_path(const char *path)
90
+{
91
+ static char buf[PATH_MAX + 1];
92
+
93
+ if (is_absolute_path(path)) {
94
+ if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
95
+ die("Too long path: %.*s", 60, path);
96
+ } else {
97
+ const char *cwd = get_pwd_cwd();
98
+ if (!cwd)
99
+ die("Cannot determine the current working directory");
100
+ if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
101
+ die("Too long path: %.*s", 60, path);
102
+ }
103
+ return buf;
104
+}
exec_cmd.c
+1
-1
@@ -50,7 +50,7 @@ static void add_path(struct strbuf *out, const char *path)
50
if (is_absolute_path(path))
51
strbuf_addstr(out, path);
52
else
53
- strbuf_addstr(out, make_absolute_path(path));
53
+ strbuf_addstr(out, make_nonrelative_path(path));
54
55
strbuf_addch(out, PATH_SEP);
56
}
path.c
-36
@@ -291,42 +291,6 @@ int adjust_shared_perm(const char *path)
291
return 0;
292
}
293
294
-static const char *get_pwd_cwd(void)
295
-{
296
- static char cwd[PATH_MAX + 1];
297
- char *pwd;
298
- struct stat cwd_stat, pwd_stat;
299
- if (getcwd(cwd, PATH_MAX) == NULL)
300
- return NULL;
301
- pwd = getenv("PWD");
302
- if (pwd && strcmp(pwd, cwd)) {
303
- stat(cwd, &cwd_stat);
304
- if (!stat(pwd, &pwd_stat) &&
305
- pwd_stat.st_dev == cwd_stat.st_dev &&
306
- pwd_stat.st_ino == cwd_stat.st_ino) {
307
- strlcpy(cwd, pwd, PATH_MAX);
308
- }
309
- }
310
- return cwd;
311
-}
312
-
313
-const char *make_nonrelative_path(const char *path)
314
-{
315
- static char buf[PATH_MAX + 1];
316
-
317
- if (is_absolute_path(path)) {
318
- if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
319
- die ("Too long path: %.*s", 60, path);
320
- } else {
321
- const char *cwd = get_pwd_cwd();
322
- if (!cwd)
323
- die("Cannot determine the current working directory");
324
- if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
325
- die ("Too long path: %.*s", 60, path);
326
- }
327
- return buf;
328
-}
329
-
294
const char *make_relative_path(const char *abs, const char *base)
295
{
296
static char buf[PATH_MAX + 1];