Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test integrity for the cfile compressors #225

Merged
merged 8 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 71 additions & 34 deletions src/fr-command-cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".gz", NULL);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
fr_process_add_arg (comm->process, filename);
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".br", NULL);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
fr_process_add_arg (comm->process, filename);
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".br", NULL);
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_set_working_dir (comm->process, temp_dir);
Expand Down Expand Up @@ -299,7 +299,7 @@ fr_command_cfile_add (FrCommand *comm,
compressed_filename = g_strconcat (filename, ".rz", NULL);
}

/* copy compressed file to the dest dir */
/* copy compressed file to the dest dir */

fr_process_begin_command (comm->process, "cp");
fr_process_set_working_dir (comm->process, temp_dir);
Expand Down Expand Up @@ -372,13 +372,13 @@ fr_command_cfile_extract (FrCommand *comm,
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_add_arg (comm->process, "-f");
Expand Down Expand Up @@ -469,6 +469,42 @@ fr_command_cfile_extract (FrCommand *comm,
g_free (temp_dir);
}

static void
fr_command_cfile_test (FrCommand *comm)
{
const char *compress_cmd;
if (is_mime_type (comm->mime_type, "application/x-gzip")) {
compress_cmd = "gzip";
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
compress_cmd = "brotli";
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
compress_cmd = "bzip2";
}
else if (is_mime_type (comm->mime_type, "application/x-compress")) {
compress_cmd = is_program_in_path ("gzip") ? "gzip" : "uncompress";
}
else if (is_mime_type (comm->mime_type, "application/x-lzip")) {
compress_cmd = "lzip";
}
else if (is_mime_type (comm->mime_type, "application/x-lzma")) {
compress_cmd = "lzma";
}
else if (is_mime_type (comm->mime_type, "application/x-xz")) {
compress_cmd = "xz";
}
else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
compress_cmd = "lzop";
} else { // i.e. if (is_mime_type (comm->mime_type, "application/x-rzip"))
g_warning ("Test integrity in unsupported for %s\n", comm->mime_type);
stokito marked this conversation as resolved.
Show resolved Hide resolved
return;
}
fr_process_begin_command (comm->process, compress_cmd);
fr_process_add_arg (comm->process, "-vt"); // verbose and test
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
}

const char *cfile_mime_type[] = { "application/x-gzip",
"application/x-brotli",
Expand All @@ -491,7 +527,7 @@ fr_command_cfile_get_mime_types (FrCommand *comm)

static FrCommandCap
fr_command_cfile_get_capabilities (FrCommand *comm,
const char *mime_type,
const char *mime_type,
gboolean check_command)
{
FrCommandCap capabilities;
Expand Down Expand Up @@ -543,12 +579,12 @@ fr_command_cfile_get_capabilities (FrCommand *comm,
static void
fr_command_cfile_finalize (GObject *object)
{
g_return_if_fail (object != NULL);
g_return_if_fail (FR_IS_COMMAND_CFILE (object));
g_return_if_fail (object != NULL);
g_return_if_fail (FR_IS_COMMAND_CFILE (object));

/* Chain up */
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (object);
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (object);
}


Expand All @@ -558,8 +594,8 @@ fr_command_cfile_get_packages (FrCommand *comm,
{
if (is_mime_type (mime_type, "application/x-gzip"))
return PACKAGES ("gzip");
else if (is_mime_type (mime_type, "application/x-brotli"))
return PACKAGES ("brotli");
else if (is_mime_type (mime_type, "application/x-brotli"))
return PACKAGES ("brotli");
else if (is_mime_type (mime_type, "application/x-bzip"))
return PACKAGES ("bzip2");
else if (is_mime_type (mime_type, "application/x-compress"))
Expand All @@ -582,18 +618,19 @@ fr_command_cfile_get_packages (FrCommand *comm,
static void
fr_command_cfile_class_init (FrCommandCFileClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
FrCommandClass *afc;
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
FrCommandClass *afc;

parent_class = g_type_class_peek_parent (class);
parent_class = g_type_class_peek_parent (class);
afc = (FrCommandClass*) class;

gobject_class->finalize = fr_command_cfile_finalize;
gobject_class->finalize = fr_command_cfile_finalize;

afc->list = fr_command_cfile_list;
afc->list = fr_command_cfile_list;
afc->add = fr_command_cfile_add;
afc->delete = fr_command_cfile_delete;
afc->extract = fr_command_cfile_extract;
afc->test = fr_command_cfile_test;
afc->get_mime_types = fr_command_cfile_get_mime_types;
afc->get_capabilities = fr_command_cfile_get_capabilities;
afc->get_packages = fr_command_cfile_get_packages;
Expand All @@ -609,17 +646,17 @@ fr_command_cfile_init (FrCommand *comm)
comm->propExtractCanSkipOlder = FALSE;
comm->propExtractCanJunkPaths = FALSE;
comm->propPassword = FALSE;
comm->propTest = FALSE;
comm->propTest = TRUE;
}


GType
fr_command_cfile_get_type ()
{
static GType type = 0;
static GType type = 0;

if (! type) {
GTypeInfo type_info = {
if (! type) {
GTypeInfo type_info = {
sizeof (FrCommandCFileClass),
NULL,
NULL,
Expand All @@ -635,7 +672,7 @@ fr_command_cfile_get_type ()
"FRCommandCFile",
&type_info,
0);
}
}

return type;
return type;
}
43 changes: 25 additions & 18 deletions src/fr-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -7324,6 +7324,27 @@ last_output_window__unrealize_cb (GtkWidget *widget,
}


static void
fr_window_view_last_output_print(GtkTextBuffer *text_buffer,
GtkTextIter *iter,
GList *scan)
{
for (; scan; scan = scan->next) {
char *line = scan->data;
char *utf8_line;
gsize bytes_written;

utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
iter,
utf8_line,
bytes_written,
"monospace", NULL);
g_free (utf8_line);
gtk_text_buffer_insert (text_buffer, iter, "\n", 1);
}
}

void
fr_window_view_last_output (FrWindow *window,
const char *title)
Expand All @@ -7334,7 +7355,6 @@ fr_window_view_last_output (FrWindow *window,
GtkWidget *scrolled;
GtkTextBuffer *text_buffer;
GtkTextIter iter;
GList *scan;

if (title == NULL)
title = _("Last Output");
Expand Down Expand Up @@ -7392,24 +7412,11 @@ fr_window_view_last_output (FrWindow *window,
G_CALLBACK (last_output_window__unrealize_cb),
NULL);

/**/

gtk_text_buffer_get_iter_at_offset (text_buffer, &iter, 0);
scan = window->archive->process->out.raw;
for (; scan; scan = scan->next) {
char *line = scan->data;
char *utf8_line;
gsize bytes_written;

utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
&iter,
utf8_line,
bytes_written,
"monospace", NULL);
g_free (utf8_line);
gtk_text_buffer_insert (text_buffer, &iter, "\n", 1);
}
/* Show STDOUT of process */
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->out.raw);
/* Show STDERR of process */
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->err.raw);

/**/

Expand Down