diff options
-rw-r--r-- | embed/ephy-web-app-utils.c | 53 | ||||
-rw-r--r-- | lib/ephy-file-helpers.c | 81 | ||||
-rw-r--r-- | lib/ephy-file-helpers.h | 3 |
3 files changed, 63 insertions, 74 deletions
diff --git a/embed/ephy-web-app-utils.c b/embed/ephy-web-app-utils.c index 7920ebc4c..f2da66adb 100644 --- a/embed/ephy-web-app-utils.c +++ b/embed/ephy-web-app-utils.c @@ -29,57 +29,6 @@ #include <glib/gstdio.h> #include <libsoup/soup-gnome.h> -static gboolean -_g_directory_delete_recursively (GFile *directory, GError **error) -{ - GFileEnumerator *children = NULL; - GFileInfo *info; - gboolean ret = TRUE; - - children = g_file_enumerate_children (directory, - "standard::name,standard::type", - 0, NULL, error); - if (error) - goto out; - - info = g_file_enumerator_next_file (children, NULL, error); - while (info || error) { - GFile *child; - const char *name; - GFileType type; - - if (error) - goto out; - - name = g_file_info_get_name (info); - child = g_file_get_child (directory, name); - type = g_file_info_get_file_type (info); - - if (type == G_FILE_TYPE_DIRECTORY) - ret = _g_directory_delete_recursively (child, error); - else if (type == G_FILE_TYPE_REGULAR) - ret = g_file_delete (child, NULL, error); - - g_object_unref (info); - - if (!ret) - goto out; - - info = g_file_enumerator_next_file (children, NULL, error); - } - - ret = TRUE; - - g_file_delete (directory, NULL, error); - -out: - - if (children) - g_object_unref (children); - - return ret; -} - /** * ephy_web_application_get_directory: * @app_name: the application name @@ -129,7 +78,7 @@ ephy_web_application_delete (const char *name) } profile = g_file_new_for_path (profile_dir); - if (!_g_directory_delete_recursively (profile, NULL)) + if (!ephy_file_delete_dir_recursively (profile, NULL)) goto out; g_print ("Deleted application profile.\n"); diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index f1e2e0e41..80d30e06d 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -381,8 +381,15 @@ ephy_file_helpers_shutdown (void) { if (!keep_temp_directory) { - /* recursively delete the contents and the directory */ - ephy_file_delete_directory (tmp_dir); + GFile *tmp_dir_file; + tmp_dir_file = g_file_new_for_path (tmp_dir); + + /* recursively delete the contents and the + * directory */ + LOG ("shutdown: delete tmp_dir %s", tmp_dir); + ephy_file_delete_dir_recursively (tmp_dir_file, + NULL); + g_object_unref (tmp_dir_file); } g_free (tmp_dir); @@ -855,30 +862,62 @@ ephy_file_browse_to (GFile *file, } /** - * ephy_file_delete_directory: - * @path: the path to remove + * ephy_file_delete_dir_recursively: + * @directory: directory to remove + * @error: location to set any #GError * * Remove @path and its contents. Like calling rm -rf @path. **/ -void -ephy_file_delete_directory (const char *path) +gboolean +ephy_file_delete_dir_recursively (GFile *directory, GError **error) { - GFile *file; - gboolean ret; - - file = g_file_new_for_path (path); - - ret = g_file_delete (file, NULL, NULL); - - if (ret == TRUE) - { - LOG ("Deleted dir '%s'", path); - } - else - { - LOG ("Couldn't delete dir '%s'", path); + GFileEnumerator *children = NULL; + GFileInfo *info; + gboolean ret = TRUE; + + children = g_file_enumerate_children (directory, + "standard::name,standard::type", + 0, NULL, error); + if (error) + goto out; + + info = g_file_enumerator_next_file (children, NULL, error); + while (info || error) { + GFile *child; + const char *name; + GFileType type; + + if (error) + goto out; + + name = g_file_info_get_name (info); + child = g_file_get_child (directory, name); + type = g_file_info_get_file_type (info); + + LOG ("ephy-file-delete-dir: delete child %s", name); + if (type == G_FILE_TYPE_DIRECTORY) + ret = ephy_file_delete_dir_recursively (child, error); + else if (type == G_FILE_TYPE_REGULAR) + ret = g_file_delete (child, NULL, error); + + g_object_unref (info); + + if (!ret) + goto out; + + info = g_file_enumerator_next_file (children, NULL, error); } - g_object_unref (file); + + ret = TRUE; + + LOG ("ephy-file-delete-dir: delete successful"); + g_file_delete (directory, NULL, error); + +out: + if (children) + g_object_unref (children); + + return ret; } /** diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h index 0c5ab9b3d..d36783579 100644 --- a/lib/ephy-file-helpers.h +++ b/lib/ephy-file-helpers.h @@ -83,7 +83,8 @@ gboolean ephy_file_launch_handler (const char *mime_type, guint32 user_time); gboolean ephy_file_browse_to (GFile *file, guint32 user_time); -void ephy_file_delete_directory (const char *path); +gboolean ephy_file_delete_dir_recursively (GFile *file, + GError **error); void ephy_file_delete_uri (const char *uri); void ephy_file_load_accels (void); void ephy_file_save_accels (void); |