[gthumb] Reduce the number of basically identical file delete functions
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Reduce the number of basically identical file delete functions
- Date: Tue, 12 May 2009 12:00:56 -0400 (EDT)
commit 6f9f9305b01642831a7eba2f3cd8d8006e7e8797
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Tue May 12 12:00:29 2009 -0400
Reduce the number of basically identical file delete functions
---
libgthumb/file-utils.c | 69 ++++++++++++++---------------------
libgthumb/file-utils.h | 5 +--
src/gth-browser-actions-callbacks.c | 2 +-
3 files changed, 31 insertions(+), 45 deletions(-)
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 517a429..175b592 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -325,27 +325,6 @@ dir_make (const gchar *path)
gboolean
-dir_remove (const gchar *path)
-{
- GFile *gfile;
- gboolean result;
- GError *error = NULL;
-
- gfile = gfile_new (path);
- result = g_file_delete (gfile, NULL, &error);
-
- if (error != NULL) {
- gfile_warning ("Could not remove directory", gfile, error);
- g_error_free (error);
- }
-
- g_object_unref (gfile);
-
- return result;
-}
-
-
-gboolean
dir_remove_recursive (const char *path)
{
GFile *gfile;
@@ -627,19 +606,38 @@ file_move (const char *from,
}
+void
+file_unlink_with_gerror (const char *path,
+ GError **gerror)
+{
+ /* Also works with empty directories */
+ GFile *gfile;
+
+ g_assert (path != NULL);
+
+ gfile = gfile_new (path);
+ if (g_file_query_exists (gfile, NULL))
+ g_file_delete (gfile, NULL, gerror);
+ g_object_unref (gfile);
+}
+
+
gboolean
file_unlink (const char *path)
{
- GFile *file;
- gboolean result;
-
+ gboolean result = TRUE;
+ GError *error = NULL;
+
g_assert (path != NULL);
-
- file = gfile_new (path);
-
- result = g_file_delete (file, NULL, NULL);
-
- g_object_unref (file);
+
+ /* Also works with empty directories */
+ file_unlink_with_gerror (path, &error);
+
+ if (error != NULL) {
+ g_warning ("File/path delete failed: %s", error->message);
+ g_error_free (error);
+ result = FALSE;
+ }
return result;
}
@@ -1796,17 +1794,6 @@ get_catalog_full_path (const char *relative_path)
}
-void
-delete_catalog (const char *full_path,
- GError **gerror)
-{
- GFile *gfile;
- gfile = gfile_new (full_path);
- g_file_delete (gfile, NULL, gerror);
- g_object_unref (gfile);
-}
-
-
gboolean
file_is_search_result (const char *path)
{
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index dd3591e..a0dd1ce 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -87,7 +87,6 @@ GList * path_list_find_path (GList *list,
/* Directory utils */
gboolean dir_make (const char *uri);
-gboolean dir_remove (const char *uri);
gboolean dir_remove_recursive (const char *path);
gboolean ensure_dir_exists (const char *path);
@@ -120,6 +119,8 @@ gboolean file_copy (const char *from,
const char *to);
gboolean file_move (const char *from,
const char *to);
+void file_unlink_with_gerror (const char *full_path,
+ GError **gerror);
gboolean file_unlink (const char *path);
void delete_thumbnail (const char *path);
gboolean mime_type_is (const char *mime_type,
@@ -178,8 +179,6 @@ gboolean uri_is_root (const char *uri);
/* Catalogs */
char * get_catalog_full_path (const char *relative_path);
-void delete_catalog (const char *full_path,
- GError **error);
gboolean file_is_search_result (const char *full_path);
/* escape */
diff --git a/src/gth-browser-actions-callbacks.c b/src/gth-browser-actions-callbacks.c
index f931148..e942735 100644
--- a/src/gth-browser-actions-callbacks.c
+++ b/src/gth-browser-actions-callbacks.c
@@ -555,7 +555,7 @@ real_catalog_delete (GthBrowser *browser)
if (catalog_path == NULL)
return;
- delete_catalog (catalog_path, &error);
+ file_unlink_with_gerror (catalog_path, &error);
if (error)
_gtk_error_dialog_from_gerror_run (GTK_WINDOW (browser), &error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]