コード例 #1
0
ファイル: pretty.c プロジェクト: albertnet/rmlint
static void rm_fmt_elem(_U RmSession *session, RmFmtHandler *parent, FILE *out,
                        RmFile *file) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *)parent;

    if(file->lint_type == RM_LINT_TYPE_UNIQUE_FILE) {
        /* pretty output should not contain this */
        return;
    }

    self->elems_written++;

    if(file->lint_type != self->last_lint_type) {
        fprintf(out, "\n%s#%s %s:\n", MAYBE_YELLOW(out, session),
                MAYBE_RESET(out, session),
                _(RM_LINT_TYPE_TO_DESCRIPTION[file->lint_type]));
        self->last_lint_type = file->lint_type;
    }

    fprintf(out, "    %s", rm_fmt_command_color(session, file, out));

    const char *format = RM_LINT_TYPE_TO_COMMAND[file->lint_type];
    switch(file->lint_type) {
    case RM_LINT_TYPE_BADUID:
        fprintf(out, format, self->user);
        break;
    case RM_LINT_TYPE_BADGID:
        fprintf(out, format, self->group);
        break;
    case RM_LINT_TYPE_BADUGID:
        fprintf(out, format, self->user, self->group);
        break;
    case RM_LINT_TYPE_DUPE_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    case RM_LINT_TYPE_DUPE_DIR_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls -la");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    default:
        fprintf(out, "%s", format);
    }

    RM_DEFINE_PATH(file);
    char *esc_path = rm_util_strsub(file_path, "'", "'\"'\"'");
    fprintf(out, "%s '%s'\n", MAYBE_RESET(out, session), esc_path);
    g_free(esc_path);
}
コード例 #2
0
ファイル: csv.c プロジェクト: FihlaTV/rmlint
static void rm_fmt_elem(_UNUSED RmSession *session, _UNUSED RmFmtHandler *parent, FILE *out,
                        RmFile *file) {
    if (file->lint_type == RM_LINT_TYPE_UNIQUE_FILE && (!file->digest || !session->cfg->write_unfinished)) {
        /* unique file with no partial checksum */
        return;
         /* TODO: add option to output all unique files */
    }
    char checksum_str[rm_digest_get_bytes(file->digest) * 2 + 1];
    memset(checksum_str, '0', sizeof(checksum_str));
    checksum_str[sizeof(checksum_str) - 1] = 0;

    if(file->digest) {
        rm_digest_hexstring(file->digest, checksum_str);
    }

    /* Escape quotes in the path (refer http://tools.ietf.org/html/rfc4180, item 6)*/
    RM_DEFINE_PATH(file);
    char *clean_path = rm_util_strsub(file_path, CSV_QUOTE, CSV_QUOTE "" CSV_QUOTE);

    fprintf(out, CSV_FORMAT, rm_file_lint_type_to_string(file->lint_type), clean_path,
            file->file_size, checksum_str);

    g_free(clean_path);
}