MCPcopy Create free account
hub / github.com/git/git / resolve_symlink

Function resolve_symlink

lockfile.c:53–75  ·  view source on GitHub ↗

* path contains a path that might be a symlink. * * If path is a symlink, attempt to overwrite it with a path to the * real file or directory (which may or may not exist), following a * chain of symlinks if necessary. Otherwise, leave path unmodified. * * This is a best-effort routine. If an error occurs, path will * either be left unmodified or will name a different symlink in a * symli

Source from the content-addressed store, hash-verified

51 * symlink chain that started with the original path.
52 */
53static void resolve_symlink(struct strbuf *path)
54{
55 int depth = MAXDEPTH;
56 static struct strbuf link = STRBUF_INIT;
57
58 while (depth--) {
59 if (strbuf_readlink(&link, path->buf, path->len) < 0)
60 break;
61
62 if (is_absolute_path(link.buf))
63 /* absolute path simply replaces p */
64 strbuf_reset(path);
65 else
66 /*
67 * link is a relative path, so replace the
68 * last element of p with it.
69 */
70 trim_last_path_component(path);
71
72 strbuf_addbuf(path, &link);
73 }
74 strbuf_reset(&link);
75}
76
77/*
78 * Lock PID file functions - write PID to a foo~pid.lock file alongside

Callers 1

lock_fileFunction · 0.85

Calls 4

strbuf_readlinkFunction · 0.85
is_absolute_pathFunction · 0.85
trim_last_path_componentFunction · 0.85
strbuf_addbufFunction · 0.85

Tested by

no test coverage detected