commit c00c1428ccaedc2d63d9d489c00d796d5718f615 from: Omar Polo date: Fri Mar 25 22:45:03 2022 UTC get rid of realpath during load it has a non-ignorable cost over NFS (sdk@ reported ~30 seconds to load 64k songs, and up to 5 minutes over wifi!) and don't provide us any real gain: files can still vanish after being imported or may appear later. The only advantage of realpath was that it would clean up the path from segments like "/./" and resolve the ".." components, but that's a minor issue anyway. prodded by, discussed with and tested by sdk@, thanks a lot! commit - d9cc6713e033478672564bf0bf4b273a74576dc3 commit + c00c1428ccaedc2d63d9d489c00d796d5718f615 blob - 127bb7da54a575fed3583b9871f1eca2479cd134 blob + 9ce661e70cec13ade9907e5e2d49b0b438b77b2c --- ctl.c +++ ctl.c @@ -272,8 +272,8 @@ show_load(struct parse_result *res, struct imsg *imsg, FILE *f; const char *file; char *line = NULL; - char path[PATH_MAX]; - size_t linesize = 0, i = 0; + char path[PATH_MAX], cwd[PATH_MAX]; + size_t linesize = 0, i = 0, n; ssize_t linelen, curr = -1; if (imsg->hdr.type == IMSG_CTL_ERR) { @@ -299,6 +299,9 @@ show_load(struct parse_result *res, struct imsg *imsg, return 1; } + if (getcwd(cwd, sizeof(cwd)) == NULL) + fatal("getcwd"); + while ((linelen = getline(&line, &linesize, f)) != -1) { if (linelen == 0) continue; @@ -310,10 +313,16 @@ show_load(struct parse_result *res, struct imsg *imsg, } if (file[0] == ' ' && file[1] == ' ') file += 2; + if (file[0] == '.' && file[1] == '/') + file += 2; - memset(&path, 0, sizeof(path)); - if (realpath(file, path) == NULL) { - log_warn("realpath %s", file); + if (*file == '/') + n = strlcpy(path, file, sizeof(path)); + else + n = snprintf(path, sizeof(path), "%s/%s", cwd, file); + + if (n >= sizeof(path)) { + log_warnx("path too long: %s", file); continue; }