コード例 #1
0
ファイル: json.c プロジェクト: sahib/rmlint
static void rm_fmt_head(RmSession *session, _UNUSED RmFmtHandler *parent, FILE *out) {
    fprintf(out, "[\n");

    RmFmtHandlerJSON *self = (RmFmtHandlerJSON *)parent;
    self->id_set = g_hash_table_new(NULL, NULL);

    if(rm_fmt_get_config_value(session->formats, "json", "oneline")) {
        self->pretty = false;
    }

    if(!rm_fmt_get_config_value(session->formats, "json", "no_header")) {
        rm_fmt_json_open(self, out);
        {
            rm_fmt_json_key(out, "description", "rmlint json-dump of lint files");
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key(out, "cwd", session->cfg->iwd);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key(out, "args", session->cfg->joined_argv);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key(out, "version", RM_VERSION);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key(out, "rev", RM_VERSION_GIT_REVISION);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "progress", 0); /* Header is always first. */
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key(out, "checksum_type",
                            rm_digest_type_to_string(session->cfg->checksum_type));
            if(session->hash_seed) {
                rm_fmt_json_sep(self, out);
                rm_fmt_json_key_int(out, "hash_seed", session->hash_seed);
            }
        }
        rm_fmt_json_close(self, out);
    }
}
コード例 #2
0
ファイル: progressbar.c プロジェクト: tomhoover/rmlint
static void rm_fmt_prog(RmSession *session,
                        RmFmtHandler *parent,
                        FILE *out,
                        RmFmtProgressState state) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *)parent;

    bool force_draw = false;

    if(self->timer == NULL) {
        self->timer = g_timer_new();
        force_draw = true;
    }

    if(state == RM_PROGRESS_STATE_SUMMARY) {
        return;
    }

    if(session->replay_files.length > 0) {
        /* Makes not much sense to print a progressbar with --replay */
        return;
    }

    if(state == RM_PROGRESS_STATE_INIT) {
        /* Do initializiation here */
        const char *update_interval_str =
            rm_fmt_get_config_value(session->formats, "progressbar", "update_interval");

        self->plain = true;
        if(rm_fmt_get_config_value(session->formats, "progressbar", "fancy") != NULL) {
            self->plain = false;
        }

        self->use_unicode_glyphs = true;
        if(rm_fmt_get_config_value(session->formats, "progressbar", "ascii") != NULL) {
            self->use_unicode_glyphs = false;
        }

        if(update_interval_str) {
            self->update_interval = g_ascii_strtoull(update_interval_str, NULL, 10);
        }

        if(self->update_interval == 0) {
            self->update_interval = 50; /* milliseconds */
        }

        fprintf(out, "\e[?25l"); /* Hide the cursor */
        fflush(out);
        return;
    }

    if(state == RM_PROGRESS_STATE_PRE_SHUTDOWN || rm_session_was_aborted()) {
        fprintf(out, "\e[?25h"); /* show the cursor */
        fflush(out);

        if(rm_session_was_aborted()) {
            return;
        }
    }
コード例 #3
0
ファイル: progressbar.c プロジェクト: arthurtiteica/rmlint
static void rm_fmt_prog(RmSession *session,
                        RmFmtHandler *parent,
                        FILE *out,
                        RmFmtProgressState state) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *)parent;
    if(state == RM_PROGRESS_STATE_SUMMARY) {
        return;
    }

    if(state == RM_PROGRESS_STATE_INIT) {
        /* Do initializiation here */
        const char *update_interval_str =
            rm_fmt_get_config_value(session->formats, "progressbar", "update_interval");

        self->plain = true;
        if(rm_fmt_get_config_value(session->formats, "progressbar", "fancy") != NULL) {
            self->plain = false;
        }

        self->use_unicode_glyphs = true;
        if(rm_fmt_get_config_value(session->formats, "progressbar", "ascii") != NULL) {
            self->use_unicode_glyphs = false;
        }

        if(update_interval_str) {
            self->update_interval = g_ascii_strtoull(update_interval_str, NULL, 10);
        }

        if(self->update_interval == 0) {
            self->update_interval = 50;
        }

        self->last_unknown_pos = 0;
        self->total_lint_bytes = 1;

        fprintf(out, "\e[?25l"); /* Hide the cursor */
        fflush(out);
        return;
    }

    if(state == RM_PROGRESS_STATE_PRE_SHUTDOWN || rm_session_was_aborted(session)) {
        fprintf(out, "\e[?25h"); /* show the cursor */
        fflush(out);

        if(rm_session_was_aborted(session)) {
            return;
        }
    }
コード例 #4
0
ファイル: progressbar.c プロジェクト: mentat-fr/rmlint
static void rm_fmt_prog(
    RmSession *session,
    RmFmtHandler *parent,
    FILE *out,
    RmFmtProgressState state
) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *) parent;

    if(state == RM_PROGRESS_STATE_INIT) {
        /* Do initializiation here */
        const char *update_interval_str = rm_fmt_get_config_value(
                                              session->formats, "progressbar", "update_interval"
                                          );

        if(update_interval_str) {
            self->update_interval = g_ascii_strtoull(update_interval_str, NULL, 10);
        }

        if(self->update_interval == 0) {
            self->update_interval = 50;
        }

        self->last_unknown_pos = 0;

        fprintf(out, "\e[?25l"); /* Hide the cursor */
        fflush(out);
        return;
    }

    if(state == RM_PROGRESS_STATE_SUMMARY || rm_session_was_aborted(session)) {
        fprintf(out, "\e[?25h"); /* show the cursor */
        fflush(out);
    }
コード例 #5
0
ファイル: json.c プロジェクト: sahib/rmlint
static void rm_fmt_foot(_UNUSED RmSession *session, RmFmtHandler *parent, FILE *out) {
    RmFmtHandlerJSON *self = (RmFmtHandlerJSON *)parent;

    if(rm_fmt_get_config_value(session->formats, "json", "no_footer")) {
        fprintf(out, "{}");
    } else {
        rm_fmt_json_open(self, out);
        {
            rm_fmt_json_key_bool(out, "aborted", rm_session_was_aborted());
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "progress", 100); /* Footer is always last. */
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "total_files", session->total_files);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "ignored_files", session->ignored_files);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "ignored_folders", session->ignored_folders);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "duplicates", session->dup_counter);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "duplicate_sets", session->dup_group_counter);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "total_lint_size", session->total_lint_size);
        }
        if(self->pretty) {
            fprintf(out, "\n}");
        } else {
            fprintf(out, "}\n");
        }
    }

    fprintf(out, "]\n");
    g_hash_table_unref(self->id_set);
}
コード例 #6
0
ファイル: csv.c プロジェクト: FihlaTV/rmlint
static void rm_fmt_head(_UNUSED RmSession *session, _UNUSED RmFmtHandler *parent, FILE *out) {
    if(rm_fmt_get_config_value(session->formats, "csv", "no_header")) {
        return;
    }

    fprintf(out, "%s%s%s%s%s%s%s\n", "type", CSV_SEP, "path", CSV_SEP, "size", CSV_SEP,
            "checksum");
}
コード例 #7
0
ファイル: timestamp.c プロジェクト: arthurtiteica/rmlint
static void rm_fmt_prog(RmSession *session,
                        _U RmFmtHandler *parent,
                        _U FILE *out,
                        RmFmtProgressState state) {
    if(state != RM_PROGRESS_STATE_INIT) {
        return;
    }

    if(rm_fmt_get_config_value(session->formats, "stamp", "iso8601")) {
        char time_buf[256];
        memset(time_buf, 0, sizeof(time_buf));
        rm_iso8601_format(time(NULL), time_buf, sizeof(time_buf));
        fprintf(out, "%s", time_buf);
    } else {
        /* Just write out current time */
        fprintf(out, "%" LLU "", (guint64)time(NULL));
    }
}
コード例 #8
0
ファイル: json.c プロジェクト: sahib/rmlint
static void rm_fmt_elem(RmSession *session, _UNUSED RmFmtHandler *parent, FILE *out,
                        RmFile *file) {
    if(rm_fmt_get_config_value(session->formats, "json", "no_body")) {
        return;
    }
    if(file->lint_type == RM_LINT_TYPE_UNIQUE_FILE &&
       (!file->digest || !session->cfg->write_unfinished)) {
        /* unique file with no partial checksum */
        return;
    }

    char checksum_str[rm_digest_get_bytes(file->digest) * 2 + 1];
    rm_fmt_json_cksum(file, checksum_str, sizeof(checksum_str));

    RmFmtHandlerJSON *self = (RmFmtHandlerJSON *)parent;

    /* Make it look like a json element */
    rm_fmt_json_open(self, out);
    {
        RM_DEFINE_PATH(file);

        rm_fmt_json_key_int(out, "id",
                            rm_fmt_json_generate_id(self, file, file_path, checksum_str));
        rm_fmt_json_sep(self, out);
        rm_fmt_json_key(out, "type", rm_file_lint_type_to_string(file->lint_type));
        rm_fmt_json_sep(self, out);

        gdouble progress = 0;
        if(session->shred_bytes_after_preprocess) {
            progress = CLAMP(100 -
                      100 * ((gdouble)session->shred_bytes_remaining /
                             (gdouble)session->shred_bytes_after_preprocess),
                      0, 100);
        }
        rm_fmt_json_key_int(out, "progress", progress);
        rm_fmt_json_sep(self, out);

        if(file->digest) {
            rm_fmt_json_key(out, "checksum", checksum_str);
            rm_fmt_json_sep(self, out);
        }

        rm_fmt_json_key_unsafe(out, "path", file_path);
        rm_fmt_json_sep(self, out);
        if(file->lint_type != RM_LINT_TYPE_UNIQUE_FILE) {
            rm_fmt_json_key_int(out, "size", file->actual_file_size);
            rm_fmt_json_sep(self, out);
            if(file->twin_count >= 0) {
                rm_fmt_json_key_int(out, "twins", file->twin_count);
                rm_fmt_json_sep(self, out);
            }
            rm_fmt_json_key_int(out, "depth", file->depth);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "inode", file->inode);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_int(out, "disk_id", file->dev);
            rm_fmt_json_sep(self, out);
            rm_fmt_json_key_bool(out, "is_original", file->is_original);
            rm_fmt_json_sep(self, out);

            if(session->cfg->find_hardlinked_dupes) {
                RmFile *hardlink_head = RM_FILE_HARDLINK_HEAD(file);

                if(hardlink_head && hardlink_head != file) {
                    char orig_checksum_str[rm_digest_get_bytes(file->digest) * 2 + 1];
                    rm_fmt_json_cksum(hardlink_head, orig_checksum_str,
                                      sizeof(orig_checksum_str));

                    RM_DEFINE_PATH(hardlink_head);

                    guint32 orig_id = rm_fmt_json_generate_id(
                        self, hardlink_head, hardlink_head_path, orig_checksum_str);

                    rm_fmt_json_key_int(out, "hardlink_of", orig_id);
                    rm_fmt_json_sep(self, out);
                }
            }
        }
        rm_fmt_json_key_float(out, "mtime", file->mtime);
    }
    rm_fmt_json_close(self, out);
}