Teach get_refdir() about FreeBSD's /usr/obj convention.

In development, I run libarchive_test frequently by hand
and it gets tedious having to specify a suitable -r path
all of the time.
This commit is contained in:
Tim Kientzle 2008-12-21 00:13:50 +00:00
parent e43c1fe0bc
commit fec90b6c9b

View File

@ -846,48 +846,59 @@ extract_reference_file(const char *name)
static char * static char *
get_refdir(const char *tmpdir) get_refdir(const char *tmpdir)
{ {
char *ref, *p; char tried[512] = { '\0' };
char buff[128];
char *pwd, *p;
/* Get the current dir. */ /* Get the current dir. */
systemf("/bin/pwd > %s/refdir", tmpdir); systemf("/bin/pwd > %s/refdir", tmpdir);
ref = slurpfile(NULL, "%s/refdir", tmpdir); pwd = slurpfile(NULL, "%s/refdir", tmpdir);
p = ref + strlen(ref); while (pwd[strlen(pwd) - 1] == '\n')
while (p[-1] == '\n') { pwd[strlen(pwd) - 1] = '\0';
--p; printf("PWD: %s\n", pwd);
*p = '\0';
}
systemf("rm %s/refdir", tmpdir); systemf("rm %s/refdir", tmpdir);
/* Look for a known file. */ /* Look for a known file. */
p = slurpfile(NULL, "%s/%s", ref, KNOWNREF); snprintf(buff, sizeof(buff), "%s", pwd);
if (p != NULL) { p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
free(p); if (p != NULL) goto success;
return (ref); strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
} strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
p = slurpfile(NULL, "%s/test/%s", ref, KNOWNREF);
if (p != NULL) { snprintf(buff, sizeof(buff), "%s/test", pwd);
free(p); p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
p = malloc(strlen(ref) + strlen("/test") + 1); if (p != NULL) goto success;
strcpy(p, ref); strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strcat(p, "/test"); strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
free(ref);
return (p); snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
} p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
p = slurpfile(NULL, "%s/%s/test/%s", ref, LIBRARY, KNOWNREF); if (p != NULL) goto success;
if (p != NULL) { strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
free(p); strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
p = malloc(strlen(ref) + 1 + strlen(LIBRARY) + strlen("/test") + 1);
strcpy(p, ref); if (memcmp(pwd, "/usr/obj", 8) == 0) {
strcat(p, "/"); snprintf(buff, sizeof(buff), "%s", pwd + 8);
strcat(p, LIBRARY); p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
strcat(p, "/test"); if (p != NULL) goto success;
free(ref); strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
return (p); strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
if (p != NULL) goto success;
strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
} }
printf("Unable to locate known reference file %s\n", KNOWNREF); printf("Unable to locate known reference file %s\n", KNOWNREF);
printf(" Checked directory %s\n", ref); printf(" Checked following directories:\n%s\n", tried);
printf(" Checked directory %s/test\n", ref);
printf(" Checked directory %s/%s/test\n", ref, LIBRARY);
exit(1); exit(1);
success:
free(p);
free(pwd);
return strdup(buff);
} }
int main(int argc, char **argv) int main(int argc, char **argv)