Esempio n. 1
0
static int depthfirst_map (flux_t *h, const char *key,
                           int dirskip, restart_map_f cb, void *arg)
{
    flux_future_t *f;
    const flux_kvsdir_t *dir;
    flux_kvsitr_t *itr;
    const char *name;
    int path_level;
    int count = 0;
    int rc = -1;

    path_level = restart_count_char (key + dirskip, '.');
    if (!(f = flux_kvs_lookup (h, NULL, FLUX_KVS_READDIR, key)))
        return -1;
    if (flux_kvs_lookup_get_dir (f, &dir) < 0) {
        if (errno == ENOENT && path_level == 0)
            rc = 0;
        goto done;
    }
    if (!(itr = flux_kvsitr_create (dir)))
        goto done;
    while ((name = flux_kvsitr_next (itr))) {
        char *nkey;
        int n;
        if (!flux_kvsdir_isdir (dir, name))
            continue;
        if (!(nkey = flux_kvsdir_key_at (dir, name)))
            goto done_destroyitr;
        if (path_level == 3) // orig 'key' = .A.B.C, thus 'nkey' is complete
            n = depthfirst_map_one (h, nkey, dirskip, cb, arg);
        else
            n = depthfirst_map (h, nkey, dirskip, cb, arg);
        if (n < 0) {
            int saved_errno = errno;
            free (nkey);
            errno = saved_errno;
            goto done_destroyitr;
        }
        count += n;
        free (nkey);
    }
    rc = count;
done_destroyitr:
    flux_kvsitr_destroy (itr);
done:
    flux_future_destroy (f);
    return rc;
}
Esempio n. 2
0
static int jobid_exist (flux_t *h, int64_t j)
{
    flux_future_t *f = NULL;
    jscctx_t *ctx = getctx (h);
    const char *path = jscctx_jobid_path (ctx, j);
    int rc = -1;

    if (path == NULL)
        goto done;
    if (!(f = flux_kvs_lookup (h, FLUX_KVS_READDIR, path))
                                || flux_kvs_lookup_get_dir (f, NULL) < 0) {
        flux_log (h, LOG_DEBUG, "flux_kvs_lookup(%s): %s",
                     path, flux_strerror (errno));
        goto done;
    }
    rc = 0;
done:
    flux_future_destroy (f);
    return rc;
}