Example #1
0
string
edit_main_rep::get_metadata (string kind) {
  string var= "global-" * kind;
  string val= get_init_string (var);
  if (val != "") return val;
  val= search_metadata (subtree (et, rp), kind);
  if (val != "") return val;
  if (kind == "title") return as_string (tail (get_name ()));
#ifndef __MINGW32__
  if (kind == "author" &&
      !is_none (resolve_in_path ("finger")) &&
      !is_none (resolve_in_path ("sed"))) {
    string val= var_eval_system ("finger `whoami` | sed -e '/Name/!d' -e 's/.*Name: //'");
    if (N(val) > 1) return utf8_to_cork (val);
  }
#endif
  return "";
}
Example #2
0
int do_search_metadata(FILE *input, char *zone_name, option_flags oflags) {
    int item_count  = 0;
    int error_count = 0;

    rodsEnv env;
    rcComm_t *conn = rods_login(&env);
    if (!conn) goto error;

    while (!feof(input)) {
        size_t jflags = JSON_DISABLE_EOF_CHECK | JSON_REJECT_DUPLICATES;
        json_error_t load_error;
        json_t *target = json_loadf(input, jflags, &load_error);
        if (!target) {
            if (!feof(input)) {
                logmsg(ERROR, "JSON error at line %d, column %d: %s",
                       load_error.line, load_error.column, load_error.text);
            }

            continue;
        }

        item_count++;
        if (!json_is_object(target)) {
            logmsg(ERROR, "Item %d in stream was not a JSON object; skipping",
                   item_count);
            error_count++;
            json_decref(target);
            continue;
        }

        json_t *results = NULL;

        if (has_collection(target)) {
            baton_error_t resolve_error;
            resolve_collection(target, conn, &env, oflags, &resolve_error);

            if (add_error_report(target, &resolve_error)) {
                error_count++;
            }
            else {
                baton_error_t search_error;
                results = search_metadata(conn, target, zone_name, oflags,
                                          &search_error);
                if (add_error_report(target, &search_error)) {
                    error_count++;
                    print_json(target);
                }
                else {
                    print_json(results);
                }
            }
        }
        else {
            baton_error_t search_error;
            results = search_metadata(conn, target, zone_name, oflags,
                                      &search_error);
            if (add_error_report(target, &search_error)) {
                error_count++;
                print_json(target);
            }
            else {
                print_json(results);
            }
        }

        if (unbuffered_flag) fflush(stdout);

        if (results) json_decref(results);
        json_decref(target);
    } // while

    rcDisconnect(conn);

    if (error_count > 0) {
        logmsg(WARN, "Processed %d items with %d errors",
               item_count, error_count);
    }
    else {
        logmsg(DEBUG, "Processed %d items with %d errors",
               item_count, error_count);
    }

    return error_count;

error:
    if (conn) rcDisconnect(conn);

    logmsg(ERROR, "Processed %d items with %d errors", item_count, error_count);

    return 1;
}