[gnome-autoar] AutoarCreate: add property for creating a top level directory
- From: Răzvan-Mihai Chițu <razvanchitu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar] AutoarCreate: add property for creating a top level directory
- Date: Mon, 22 Aug 2016 09:45:17 +0000 (UTC)
commit 04289f2babfe2b44daae123dde1a46358812c478
Author: Razvan Chitu <razvan ch95 gmail com>
Date: Mon Aug 15 17:39:58 2016 +0300
AutoarCreate: add property for creating a top level directory
Previously, AutoarCreate would create a top level directory if more than one
files would be compressed. This leads to problems because clients cannot decide
whether they want a top level directory or not. In order to fix this, add a
property for creating a top level directory.
https://bugzilla.gnome.org/show_bug.cgi?id=768645
gnome-autoar/autoar-create.c | 51 ++++++++++++++++++++++++++++-------
gnome-autoar/autoar-create.h | 60 +++++++++++++++++++++--------------------
tests/test-create.c | 3 +-
3 files changed, 73 insertions(+), 41 deletions(-)
---
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c
index 4a18206..75c48fe 100644
--- a/gnome-autoar/autoar-create.c
+++ b/gnome-autoar/autoar-create.c
@@ -114,7 +114,7 @@ struct _AutoarCreatePrivate
char *extension;
int in_thread : 1;
- int prepend_basename : 1;
+ gboolean create_top_level_directory;
};
enum
@@ -134,6 +134,7 @@ enum
PROP_OUTPUT_FILE,
PROP_FORMAT,
PROP_FILTER,
+ PROP_CREATE_TOP_LEVEL_DIRECTORY,
PROP_SIZE, /* This property is currently unused */
PROP_COMPLETED_SIZE,
PROP_FILES,
@@ -169,6 +170,9 @@ autoar_create_get_property (GObject *object,
case PROP_FILTER:
g_value_set_enum (value, priv->format);
break;
+ case PROP_CREATE_TOP_LEVEL_DIRECTORY:
+ g_value_set_boolean (value, priv->create_top_level_directory);
+ break;
case PROP_SIZE:
g_value_set_uint64 (value, priv->size);
break;
@@ -223,6 +227,9 @@ autoar_create_set_property (GObject *object,
case PROP_FILTER:
priv->filter = g_value_get_enum (value);
break;
+ case PROP_CREATE_TOP_LEVEL_DIRECTORY:
+ priv->create_top_level_directory = g_value_get_boolean (value);
+ break;
case PROP_OUTPUT_IS_DEST:
priv->output_is_dest = g_value_get_boolean (value);
break;
@@ -298,6 +305,21 @@ autoar_create_get_filter (AutoarCreate *arcreate)
}
/**
+ * autoar_create_get_create_top_level_directory:
+ * @arcreate: an #AutoarCreate
+ *
+ * Gets whether a top level directory will be created in the new archive.
+ *
+ * Returns: whether a top level directory will be created
+ **/
+gboolean
+autoar_create_get_create_top_level_directory (AutoarCreate *arcreate)
+{
+ g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), FALSE);
+ return arcreate->priv->create_top_level_directory;
+}
+
+/**
* autoar_create_get_size:
* @arcreate: an #AutoarCreate
*
@@ -809,8 +831,8 @@ autoar_create_do_add_to_archive (AutoarCreate *arcreate,
default:
root_basename = g_file_get_basename (root);
pathname_relative = g_file_get_relative_path (root, file);
- pathname = g_strconcat (priv->prepend_basename ? priv->source_basename_noext : "",
- priv->prepend_basename ? "/" : "",
+ pathname = g_strconcat (priv->create_top_level_directory ? priv->source_basename_noext : "",
+ priv->create_top_level_directory ? "/" : "",
root_basename,
pathname_relative != NULL ? "/" : "",
pathname_relative != NULL ? pathname_relative : "",
@@ -1054,6 +1076,15 @@ autoar_create_class_init (AutoarCreateClass *klass)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_CREATE_TOP_LEVEL_DIRECTORY,
+ g_param_spec_boolean ("create-top-level-directory",
+ "Create top level directory",
+ "Whether to create a top level directory",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (object_class, PROP_SIZE, /* This propery is unused! */
g_param_spec_uint64 ("size",
@@ -1228,7 +1259,6 @@ autoar_create_init (AutoarCreate *arcreate)
priv->extension = NULL;
priv->in_thread = FALSE;
- priv->prepend_basename = FALSE;
}
/**
@@ -1238,6 +1268,9 @@ autoar_create_init (AutoarCreate *arcreate)
* new archive if you set #AutoarCreate:output-is-dest on the returned object
* @format: the compression format
* @filter: the compression filter
+ * @create_top_level_directory: whether to create a top level directory in the
+ * new archive. The directory will have the name of the archive without the
+ * extension
*
* Create a new #AutoarCreate object.
*
@@ -1247,7 +1280,8 @@ AutoarCreate*
autoar_create_new (GList *source_files,
GFile *output_file,
AutoarFormat format,
- AutoarFilter filter)
+ AutoarFilter filter,
+ gboolean create_top_level_directory)
{
AutoarCreate *arcreate;
@@ -1259,6 +1293,7 @@ autoar_create_new (GList *source_files,
"output-file", g_object_ref (output_file),
"format", format,
"filter", filter,
+ "create-top-level-directory", create_top_level_directory,
NULL);
return arcreate;
@@ -1421,12 +1456,6 @@ autoar_create_step_create (AutoarCreate *arcreate)
return;
}
- /* Check whether we have multiple source files */
- if (g_list_length (priv->source_files) == 1)
- priv->prepend_basename = FALSE;
- else
- priv->prepend_basename = TRUE;
-
archive_entry_linkresolver_set_strategy (priv->resolver, archive_format (priv->a));
for (l = priv->source_files; l != NULL; l = l->next) {
diff --git a/gnome-autoar/autoar-create.h b/gnome-autoar/autoar-create.h
index 20863d6..e5247d1 100644
--- a/gnome-autoar/autoar-create.h
+++ b/gnome-autoar/autoar-create.h
@@ -65,35 +65,37 @@ struct _AutoarCreateClass
**/
#define AUTOAR_CREATE_ERROR autoar_create_quark()
-GQuark autoar_create_quark (void);
-
-GType autoar_create_get_type (void) G_GNUC_CONST;
-
-AutoarCreate* autoar_create_new (GList *source_files,
- GFile *output_file,
- AutoarFormat format,
- AutoarFilter filter);
-
-void autoar_create_start (AutoarCreate *arcreate,
- GCancellable *cancellable);
-void autoar_create_start_async (AutoarCreate *arcreate,
- GCancellable *cancellable);
-
-GList *autoar_create_get_source_files (AutoarCreate *arcreate);
-GFile *autoar_create_get_output_file (AutoarCreate *arcreate);
-AutoarFormat autoar_create_get_format (AutoarCreate *arcreate);
-AutoarFilter autoar_create_get_filter (AutoarCreate *arcreate);
-guint64 autoar_create_get_size (AutoarCreate *arcreate);
-guint64 autoar_create_get_completed_size (AutoarCreate *arcreate);
-guint autoar_create_get_files (AutoarCreate *arcreate);
-guint autoar_create_get_completed_files (AutoarCreate *arcreate);
-gboolean autoar_create_get_output_is_dest (AutoarCreate *arcreate);
-gint64 autoar_create_get_notify_interval (AutoarCreate *arcreate);
-
-void autoar_create_set_output_is_dest (AutoarCreate *arcreate,
- gboolean output_is_dest);
-void autoar_create_set_notify_interval (AutoarCreate *arcreate,
- gint64 notify_interval);
+GQuark autoar_create_quark (void);
+
+GType autoar_create_get_type (void) G_GNUC_CONST;
+
+AutoarCreate * autoar_create_new (GList *source_files,
+ GFile *output_file,
+ AutoarFormat format,
+ AutoarFilter filter,
+ gboolean create_top_level_directory);
+
+void autoar_create_start (AutoarCreate *arcreate,
+ GCancellable *cancellable);
+void autoar_create_start_async (AutoarCreate *arcreate,
+ GCancellable *cancellable);
+
+GList * autoar_create_get_source_files (AutoarCreate *arcreate);
+GFile * autoar_create_get_output_file (AutoarCreate *arcreate);
+AutoarFormat autoar_create_get_format (AutoarCreate *arcreate);
+AutoarFilter autoar_create_get_filter (AutoarCreate *arcreate);
+gboolean autoar_create_get_create_top_level_directory (AutoarCreate *arcreate);
+guint64 autoar_create_get_size (AutoarCreate *arcreate);
+guint64 autoar_create_get_completed_size (AutoarCreate *arcreate);
+guint autoar_create_get_files (AutoarCreate *arcreate);
+guint autoar_create_get_completed_files (AutoarCreate *arcreate);
+gboolean autoar_create_get_output_is_dest (AutoarCreate *arcreate);
+gint64 autoar_create_get_notify_interval (AutoarCreate *arcreate);
+
+void autoar_create_set_output_is_dest (AutoarCreate *arcreate,
+ gboolean output_is_dest);
+void autoar_create_set_notify_interval (AutoarCreate *arcreate,
+ gint64 notify_interval);
G_END_DECLS
#endif /* AUTOAR_CREATE_H */
diff --git a/tests/test-create.c b/tests/test-create.c
index 412f3ea..0adfa04 100644
--- a/tests/test-create.c
+++ b/tests/test-create.c
@@ -72,7 +72,8 @@ main (int argc,
arcreate = autoar_create_new (source_files,
output_file,
atoi (argv[1]),
- atoi (argv[2]));
+ atoi (argv[2]),
+ TRUE);
g_signal_connect (arcreate, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL);
g_signal_connect (arcreate, "progress", G_CALLBACK (my_handler_progress), NULL);
g_signal_connect (arcreate, "error", G_CALLBACK (my_handler_error), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]