[gnome-autoar] AutoarExtract: remove support for memory files
- From: Răzvan-Mihai Chițu <razvanchitu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar] AutoarExtract: remove support for memory files
- Date: Mon, 22 Aug 2016 09:44:17 +0000 (UTC)
commit 5b6837d0d06062cdb0ed9b4e8e3dc7441b95d008
Author: Razvan Chitu <razvan ch95 gmail com>
Date: Sun Aug 7 15:45:51 2016 +0300
AutoarExtract: remove support for memory files
While libarchive offers support for archives read from memory, there is no use
case for this feature in gnome-autoar.
https://bugzilla.gnome.org/show_bug.cgi?id=768645
gnome-autoar/autoar-extract.c | 197 +++++------------------------------------
gnome-autoar/autoar-extract.h | 13 ---
tests/test-extract.c | 26 +-----
3 files changed, 24 insertions(+), 212 deletions(-)
---
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index 6071723..80eb92f 100644
--- a/gnome-autoar/autoar-extract.c
+++ b/gnome-autoar/autoar-extract.c
@@ -109,14 +109,10 @@ struct _AutoarExtractPrivate
GFile *source_file;
GFile *output_file;
- int source_is_mem : 1;
int output_is_dest : 1;
AutoarPref *arpref;
- const void *source_buffer;
- gsize source_buffer_size;
-
GCancellable *cancellable;
gint64 notify_interval;
@@ -174,14 +170,13 @@ enum
{
PROP_0,
PROP_SOURCE, /* Only used to display messages */
- PROP_SOURCE_FILE, /* It may be invalid if source-is-mem is TRUE */
+ PROP_SOURCE_FILE,
PROP_OUTPUT, /* Only used to display messages */
PROP_OUTPUT_FILE,
PROP_SIZE,
PROP_COMPLETED_SIZE,
PROP_FILES,
PROP_COMPLETED_FILES,
- PROP_SOURCE_IS_MEM, /* Must be set when constructing object */
PROP_OUTPUT_IS_DEST,
PROP_NOTIFY_INTERVAL
};
@@ -225,9 +220,6 @@ autoar_extract_get_property (GObject *object,
case PROP_COMPLETED_FILES:
g_value_set_uint (value, priv->completed_files);
break;
- case PROP_SOURCE_IS_MEM:
- g_value_set_boolean (value, priv->source_is_mem);
- break;
case PROP_OUTPUT_IS_DEST:
g_value_set_boolean (value, priv->output_is_dest);
break;
@@ -269,9 +261,6 @@ autoar_extract_set_property (GObject *object,
g_clear_object (&(priv->output_file));
priv->output_file = g_object_ref (g_value_get_object (value));
break;
- case PROP_SOURCE_IS_MEM:
- priv->source_is_mem = g_value_get_boolean (value);
- break;
case PROP_OUTPUT_IS_DEST:
autoar_extract_set_output_is_dest (arextract, g_value_get_boolean (value));
break;
@@ -288,9 +277,8 @@ autoar_extract_set_property (GObject *object,
* autoar_extract_get_source:
* @arextract: an #AutoarExtract
*
- * If #AutoarExtract:source_is_mem is %TRUE, gets the descriptive string for
- * the source memory buffer. Otherwise, gets the source file will be extracted
- * for this object. It may be a filename or URI.
+ * Gets the source file that will be extracted for this object. It may be a
+ * filename or URI.
*
* Returns: (transfer none): a string
**/
@@ -305,10 +293,8 @@ autoar_extract_get_source (AutoarExtract *arextract)
* autoar_extract_get_source_file:
* @arextract: an #AutoarExtract
*
- * If #AutoarExtract:source_is_mem is %TRUE, gets the #GFile object generated
- * using the value of #AutoarExtract:source. The returned #GFile is not usable
- * at all. Otherwise, gets the #GFile object which represents the source
- * archive will be extracted for this object.
+ * Gets the #GFile object which represents the source archive that will be
+ * extracted for this object.
*
* Returns: (transfer none): a #GFile
**/
@@ -414,21 +400,6 @@ autoar_extract_get_completed_files (AutoarExtract *arextract)
}
/**
- * autoar_extract_get_source_is_mem:
- * @arextract: an #AutoarExtract
- *
- * Gets whether the source archive is a memory buffer.
- *
- * Returns: %TRUE if the source archive is a memory buffer.
- **/
-gboolean
-autoar_extract_get_source_is_mem (AutoarExtract *arextract)
-{
- g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), FALSE);
- return arextract->priv->source_is_mem;
-}
-
-/**
* autoar_extract_get_output_is_dest:
* @arextract: an #AutoarExtract
*
@@ -599,6 +570,7 @@ libarchive_read_open_cb (struct archive *ar_read,
{
AutoarExtract *arextract;
AutoarExtractPrivate *priv;
+ GFileInputStream *istream;
g_debug ("libarchive_read_open_cb: called");
@@ -608,18 +580,10 @@ libarchive_read_open_cb (struct archive *ar_read,
if (priv->error != NULL)
return ARCHIVE_FATAL;
- if (arextract->priv->source_is_mem) {
- priv->istream =
- g_memory_input_stream_new_from_data (priv->source_buffer,
- priv->source_buffer_size,
- NULL);
- } else {
- GFileInputStream *istream;
- istream = g_file_read (priv->source_file,
- priv->cancellable,
- &(arextract->priv->error));
- priv->istream = G_INPUT_STREAM (istream);
- }
+ istream = g_file_read (priv->source_file,
+ priv->cancellable,
+ &(arextract->priv->error));
+ priv->istream = G_INPUT_STREAM (istream);
if (priv->error != NULL)
return ARCHIVE_FATAL;
@@ -1327,15 +1291,6 @@ autoar_extract_class_init (AutoarExtractClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
- g_object_class_install_property (object_class, PROP_SOURCE_IS_MEM,
- g_param_spec_boolean ("source-is-mem",
- "Source is memory",
- "Whether source file is in memory",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
g_object_class_install_property (object_class, PROP_OUTPUT_IS_DEST,
g_param_spec_boolean ("output-is-dest",
"Output is destination",
@@ -1471,9 +1426,6 @@ autoar_extract_init (AutoarExtract *arextract)
priv = AUTOAR_EXTRACT_GET_PRIVATE (arextract);
arextract->priv = priv;
- priv->source_buffer = NULL;
- priv->source_buffer_size = 0;
-
priv->cancellable = NULL;
priv->size = 0;
@@ -1512,7 +1464,6 @@ autoar_extract_new_full (const char *source,
GFile *source_file,
const char *output,
GFile *output_file,
- gboolean source_is_mem,
AutoarPref *arpref,
const void *buffer,
gsize buffer_size,
@@ -1521,21 +1472,17 @@ autoar_extract_new_full (const char *source,
AutoarExtract *arextract;
char *gen_source, *gen_output;
GFile *gen_source_file, *gen_output_file;
+ g_autofree char *source_basename;
gen_source = NULL;
gen_source_file = NULL;
gen_output = NULL;
gen_output_file = NULL;
- if (source_is_mem) {
- gen_source = g_strdup_printf ("(memory %p, size %" G_GSIZE_FORMAT ")", buffer, buffer_size);
- gen_source_file = g_file_new_for_commandline_arg (gen_source);
- } else {
- if (source == NULL)
- gen_source = autoar_common_g_file_get_name (source_file);
- if (source_file == NULL)
- gen_source_file = g_file_new_for_commandline_arg (source);
- }
+ if (source == NULL)
+ gen_source = autoar_common_g_file_get_name (source_file);
+ if (source_file == NULL)
+ gen_source_file = g_file_new_for_commandline_arg (source);
if (output == NULL)
gen_output = autoar_common_g_file_get_name (output_file);
@@ -1548,24 +1495,13 @@ autoar_extract_new_full (const char *source,
"source-file", source_file != NULL ? source_file : gen_source_file,
"output", output != NULL ? output : gen_output,
"output-file", output_file != NULL ? output_file : gen_output_file,
- "source-is-mem", source_is_mem, NULL);
+ NULL);
+
arextract->priv->arpref = g_object_ref (arpref);
- if (source_is_mem) {
- arextract->priv->source_buffer = buffer;
- arextract->priv->source_buffer_size = buffer_size;
- if (suggested_destname != NULL)
- arextract->priv->suggested_destname =
- autoar_common_get_basename_remove_extension (suggested_destname);
- else
- arextract->priv->suggested_destname =
- autoar_common_get_basename_remove_extension (gen_source);
- } else {
- char *source_basename = g_file_get_basename (arextract->priv->source_file);
- arextract->priv->suggested_destname =
- autoar_common_get_basename_remove_extension (source_basename);
- g_free (source_basename);
- }
+ source_basename = g_file_get_basename (arextract->priv->source_file);
+ arextract->priv->suggested_destname =
+ autoar_common_get_basename_remove_extension (source_basename);
g_free (gen_source);
g_free (gen_output);
@@ -1600,7 +1536,7 @@ autoar_extract_new (const char *source,
g_return_val_if_fail (output != NULL, NULL);
return autoar_extract_new_full (source, NULL, output, NULL,
- FALSE, arpref,
+ arpref,
NULL, 0, NULL);
}
@@ -1625,74 +1561,10 @@ autoar_extract_new_file (GFile *source_file,
g_return_val_if_fail (output_file != NULL, NULL);
return autoar_extract_new_full (NULL, source_file, NULL, output_file,
- FALSE, arpref,
+ arpref,
NULL, 0, NULL);
}
-/**
- * autoar_extract_new_memory:
- * @buffer: memory buffer holding the source archive
- * @buffer_size: the size of the source archive memory buffer
- * @source_name: the name of the source archive
- * @output: output directory of extracted file or directory, or the file name
- * of the extracted file or directory itself if you set
- * #AutoarExtract:output-is-dest on the returned object
- * @arpref: an #AutoarPref object
- *
- * Create a new #AutoarExtract object. @source_name does not need to be a full
- * path. The file which it represents does not need to exist, either. This
- * argument is only used to decide the name of the extracted file or directory,
- * and it is useless if you set #AutoarExtract:output-is-dest to %TRUE.
- *
- * Returns: (transfer full): a new #AutoarExtract object
- **/
-AutoarExtract*
-autoar_extract_new_memory (const void *buffer,
- gsize buffer_size,
- const char *source_name,
- const char *output,
- AutoarPref *arpref)
-{
-
- g_return_val_if_fail (output != NULL, NULL);
- g_return_val_if_fail (buffer != NULL, NULL);
-
- return autoar_extract_new_full (NULL, NULL, output, NULL,
- TRUE, arpref,
- buffer, buffer_size, source_name);
-}
-
-/**
- * autoar_extract_new_memory_file:
- * @buffer: memory buffer holding the source archive
- * @buffer_size: the size of the source archive memory buffer
- * @source_name: the name of the source archive
- * @output_file: output directory of extracted file or directory, or the file
- * name of the extracted file or directory itself if you set
- * #AutoarExtract:output-is-dest on the returned object
- * @arpref: an #AutoarPref object
- *
- * Create a new #AutoarExtract object. This function is similar to
- * autoar_extract_new_memory() except for the argument for the output
- * directory is #GFile.
- *
- * Returns: (transfer full): a new #AutoarExtract object
- **/
-AutoarExtract*
-autoar_extract_new_memory_file (const void *buffer,
- gsize buffer_size,
- const char *source_name,
- GFile *output_file,
- AutoarPref *arpref)
-{
- g_return_val_if_fail (output_file != NULL, NULL);
- g_return_val_if_fail (buffer != NULL, NULL);
-
- return autoar_extract_new_full (NULL, NULL, NULL, output_file,
- TRUE, arpref,
- buffer, buffer_size, source_name);
-}
-
static void
autoar_extract_step_initialize_pattern (AutoarExtract *arextract) {
/* Step 0: Compile the file name pattern. */
@@ -2050,8 +1922,7 @@ autoar_extract_run (AutoarExtract *arextract)
g_return_if_fail (AUTOAR_IS_EXTRACT (arextract));
priv = arextract->priv;
- g_return_if_fail (priv->source_file != NULL || (priv->source_is_mem &&
- priv->source_buffer != NULL));
+ g_return_if_fail (priv->source_file != NULL);
g_return_if_fail (priv->output_file != NULL);
if (g_cancellable_is_cancelled (priv->cancellable)) {
@@ -2147,25 +2018,3 @@ autoar_extract_start_async (AutoarExtract *arextract,
g_task_set_task_data (task, NULL, NULL);
g_task_run_in_thread (task, autoar_extract_start_async_thread);
}
-
-/**
- * autoar_extract_free_source_buffer:
- * @arextract: an #AutoarExtract object
- * @free_func: a function to free the memory buffer
- *
- * Free the source memory archive provided in autoar_extract_new_memory() or
- * autoar_extract_new_memory_file(). This functions should only be called
- * after the extracting job is completed. That is, you should only call this
- * function after you receives one of #AutoarExtract::cancelled,
- * #AutoarExtract::error, or #AutoarExtract::completed signal.
- **/
-void
-autoar_extract_free_source_buffer (AutoarExtract *arextract,
- GDestroyNotify free_func)
-{
- if (arextract->priv->source_buffer != NULL)
- (*free_func)((void*)(arextract->priv->source_buffer));
-
- arextract->priv->source_buffer = NULL;
- arextract->priv->source_buffer_size = 0;
-}
diff --git a/gnome-autoar/autoar-extract.h b/gnome-autoar/autoar-extract.h
index be97e83..f649543 100644
--- a/gnome-autoar/autoar-extract.h
+++ b/gnome-autoar/autoar-extract.h
@@ -75,23 +75,11 @@ AutoarExtract *autoar_extract_new (const char *source,
AutoarExtract *autoar_extract_new_file (GFile *source_file,
GFile *output_file,
AutoarPref *arpref);
-AutoarExtract *autoar_extract_new_memory (const void *buffer,
- gsize buffer_size,
- const char *source_name,
- const char *output,
- AutoarPref *arpref);
-AutoarExtract *autoar_extract_new_memory_file (const void *buffer,
- gsize buffer_size,
- const char *source_name,
- GFile *output_file,
- AutoarPref *arpref);
void autoar_extract_start (AutoarExtract *arextract,
GCancellable *cancellable);
void autoar_extract_start_async (AutoarExtract *arextract,
GCancellable *cancellable);
-void autoar_extract_free_source_buffer (AutoarExtract *arextract,
- GDestroyNotify free_func);
char *autoar_extract_get_source (AutoarExtract *arextract);
GFile *autoar_extract_get_source_file (AutoarExtract *arextract);
@@ -101,7 +89,6 @@ guint64 autoar_extract_get_size (AutoarExtract *arextract);
guint64 autoar_extract_get_completed_size (AutoarExtract *arextract);
guint autoar_extract_get_files (AutoarExtract *arextract);
guint autoar_extract_get_completed_files (AutoarExtract *arextract);
-gboolean autoar_extract_get_source_is_mem (AutoarExtract *arextract);
gboolean autoar_extract_get_output_is_dest (AutoarExtract *arextract);
gint64 autoar_extract_get_notify_interval (AutoarExtract *arextract);
diff --git a/tests/test-extract.c b/tests/test-extract.c
index 197eca8..ae6325c 100644
--- a/tests/test-extract.c
+++ b/tests/test-extract.c
@@ -76,31 +76,7 @@ main (int argc,
autoar_pref_set_delete_if_succeed (arpref, FALSE);
autoar_pref_set_pattern_to_ignore (arpref, (const char**)argv + 3);
- autoar_pref_forget_changes (arpref);
- autoar_pref_write_gsettings (arpref, settings);
-
- if (g_str_has_suffix (argv[0], "test-extract-memory")) {
- gsize length;
- GFile *file;
- GError *error;
-
- g_print ("Loading whole file into memory ... ");
-
- error = NULL;
- file = g_file_new_for_commandline_arg (argv[1]);
- if (!g_file_load_contents (file, NULL, &content, &length, NULL, &error)) {
- g_printerr ("\ntest-extract-memory: Error %d: %s\n", error->code, error->message);
- g_object_unref (file);
- g_error_free (error);
- return 1;
- }
-
- g_print ("OK\n");
- g_object_unref (file);
- arextract = autoar_extract_new_memory (content, length, argv[1], argv[2], arpref);
- } else {
- arextract = autoar_extract_new (argv[1], argv[2], arpref);
- }
+ arextract = autoar_extract_new (argv[1], argv[2], arpref);
g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL);
g_signal_connect (arextract, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]