* 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
| 51 | * symlink chain that started with the original path. |
| 52 | */ |
| 53 | static 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 |
no test coverage detected