static int process_file(const char *file, int *total) { Db *db; couchstore_error_t errcode; int count = 0; errcode = couchstore_open_db(file, COUCHSTORE_OPEN_FLAG_RDONLY, &db); if (errcode != COUCHSTORE_SUCCESS) { fprintf(stderr, "Failed to open \"%s\": %s\n", file, couchstore_strerror(errcode)); return -1; } else { fprintf(stderr, "Dumping \"%s\":\n", file); } switch (mode) { case DumpBySequence: if (dumpTree) { errcode = couchstore_walk_seq_tree(db, 0, COUCHSTORE_INCLUDE_CORRUPT_DOCS, visit_node, &count); } else { errcode = couchstore_changes_since(db, 0, COUCHSTORE_INCLUDE_CORRUPT_DOCS, foldprint, &count); } break; case DumpByID: if (dumpTree) { errcode = couchstore_walk_id_tree(db, NULL, COUCHSTORE_INCLUDE_CORRUPT_DOCS, visit_node, &count); } else if (oneKey) { DocInfo* info; errcode = couchstore_docinfo_by_id(db, dumpKey.buf, dumpKey.size, &info); if (errcode == COUCHSTORE_SUCCESS) { foldprint(db, info, &count); couchstore_free_docinfo(info); } } else { errcode = couchstore_all_docs(db, NULL, COUCHSTORE_INCLUDE_CORRUPT_DOCS, foldprint, &count); } break; case DumpLocals: errcode = couchstore_print_local_docs(db, &count); break; } (void)couchstore_close_db(db); if (errcode < 0) { fprintf(stderr, "Failed to dump database \"%s\": %s\n", file, couchstore_strerror(errcode)); return -1; } *total += count; return 0; }
static int process_file(const char *file, int *total) { Db *db; couchstore_error_t errcode; errcode = couchstore_open_db(file, COUCHSTORE_OPEN_FLAG_RDONLY, &db); if (errcode != COUCHSTORE_SUCCESS) { fprintf(stderr, "Failed to open \"%s\": %s\n", file, couchstore_strerror(errcode)); return -1; } int count = 0; switch (mode) { case DumpBySequence: if (dumpTree) { errcode = couchstore_walk_seq_tree(db, 0, COUCHSTORE_INCLUDE_CORRUPT_DOCS, visit_node, &count); } else { errcode = couchstore_changes_since(db, 0, COUCHSTORE_INCLUDE_CORRUPT_DOCS, foldprint, &count); } break; case DumpByID: if (dumpTree) { errcode = couchstore_walk_id_tree(db, NULL, COUCHSTORE_INCLUDE_CORRUPT_DOCS, visit_node, &count); } else { errcode = couchstore_all_docs(db, NULL, COUCHSTORE_INCLUDE_CORRUPT_DOCS, foldprint, &count); } break; } (void)couchstore_close_db(db); if (errcode < 0) { fprintf(stderr, "Failed to dump database \"%s\": %s\n", file, couchstore_strerror(errcode)); return -1; } *total += count; return 0; }