diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-06-25 10:09:51 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-06-25 11:41:36 +0530 |
commit | cc02eba1d357dde0132593649c67a194750fe37d (patch) | |
tree | f21ed36fb32415faeb09b042bbb53d43c6043f0f /src/jobs.c | |
parent | 129082adfc234cdc2481d98b7f523a75126a0cf1 (diff) |
jobs: check cache status of derivations
Diffstat (limited to 'src/jobs.c')
-rw-r--r-- | src/jobs.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -1,4 +1,5 @@ #include <errno.h> +#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -204,6 +205,32 @@ static int job_read_outputs(struct job *job, cJSON *outputs) return 0; } +static int job_read_cache(struct job *job, cJSON *is_cached) +{ + int ret; + + if (cJSON_IsFalse(is_cached)) { + job->insubstituters = false; + return JOB_READ_SUCCESS; + } + + for (size_t i = 0; i < job->outputs_filled; i++) { + ret = access(job->outputs[i]->store_path, F_OK); + if (ret == 0) + continue; + + if (errno == ENOENT || errno == ENOTDIR) { + job->insubstituters = true; + return JOB_READ_SUCCESS; + } else { + print_err("%s", strerror(errno)); + return --errno; + } + } + + return JOB_READ_CACHED; +} + int job_read(FILE *stream, struct job **job) { cJSON *temp; @@ -263,6 +290,15 @@ int job_read(FILE *stream, struct job **job) if (ret < 0) goto out_free; + temp = cJSON_GetObjectItemCaseSensitive(root, "isCached"); + if (!cJSON_IsBool(temp)) { + ret = JOB_READ_JSON_INVAL; + goto out_free; + } + ret = job_read_cache(j, temp); + if (ret < 0) + goto out_free; + out_free: cJSON_Delete(root); if (ret != JOB_READ_SUCCESS) @@ -366,11 +402,12 @@ out_free_job: int jobs_init(FILE **stream, char *expr) { size_t argindex; - char *args[4]; + char *args[5]; int ret; argindex = 0; args[argindex++] = "nix-eval-jobs"; + args[argindex++] = "--check-cache-status"; if (evanix_opts.isflake) args[argindex++] = "--flake"; args[argindex++] = expr; |