Skip to content

Commit

Permalink
jobs: fix cache locality check
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Jul 11, 2024
1 parent 8d5bd8b commit 92a2704
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ static int job_read_outputs(struct job *job, cJSON *outputs)
/* for nix-eval-jobs output only, for dag use the htab instead */
struct job *job_search(struct job *job, const char *drv)
{
if (strcmp(drv, job->drv_path))
if (!strcmp(drv, job->drv_path))
return job;

for (size_t i = 0; i < job->deps_filled; i++) {
if (strcmp(drv, job->deps[i]->drv_path))
if (!strcmp(drv, job->deps[i]->drv_path))
return job->deps[i];
}

Expand Down Expand Up @@ -274,10 +274,8 @@ static int job_read_cache(struct job *job)

j = job_search(job, trim(line));
if (j == NULL) {
/* bug in nix-eval-jobs or nix-build */
print_err("%s", "could not find job");
ret = -ESRCH;
goto out_free_line;
/* nix-eval-jobs doesn't count src */
continue;
}

if (in_fetched_block)
Expand All @@ -297,9 +295,11 @@ static int job_read_cache(struct job *job)
}

/* remove stale deps */
for (size_t i = 0; i < job->deps_filled; i++) {
for (size_t i = 0; i < job->deps_filled;) {
if (job->deps[i]->stale)
job_free(job->deps[i]);
else
i++;
}

out_free_line:
Expand Down
8 changes: 8 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,16 @@ int run(const char *file, char *argv[])

char *trim(char *s)
{
size_t end, i;

while (isspace(*s))
s++;

for (i = 0, end = 0; s[i]; i++) {
if (isgraph(s[i]))
end = i + 1;
}
s[end] = '\0';

return s;
}

0 comments on commit 92a2704

Please sign in to comment.