aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-path.c48
-rw-r--r--e-util/e-path.h1
3 files changed, 54 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 53cdc63750..c1b916be6f 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+2002-08-22 Dan Winship <danw@ximian.com>
+
+ * e-path.c (e_path_rmdir): Remove an e_path directory, and its
+ parent "subfolders" dir if it's now empty.
+
2002-08-22 JP Rosevear <jpr@ximian.com>
* e-time-utils.c (e_time_parse_date): if the year was two digits,
diff --git a/e-util/e-path.c b/e-util/e-path.c
index 06ac05ef25..06b75686b1 100644
--- a/e-util/e-path.c
+++ b/e-util/e-path.c
@@ -23,6 +23,7 @@
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <glib.h>
#include "e-path.h"
@@ -204,3 +205,50 @@ e_path_find_folders (const char *prefix,
{
return find_folders_recursive (prefix, "", callback, data);
}
+
+
+/**
+ * e_path_rmdir:
+ * @prefix: a prefix to prepend to the path, or %NULL
+ * @path: the virtual path to convert to a filesystem path.
+ *
+ * This removes the directory pointed to by @prefix and @path
+ * and attempts to remove its parent "subfolders" directory too
+ * if it's empty.
+ *
+ * Return value: -1 (with errno set) if it failed to rmdir the
+ * specified directory. 0 otherwise, whether or not it removed
+ * the parent directory.
+ **/
+int
+e_path_rmdir (const char *prefix, const char *vpath)
+{
+ char *physical_path, *p;
+
+ /* Remove the directory itself */
+ physical_path = e_path_to_physical (prefix, vpath);
+ if (rmdir (physical_path) == -1) {
+ g_free (physical_path);
+ return -1;
+ }
+
+ /* Attempt to remove its parent "subfolders" directory,
+ * ignoring errors since it might not be empty.
+ */
+
+ p = strrchr (physical_path, '/');
+ if (p[1] == '\0') {
+ g_free (physical_path);
+ return 0;
+ }
+ *p = '\0';
+ p = strrchr (physical_path, '/');
+ if (!p || strcmp (p + 1, SUBFOLDER_DIR_NAME) != 0) {
+ g_free (physical_path);
+ return 0;
+ }
+
+ rmdir (physical_path);
+ g_free (physical_path);
+ return 0;
+}
diff --git a/e-util/e-path.h b/e-util/e-path.h
index a40cf9fb16..2295889778 100644
--- a/e-util/e-path.h
+++ b/e-util/e-path.h
@@ -32,4 +32,5 @@ gboolean e_path_find_folders (const char *prefix,
EPathFindFoldersCallback callback,
gpointer data);
+int e_path_rmdir (const char *prefix, const char *vpath);
#endif /* __E_PATH__ */