[gnome-autoar/wip/razvan/general-improvements: 13/20] 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/wip/razvan/general-improvements: 13/20] AutoarCreate: add property for creating a top level directory
- Date: Fri, 19 Aug 2016 17:30:50 +0000 (UTC)
commit f9afadbcc4aa8394fee5ef530b46ad511a3c7ba5
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 | 71 ++++++++++++++++++++++++++++++++++++------
gnome-autoar/autoar-create.h | 61 +++++++++++++++++++-----------------
2 files changed, 93 insertions(+), 39 deletions(-)
---
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c
index ff2526a..17ff0fd 100644
--- a/gnome-autoar/autoar-create.c
+++ b/gnome-autoar/autoar-create.c
@@ -89,6 +89,8 @@ struct _AutoarCreatePrivate
int output_is_dest : 1;
+ gboolean started;
+
guint64 size; /* This field is currently unused */
guint64 completed_size;
@@ -114,7 +116,7 @@ struct _AutoarCreatePrivate
char *extension;
int in_thread : 1;
- int prepend_basename : 1;
+ gboolean create_top_level_directory;
};
enum
@@ -134,6 +136,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 +172,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 +229,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 +307,22 @@ 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 archive. See
+ * autoar_create_set_create_top_level_directory() for more details.
+ *
+ * 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
*
@@ -391,6 +416,28 @@ autoar_create_get_notify_interval (AutoarCreate *arcreate)
}
/**
+ * autoar_create_set_create_top_level_directory:
+ * @arcreate: an #AutoarCreate
+ * @create_top_level_directory: %TRUE if a top level directory should be
+ * created in the new archive
+ *
+ * By default #AutoarCreate:create-top-level-directory is set to %FALSE, so the
+ * source files will be added directly to the archive's root. By setting
+ * #AutoarCreate:create-top-level-directory to %TRUE a top level directory
+ * will be created and it will have the name of the archive without the
+ * extension. Setting the property once the operation is started will have no
+ * effect.
+ **/
+void
+autoar_create_set_create_top_level_directory (AutoarCreate *arcreate,
+ gboolean create_top_level_directory)
+{
+ g_return_if_fail (AUTOAR_IS_CREATE (arcreate));
+ g_return_if_fail (arcreate->priv->started);
+ arcreate->priv->create_top_level_directory = create_top_level_directory;
+}
+
+/**
* autoar_create_set_output_is_dest:
* @arcreate: an #AutoarCreate
* @output_is_dest: %TRUE if the location of the new archive has been already
@@ -809,8 +856,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 +1101,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 +1284,6 @@ autoar_create_init (AutoarCreate *arcreate)
priv->extension = NULL;
priv->in_thread = FALSE;
- priv->prepend_basename = FALSE;
}
/**
@@ -1421,12 +1476,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) {
@@ -1514,6 +1563,8 @@ autoar_create_run (AutoarCreate *arcreate)
g_return_if_fail (AUTOAR_IS_CREATE (arcreate));
priv = arcreate->priv;
+ priv->started = TRUE;
+
g_return_if_fail (priv->source_files != NULL);
g_return_if_fail (priv->output_file != NULL);
diff --git a/gnome-autoar/autoar-create.h b/gnome-autoar/autoar-create.h
index 20863d6..42b6707 100644
--- a/gnome-autoar/autoar-create.h
+++ b/gnome-autoar/autoar-create.h
@@ -65,35 +65,38 @@ 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);
+
+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_create_top_level_directory (AutoarCreate *arcreate,
+ gboolean create_top_level_directory);
+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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]