file-roller r2393 - in trunk: . src
- From: paobac svn gnome org
- To: svn-commits-list gnome org
- Subject: file-roller r2393 - in trunk: . src
- Date: Mon, 28 Jul 2008 18:57:15 +0000 (UTC)
Author: paobac
Date: Mon Jul 28 18:57:15 2008
New Revision: 2393
URL: http://svn.gnome.org/viewvc/file-roller?rev=2393&view=rev
Log:
2008-07-28 Paolo Bacchilega <paobac svn gnome org>
* src/fr-command-rar.c: always load the first volume of the series to
list the whole content of the archive.
Fixes bug #545168 â no longer possible to open a multi-volume rar
from any part
* src/fr-window.c (action_performed): update the archive name after
loading the content.
* src/fr-archive.c (action_performed): update the archive name after
loading the content.
(get_mime_type_from_magic_numbers): use the new function
g_load_file_in_buffer.
* src/gio-utils.h:
* src/gio-utils.c: added function g_load_file_in_buffer()
Modified:
trunk/ChangeLog
trunk/src/fr-archive.c
trunk/src/fr-command-rar.c
trunk/src/fr-window.c
trunk/src/gio-utils.c
trunk/src/gio-utils.h
Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c (original)
+++ trunk/src/fr-archive.c Mon Jul 28 18:57:15 2008
@@ -543,17 +543,10 @@
{ "application/zip", "PK00PK\003\004", 0, 8 },
{ NULL, NULL, 0 }
};
- GFileInputStream *istream;
- char buffer[32];
- int n, i;
+ char buffer[32];
+ int i;
- istream = g_file_read (file, NULL, NULL);
- if (istream == NULL)
- return NULL;
-
- n = g_input_stream_read (G_INPUT_STREAM (istream), buffer, sizeof (buffer), NULL, NULL);
- g_object_unref (istream);
- if (n < 0)
+ if (! g_load_file_in_buffer (file, buffer, 32, NULL))
return NULL;
for (i = 0; sniffer_data[i].mime_type != NULL; i++)
@@ -946,6 +939,10 @@
break;
case FR_ACTION_LISTING_CONTENT:
+ /* the name of the volumes are different from the
+ * original name */
+ if (archive->command->multi_volume)
+ fr_archive_change_name (archive, archive->command->filename);
fr_command_update_capabilities (archive->command);
if (! fr_command_is_capable_of (archive->command, FR_COMMAND_CAN_WRITE))
archive->read_only = TRUE;
Modified: trunk/src/fr-command-rar.c
==============================================================================
--- trunk/src/fr-command-rar.c (original)
+++ trunk/src/fr-command-rar.c Mon Jul 28 18:57:15 2008
@@ -30,6 +30,7 @@
#include "file-data.h"
#include "file-utils.h"
+#include "gio-utils.h"
#include "glib-utils.h"
#include "fr-command.h"
#include "fr-command-rar.h"
@@ -204,10 +205,119 @@
}
+typedef enum {
+ FIRST_VOLUME_IS_000,
+ FIRST_VOLUME_IS_001,
+ FIRST_VOLUME_IS_RAR
+} FirstVolumeExtension;
+
+
+static char *
+get_first_volume_name (const char *name,
+ const char *pattern,
+ FirstVolumeExtension extension_type)
+{
+ char *volume_name = NULL;
+ GRegex *re;
+
+ re = g_regex_new (pattern, G_REGEX_CASELESS, 0, NULL);
+ if (g_regex_match (re, name, 0, NULL)) {
+ char **parts;
+ int l, i;
+
+ parts = g_regex_split (re, name, 0);
+ l = strlen (parts[2]);
+ switch (extension_type) {
+ case FIRST_VOLUME_IS_000:
+ for (i = 0; i < l; i++)
+ parts[2][i] = '0';
+ break;
+
+ case FIRST_VOLUME_IS_001:
+ for (i = 0; i < l; i++)
+ parts[2][i] = (i < l - 1) ? '0' : '1';
+ break;
+
+ case FIRST_VOLUME_IS_RAR:
+ if (g_str_has_suffix (parts[1], "r")) {
+ parts[2][0] = 'a';
+ parts[2][1] = 'r';
+ }
+ else {
+ parts[2][0] = 'A';
+ parts[2][1] = 'R';
+ }
+ break;
+ }
+
+ volume_name = g_strjoinv ("", parts);
+
+ g_strfreev (parts);
+ }
+ g_regex_unref (re);
+
+ if (volume_name != NULL) {
+ char *tmp;
+
+ tmp = volume_name;
+ volume_name = g_filename_from_utf8 (tmp, -1, NULL, NULL, NULL);
+ g_free (tmp);
+ }
+
+ return volume_name;
+}
+
+
+static void
+check_multi_vomule (FrCommand *comm)
+{
+ GFile *file;
+ char buffer[11];
+
+ file = g_file_new_for_path (comm->filename);
+ if (! g_load_file_in_buffer (file, buffer, 11, NULL)) {
+ g_object_unref (file);
+ return;
+ }
+
+ if ((buffer[10] & 0x01) == 0x01) {
+ char *volume_name = NULL;
+ char *name;
+
+ name = g_filename_to_utf8 (file_name_from_path (comm->filename), -1, NULL, NULL, NULL);
+
+ volume_name = get_first_volume_name (name, "^(.*\\.part)([0-9]+)(\\.rar)$", FIRST_VOLUME_IS_001);
+ if (volume_name == NULL)
+ volume_name = get_first_volume_name (name, "^(.*\\.r)([0-9]+)$", FIRST_VOLUME_IS_RAR);
+ if (volume_name == NULL)
+ volume_name = get_first_volume_name (name, "^(.*\\.)([0-9]+)$", FIRST_VOLUME_IS_001);
+
+ if (volume_name != NULL) {
+ GFile *parent;
+ GFile *child;
+ char *volume_filename;
+
+ parent = g_file_get_parent (file);
+ child = g_file_get_child (parent, volume_name);
+ volume_filename = g_file_get_path (child);
+ fr_command_set_multi_volume (comm, volume_filename);
+
+ g_free (volume_filename);
+ g_object_unref (child);
+ g_object_unref (parent);
+ }
+
+ g_free (name);
+ }
+
+ g_object_unref (file);
+}
+
+
static void
fr_command_rar_list (FrCommand *comm)
{
- FR_COMMAND_RAR (comm)->list_started = FALSE;
+ check_multi_vomule (comm);
fr_process_set_out_line_func (FR_COMMAND (comm)->process,
process_line,
@@ -228,6 +338,8 @@
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
+
+ FR_COMMAND_RAR (comm)->list_started = FALSE;
fr_process_start (comm->process);
}
Modified: trunk/src/fr-window.c
==============================================================================
--- trunk/src/fr-window.c (original)
+++ trunk/src/fr-window.c Mon Jul 28 18:57:15 2008
@@ -3020,6 +3020,11 @@
break;
case FR_ACTION_LISTING_CONTENT:
+ /* update the uri because multi-volume archives can have
+ * a different name after loading. */
+ g_free (window->priv->archive_uri);
+ window->priv->archive_uri = g_file_get_uri (window->archive->file);
+
close_progress_dialog (window, FALSE);
if (error->type != FR_PROC_ERROR_NONE) {
fr_window_remove_from_recent_list (window, window->priv->archive_uri);
Modified: trunk/src/gio-utils.c
==============================================================================
--- trunk/src/gio-utils.c (original)
+++ trunk/src/gio-utils.c Mon Jul 28 18:57:15 2008
@@ -55,31 +55,31 @@
{
Filter *filter;
GRegexCompileFlags flags;
-
+
filter = g_new0 (Filter, 1);
- if ((pattern != NULL) && (strcmp (pattern, "*") != 0))
+ if ((pattern != NULL) && (strcmp (pattern, "*") != 0))
filter->pattern = g_strdup (pattern);
filter->options = options;
if (filter->options & FILTER_IGNORECASE)
flags = G_REGEX_CASELESS;
else
- flags = 0;
+ flags = 0;
filter->regexps = search_util_get_regexps (pattern, flags);
-
+
return filter;
}
static void
filter_destroy (Filter *filter)
-{
+{
if (filter == NULL)
return;
g_free (filter->pattern);
- if (filter->regexps != NULL)
+ if (filter->regexps != NULL)
free_regexps (filter->regexps);
g_free (filter);
}
@@ -107,7 +107,7 @@
if (filter->pattern == NULL)
return TRUE;
-
+
utf8_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
matched = match_regexps (filter->regexps, utf8_name, 0);
g_free (utf8_name);
@@ -170,21 +170,21 @@
for_each_child_done_cb (gpointer user_data)
{
ForEachChildData *fec = user_data;
-
+
g_source_remove (fec->source_id);
if (fec->current != NULL) {
g_object_unref (fec->current);
fec->current = NULL;
}
- if (fec->done_func)
+ if (fec->done_func)
fec->done_func (fec->error, fec->user_data);
for_each_child_data_free (fec);
-
+
return FALSE;
}
-static void
+static void
for_each_child_done (ForEachChildData *fec)
{
fec->source_id = g_idle_add (for_each_child_done_cb, fec);
@@ -195,18 +195,18 @@
static gboolean
-for_each_child_start_cb (gpointer user_data)
+for_each_child_start_cb (gpointer user_data)
{
ForEachChildData *fec = user_data;
-
+
g_source_remove (fec->source_id);
for_each_child_start_current (fec);
-
+
return FALSE;
}
-static void
+static void
for_each_child_start (ForEachChildData *fec)
{
fec->source_id = g_idle_add (for_each_child_start_cb, fec);
@@ -227,16 +227,16 @@
for_each_child_start_next_sub_directory (ForEachChildData *fec)
{
char *sub_directory = NULL;
-
+
if (fec->to_visit != NULL) {
GList *tmp;
-
+
sub_directory = (char*) fec->to_visit->data;
tmp = fec->to_visit;
fec->to_visit = g_list_remove_link (fec->to_visit, tmp);
g_list_free (tmp);
}
-
+
if (sub_directory != NULL) {
for_each_child_set_current (fec, sub_directory);
for_each_child_start (fec);
@@ -253,25 +253,25 @@
{
ForEachChildData *fec = user_data;
GError *error = NULL;
-
+
if (! g_file_enumerator_close_finish (fec->enumerator,
result,
- &error))
+ &error))
{
if (fec->error == NULL)
fec->error = g_error_copy (error);
else
g_clear_error (&error);
}
-
- if ((fec->error == NULL) && fec->recursive)
+
+ if ((fec->error == NULL) && fec->recursive)
for_each_child_start_next_sub_directory (fec);
else
for_each_child_done (fec);
}
-static void
+static void
for_each_child_next_files_ready (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
@@ -279,7 +279,7 @@
ForEachChildData *fec = user_data;
GList *children, *scan;
char *current_directory;
-
+
children = g_file_enumerator_next_files_finish (fec->enumerator,
result,
&(fec->error));
@@ -292,7 +292,7 @@
fec);
return;
}
-
+
current_directory = g_file_get_uri (fec->current);
for (scan = children; scan; scan = scan->next) {
GFileInfo *child_info = scan->data;
@@ -305,21 +305,21 @@
/* avoid to visit a directory more than ones */
if (g_hash_table_lookup (fec->already_visited, uri) == NULL) {
- char *sub_directory;
-
+ char *sub_directory;
+
sub_directory = g_strdup (uri);
g_hash_table_insert (fec->already_visited, sub_directory, GINT_TO_POINTER (1));
fec->to_visit = g_list_append (fec->to_visit, sub_directory);
}
}
-
+
fec->for_each_file_func (uri, child_info, fec->user_data);
-
- g_free (uri);
+
+ g_free (uri);
g_free (name);
}
g_free (current_directory);
-
+
g_file_enumerator_next_files_async (fec->enumerator,
N_FILES_PER_REQUEST,
G_PRIORITY_DEFAULT,
@@ -334,13 +334,13 @@
gpointer user_data)
{
ForEachChildData *fec = user_data;
-
+
fec->enumerator = g_file_enumerate_children_finish (fec->current, result, &(fec->error));
if (fec->enumerator == NULL) {
for_each_child_done (fec);
return;
}
-
+
g_file_enumerator_next_files_async (fec->enumerator,
N_FILES_PER_REQUEST,
G_PRIORITY_DEFAULT,
@@ -356,11 +356,11 @@
if (fec->start_dir_func != NULL) {
char *directory;
DirOp op;
-
+
directory = g_file_get_uri (fec->current);
op = fec->start_dir_func (directory, &(fec->error), fec->user_data);
g_free (directory);
-
+
switch (op) {
case DIR_OP_SKIP:
for_each_child_start_next_sub_directory (fec);
@@ -372,7 +372,7 @@
break;
}
}
-
+
g_file_enumerate_children_async (fec->current,
"standard::name,standard::type",
fec->follow_links ? G_FILE_QUERY_INFO_NONE : G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -387,21 +387,21 @@
* @directory: The directory to visit.
* @recursive: Whether to traverse the @directory recursively.
* @follow_links: Whether to dereference the symbolic links.
- * @cancellable: An optional @GCancellable object, used to cancel the process.
+ * @cancellable: An optional @GCancellable object, used to cancel the process.
* @start_dir_func: the function called for each sub-directory, or %NULL if
* not needed.
* @for_each_file_func: the function called for each file. Can't be %NULL.
- * @done_func: the function called at the end of the traversing process.
+ * @done_func: the function called at the end of the traversing process.
* Can't be %NULL.
* @user_data: data to pass to @done_func
*
- * Traverse the @directory's filesystem structure calling the
+ * Traverse the @directory's filesystem structure calling the
* @for_each_file_func function for each file in the directory; the
- * @start_dir_func function on each directory before it's going to be
- * traversed, this includes @directory too; the @done_func function is
+ * @start_dir_func function on each directory before it's going to be
+ * traversed, this includes @directory too; the @done_func function is
* called at the end of the process.
* Some traversing options are available: if @recursive is TRUE the
- * directory is traversed recursively; if @follow_links is TRUE, symbolic
+ * directory is traversed recursively; if @follow_links is TRUE, symbolic
* links are dereferenced, otherwise they are returned as links.
* Each callback uses the same @user_data additional parameter.
*/
@@ -416,11 +416,11 @@
gpointer user_data)
{
ForEachChildData *fec;
-
+
g_return_if_fail (for_each_file_func != NULL);
fec = g_new0 (ForEachChildData, 1);
-
+
fec->base_directory = g_strdup (directory);
fec->recursive = recursive;
fec->follow_links = follow_links;
@@ -429,13 +429,13 @@
fec->for_each_file_func = for_each_file_func;
fec->done_func = done_func;
fec->user_data = user_data;
- fec->already_visited = g_hash_table_new_full (g_str_hash,
+ fec->already_visited = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
NULL);
-
+
for_each_child_set_current (fec, fec->base_directory);
- for_each_child_start_current (fec);
+ for_each_child_start_current (fec);
}
@@ -494,7 +494,7 @@
base_len = 0;
if (strcmp (base_dir, "/") != 0)
base_len = strlen (base_dir);
-
+
for (scan = file_list; scan; scan = scan->next) {
char *full_path = scan->data;
if (path_in_path (base_dir, full_path)) {
@@ -502,7 +502,7 @@
rel_list = g_list_prepend (rel_list, rel_path);
}
}
-
+
return rel_list;
}
@@ -516,7 +516,7 @@
GList *scan;
GList *dir_list = NULL;
int base_dir_len;
-
+
if (base_dir == NULL)
base_dir = "";
base_dir_len = strlen (base_dir);
@@ -539,7 +539,7 @@
if (g_hash_table_lookup (h_dirs, dir) == NULL) {
g_hash_table_insert (h_dirs, dir, GINT_TO_POINTER (1));
dir_list = g_list_prepend (dir_list, dir);
- }
+ }
else
g_free (dir);
@@ -562,10 +562,10 @@
GetFileListData *gfl = user_data;
GHashTable *h_dirs;
GList *scan;
-
+
gfl->files = g_list_reverse (gfl->files);
gfl->dirs = g_list_reverse (gfl->dirs);
-
+
if (! filter_empty (gfl->include_filter) || (gfl->exclude_filter->pattern != NULL)) {
path_list_free (gfl->dirs);
gfl->dirs = NULL;
@@ -573,34 +573,34 @@
h_dirs = g_hash_table_new (g_str_hash, g_str_equal);
- /* Always include the base directory, this way empty base
+ /* Always include the base directory, this way empty base
* directories are added to the archive as well. */
-
+
if (gfl->base_dir != NULL) {
char *dir;
-
+
dir = g_strdup (gfl->base_dir);
gfl->dirs = g_list_prepend (gfl->dirs, dir);
g_hash_table_insert (h_dirs, dir, GINT_TO_POINTER (1));
}
-
- /* Add all the parent directories in gfl->files/gfl->dirs to the
- * gfl->dirs list, the hash table is used to avoid duplicated
+
+ /* Add all the parent directories in gfl->files/gfl->dirs to the
+ * gfl->dirs list, the hash table is used to avoid duplicated
* entries. */
-
+
for (scan = gfl->dirs; scan; scan = scan->next)
g_hash_table_insert (h_dirs, (char*)scan->data, GINT_TO_POINTER (1));
-
+
gfl->dirs = g_list_concat (gfl->dirs, get_dir_list_from_file_list (h_dirs, gfl->base_dir, gfl->files, FALSE));
-
+
if (filter_empty (gfl->include_filter))
gfl->dirs = g_list_concat (gfl->dirs, get_dir_list_from_file_list (h_dirs, gfl->base_dir, gfl->dirs, TRUE));
-
+
/**/
-
+
if (error == NULL) {
GList *rel_files, *rel_dirs;
-
+
if (gfl->base_dir != NULL) {
rel_files = get_relative_file_list (NULL, gfl->files, gfl->base_dir);
rel_dirs = get_relative_file_list (NULL, gfl->dirs, gfl->base_dir);
@@ -611,13 +611,13 @@
gfl->files = NULL;
gfl->dirs = NULL;
}
-
+
/* rel_files/rel_dirs must be deallocated in done_func */
gfl->done_func (rel_files, rel_dirs, NULL, gfl->done_data);
}
else
gfl->done_func (NULL, NULL, error, gfl->done_data);
-
+
g_hash_table_destroy (h_dirs);
get_file_list_data_free (gfl);
}
@@ -625,7 +625,7 @@
static void
get_file_list_for_each_file (const char *uri,
- GFileInfo *info,
+ GFileInfo *info,
gpointer user_data)
{
GetFileListData *gfl = user_data;
@@ -635,10 +635,10 @@
gfl->dirs = g_list_prepend (gfl->dirs, g_strdup (uri));
break;
case G_FILE_TYPE_REGULAR:
- if (filter_matches (gfl->include_filter, uri))
- if ((gfl->exclude_filter->pattern == NULL) || ! filter_matches (gfl->exclude_filter, uri))
+ if (filter_matches (gfl->include_filter, uri))
+ if ((gfl->exclude_filter->pattern == NULL) || ! filter_matches (gfl->exclude_filter, uri))
gfl->files = g_list_prepend (gfl->files, g_strdup (uri));
- break;
+ break;
default:
break;
}
@@ -651,16 +651,16 @@
gpointer user_data)
{
GetFileListData *gfl = user_data;
-
+
if ((gfl->exclude_folders_filter->pattern == NULL) || ! filter_matches (gfl->exclude_folders_filter, uri))
return DIR_OP_CONTINUE;
- else
- return DIR_OP_SKIP;
+ else
+ return DIR_OP_SKIP;
}
void
-g_directory_list_async (const char *directory,
+g_directory_list_async (const char *directory,
const char *base_dir,
gboolean recursive,
gboolean follow_links,
@@ -676,13 +676,13 @@
{
GetFileListData *gfl;
FilterOptions filter_options;
-
+
gfl = g_new0 (GetFileListData, 1);
gfl->directory = g_strdup (directory);
gfl->base_dir = g_strdup (base_dir);
gfl->done_func = done_func;
gfl->done_data = done_data;
-
+
filter_options = FILTER_DEFAULT;
if (no_backup_files)
filter_options |= FILTER_NOBACKUPFILES;
@@ -693,7 +693,7 @@
gfl->include_filter = filter_new (include_files, filter_options);
gfl->exclude_filter = filter_new (exclude_files, ignorecase ? FILTER_IGNORECASE : FILTER_DEFAULT);
gfl->exclude_folders_filter = filter_new (exclude_folders, ignorecase ? FILTER_IGNORECASE : FILTER_DEFAULT);
-
+
g_directory_foreach_child (directory,
recursive,
follow_links,
@@ -819,7 +819,7 @@
gfl->files = g_list_prepend (gfl->files, rel_path);
}
}
-
+
gfl->current_dir = gfl->to_visit;
get_items_for_current_dir (gfl);
}
@@ -838,7 +838,7 @@
gpointer progress_callback_data;
CopyDoneCallback callback;
gpointer user_data;
-
+
GList *source;
GList *destination;
int n_file;
@@ -858,7 +858,7 @@
gpointer user_data)
{
CopyFilesData *cfd;
-
+
cfd = g_new0 (CopyFilesData, 1);
cfd->sources = gio_file_list_dup (sources);
cfd->destinations = gio_file_list_dup (destinations);
@@ -869,12 +869,12 @@
cfd->progress_callback_data = progress_callback_data;
cfd->callback = callback;
cfd->user_data = user_data;
-
+
cfd->source = cfd->sources;
cfd->destination = cfd->destinations;
cfd->n_file = 1;
cfd->tot_files = g_list_length (cfd->sources);
-
+
return cfd;
}
@@ -899,7 +899,7 @@
cfd->source = g_list_next (cfd->source);
cfd->destination = g_list_next (cfd->destination);
cfd->n_file++;
-
+
g_copy_current_file (cfd);
}
@@ -912,7 +912,7 @@
CopyFilesData *cfd = user_data;
GFile *source = cfd->source->data;
GError *error = NULL;
-
+
if (! g_file_copy_finish (source, result, &error)) {
if (cfd->callback)
cfd->callback (error, cfd->user_data);
@@ -920,7 +920,7 @@
copy_files_data_free (cfd);
return;
}
-
+
g_copy_next_file (cfd);
}
@@ -931,7 +931,7 @@
gpointer user_data)
{
CopyFilesData *cfd = user_data;
-
+
if (cfd->progress_callback)
cfd->progress_callback (cfd->n_file,
cfd->tot_files,
@@ -952,7 +952,7 @@
copy_files_data_free (cfd);
return;
}
-
+
g_file_copy_async ((GFile*) cfd->source->data,
(GFile*) cfd->destination->data,
cfd->flags,
@@ -977,15 +977,15 @@
gpointer user_data)
{
CopyFilesData *cfd;
-
- cfd = copy_files_data_new (sources,
- destinations,
- flags,
- io_priority,
- cancellable,
- progress_callback,
- progress_callback_data,
- callback,
+
+ cfd = copy_files_data_new (sources,
+ destinations,
+ flags,
+ io_priority,
+ cancellable,
+ progress_callback,
+ progress_callback_data,
+ callback,
user_data);
g_copy_current_file (cfd);
}
@@ -1004,20 +1004,20 @@
{
GList *source_files;
GList *destination_files;
-
+
source_files = g_list_append (NULL, (gpointer) source);
destination_files = g_list_append (NULL, (gpointer) destination);
-
- g_copy_files_async (source_files,
- destination_files,
- flags,
- io_priority,
- cancellable,
- progress_callback,
- progress_callback_data,
- callback,
+
+ g_copy_files_async (source_files,
+ destination_files,
+ flags,
+ io_priority,
+ cancellable,
+ progress_callback,
+ progress_callback_data,
+ callback,
user_data);
-
+
g_list_free (source_files);
g_list_free (destination_files);
}
@@ -1035,20 +1035,20 @@
gpointer user_data)
{
GList *source_files, *destination_files;
-
+
source_files = gio_file_list_new_from_uri_list (sources);
destination_files = gio_file_list_new_from_uri_list (destinations);
-
- g_copy_files_async (source_files,
- destination_files,
- flags,
- io_priority,
- cancellable,
- progress_callback,
- progress_callback_data,
- callback,
+
+ g_copy_files_async (source_files,
+ destination_files,
+ flags,
+ io_priority,
+ cancellable,
+ progress_callback,
+ progress_callback_data,
+ callback,
user_data);
-
+
gio_file_list_free (source_files);
gio_file_list_free (destination_files);
}
@@ -1067,10 +1067,10 @@
{
GList *source_list;
GList *destination_list;
-
+
source_list = g_list_append (NULL, (gpointer)source);
destination_list = g_list_append (NULL, (gpointer)destination);
-
+
g_copy_uris_async (source_list,
destination_list,
flags,
@@ -1080,7 +1080,7 @@
progress_callback_data,
callback,
user_data);
-
+
g_list_free (source_list);
g_list_free (destination_list);
}
@@ -1100,11 +1100,11 @@
GFileInfo *info)
{
ChildData *data;
-
+
data = g_new0 (ChildData, 1);
data->uri = g_strdup (uri);
data->info = g_file_info_dup (info);
-
+
return data;
}
@@ -1131,7 +1131,7 @@
CopyDoneCallback callback;
gpointer user_data;
GError *error;
-
+
GList *to_copy;
GList *current;
GFile *current_source;
@@ -1146,7 +1146,7 @@
{
if (dcd == NULL)
return;
-
+
g_free (dcd->source);
g_free (dcd->destination);
if (dcd->current_source != NULL) {
@@ -1164,27 +1164,27 @@
}
-static gboolean
+static gboolean
g_directory_copy_done (gpointer user_data)
{
DirectoryCopyData *dcd = user_data;
-
+
g_source_remove (dcd->source_id);
-
+
if (dcd->callback)
dcd->callback (dcd->error, dcd->user_data);
if (dcd->error != NULL)
g_clear_error (&(dcd->error));
directory_copy_data_free (dcd);
-
+
return FALSE;
}
static GFile *
-get_destination_for_uri (DirectoryCopyData *dcd,
+get_destination_for_uri (DirectoryCopyData *dcd,
const char *uri)
-{
+{
char *destination_uri;
GFile *destination_file;
@@ -1202,17 +1202,17 @@
static void g_directory_copy_current_child (DirectoryCopyData *dcd);
-static gboolean
+static gboolean
g_directory_copy_next_child (gpointer user_data)
{
DirectoryCopyData *dcd = user_data;
-
+
g_source_remove (dcd->source_id);
-
+
dcd->current = g_list_next (dcd->current);
dcd->n_file++;
g_directory_copy_current_child (dcd);
-
+
return FALSE;
}
@@ -1239,7 +1239,7 @@
gpointer user_data)
{
DirectoryCopyData *dcd = user_data;
-
+
if (dcd->progress_callback)
dcd->progress_callback (dcd->n_file,
dcd->tot_files,
@@ -1256,7 +1256,7 @@
{
ChildData *child;
gboolean async_op = FALSE;
-
+
if (dcd->current == NULL) {
dcd->source_id = g_idle_add (g_directory_copy_done, dcd);
return;
@@ -1278,24 +1278,24 @@
dcd->source_id = g_idle_add (g_directory_copy_next_child, dcd);
return;
}
-
+
switch (g_file_info_get_file_type (child->info)) {
- case G_FILE_TYPE_DIRECTORY:
+ case G_FILE_TYPE_DIRECTORY:
/* FIXME: how to make a directory asynchronously ? */
-
- /* doesn't check the returned error for now, because when an
+
+ /* doesn't check the returned error for now, because when an
* error occurs the code is not returned (for example when
- * a directory already exists the G_IO_ERROR_EXISTS code is
+ * a directory already exists the G_IO_ERROR_EXISTS code is
* *not* returned), so we cannot discriminate between warnings
* and fatal errors. (see bug #525155) */
-
- g_file_make_directory (dcd->current_destination,
- NULL,
+
+ g_file_make_directory (dcd->current_destination,
+ NULL,
NULL);
-
- /*if (! g_file_make_directory (dcd->current_destination,
- dcd->cancellable,
- &(dcd->error)))
+
+ /*if (! g_file_make_directory (dcd->current_destination,
+ dcd->cancellable,
+ &(dcd->error)))
{
dcd->source_id = g_idle_add (g_directory_copy_done, dcd);
return;
@@ -1303,16 +1303,16 @@
break;
case G_FILE_TYPE_SYMBOLIC_LINK:
/* FIXME: how to make a link asynchronously ? */
-
- g_file_make_symbolic_link (dcd->current_destination,
- g_file_info_get_symlink_target (child->info),
- NULL,
+
+ g_file_make_symbolic_link (dcd->current_destination,
+ g_file_info_get_symlink_target (child->info),
+ NULL,
NULL);
- /*if (! g_file_make_symbolic_link (dcd->current_destination,
- g_file_info_get_symlink_target (child->info),
- dcd->cancellable,
- &(dcd->error)))
+ /*if (! g_file_make_symbolic_link (dcd->current_destination,
+ g_file_info_get_symlink_target (child->info),
+ dcd->cancellable,
+ &(dcd->error)))
{
dcd->source_id = g_idle_add (g_directory_copy_done, dcd);
return;
@@ -1333,7 +1333,7 @@
default:
break;
}
-
+
if (! async_op)
dcd->source_id = g_idle_add (g_directory_copy_next_child, dcd);
}
@@ -1343,14 +1343,14 @@
g_directory_copy_start_copying (gpointer user_data)
{
DirectoryCopyData *dcd = user_data;
-
+
g_source_remove (dcd->source_id);
-
+
dcd->to_copy = g_list_reverse (dcd->to_copy);
dcd->current = dcd->to_copy;
dcd->n_file = 1;
g_directory_copy_current_child (dcd);
-
+
return FALSE;
}
@@ -1372,32 +1372,32 @@
static void
-g_directory_copy_for_each_file (const char *uri,
- GFileInfo *info,
+g_directory_copy_for_each_file (const char *uri,
+ GFileInfo *info,
gpointer user_data)
{
DirectoryCopyData *dcd = user_data;
-
+
dcd->to_copy = g_list_prepend (dcd->to_copy, child_data_new (uri, info));
dcd->tot_files++;
}
static DirOp
-g_directory_copy_start_dir (const char *uri,
+g_directory_copy_start_dir (const char *uri,
GError **error,
gpointer user_data)
-{
+{
DirectoryCopyData *dcd = user_data;
GFileInfo *info;
-
+
info = g_file_info_new ();
g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
dcd->to_copy = g_list_prepend (dcd->to_copy, child_data_new (uri, info));
g_object_unref (info);
-
+
dcd->tot_files++;
-
+
return DIR_OP_CONTINUE;
}
@@ -1414,7 +1414,7 @@
gpointer user_data)
{
DirectoryCopyData *dcd;
-
+
dcd = g_new0 (DirectoryCopyData, 1);
dcd->source = g_strdup (source);
dcd->destination = g_strdup (destination);
@@ -1424,8 +1424,8 @@
dcd->progress_callback = progress_callback;
dcd->progress_callback_data = progress_callback_data;
dcd->callback = callback;
- dcd->user_data = user_data;
-
+ dcd->user_data = user_data;
+
g_directory_foreach_child (dcd->source,
TRUE,
TRUE,
@@ -1435,3 +1435,24 @@
g_directory_copy_list_ready,
dcd);
}
+
+
+gboolean
+g_load_file_in_buffer (GFile *file,
+ void *buffer,
+ gsize size,
+ GError **error)
+{
+ GFileInputStream *istream;
+ int n;
+
+ istream = g_file_read (file, NULL, error);
+ if (istream == NULL)
+ return FALSE;
+
+ n = g_input_stream_read (G_INPUT_STREAM (istream), buffer, size, NULL, error);
+ g_object_unref (istream);
+
+ return (n >= 0);
+}
+
Modified: trunk/src/gio-utils.h
==============================================================================
--- trunk/src/gio-utils.h (original)
+++ trunk/src/gio-utils.h Mon Jul 28 18:57:15 2008
@@ -37,14 +37,14 @@
typedef DirOp (*StartDirCallback) (const char *uri,
GError **error,
gpointer user_data);
-typedef void (*ForEachChildCallback) (const char *uri,
- GFileInfo *info,
+typedef void (*ForEachChildCallback) (const char *uri,
+ GFileInfo *info,
gpointer user_data);
-typedef void (*ForEachDoneCallback) (GError *error,
- gpointer data);
-typedef void (*ListReadyCallback) (GList *files,
- GList *dirs,
- GError *error,
+typedef void (*ForEachDoneCallback) (GError *error,
+ gpointer data);
+typedef void (*ListReadyCallback) (GList *files,
+ GList *dirs,
+ GError *error,
gpointer user_data);
typedef void (*CopyProgressCallback) (goffset current_file,
goffset total_files,
@@ -55,7 +55,7 @@
gpointer user_data);
typedef void (*CopyDoneCallback) (GError *error,
gpointer user_data);
-
+
/* asynchronous recursive list functions */
void g_directory_foreach_child (const char *directory,
@@ -66,7 +66,7 @@
ForEachChildCallback for_each_file_func,
ForEachDoneCallback done_func,
gpointer user_data);
-void g_directory_list_async (const char *directory,
+void g_directory_list_async (const char *directory,
const char *base_dir,
gboolean recursive,
gboolean follow_links,
@@ -84,8 +84,8 @@
GCancellable *cancellable,
ListReadyCallback done_func,
gpointer done_data);
-
-/* asynchronous copy functions */
+
+/* asynchronous copy functions */
void g_copy_files_async (GList *sources,
GList *destinations,
@@ -122,7 +122,7 @@
CopyProgressCallback progress_callback,
gpointer progress_callback_data,
CopyDoneCallback callback,
- gpointer user_data);
+ gpointer user_data);
void g_directory_copy_async (const char *source,
const char *destination,
GFileCopyFlags flags,
@@ -132,17 +132,22 @@
gpointer progress_callback_data,
CopyDoneCallback callback,
gpointer user_data);
+gboolean g_load_file_in_buffer (GFile *file,
+ void *buffer,
+ gsize size,
+ GError **error);
/* convenience macros */
+
/**
* g_directory_list_all_async:
- * @directory:
- * @base_dir:
+ * @directory:
+ * @base_dir:
* @recursive:
* @cancellable:
* @done_func:
* @done_data:
- *
+ *
*/
#define g_directory_list_all_async(directory, base_dir, recursive, cancellable, done_func, done_data) \
g_directory_list_async ((directory), (base_dir), (recursive), TRUE, FALSE, FALSE, NULL, NULL, NULL, FALSE, (cancellable), (done_func), (done_data))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]