put some code in a function
authorDana Jansens <danakj@orodu.net>
Tue, 29 May 2007 23:46:26 +0000 (23:46 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 29 May 2007 23:46:26 +0000 (23:46 +0000)
src/install.c

index 7d1670028023eae7ca3cbc5e32b74eb0015cc084..0778cd97008ca2e76df19b74b1e3d4b119d40eeb 100644 (file)
@@ -28,6 +28,7 @@ static int gzopen_frontend(const char *path, int oflags, int mode);
 static int gzclose_frontend(int nothing);
 static ssize_t gzread_frontend(int nothing, void *buf, size_t s);
 static ssize_t gzwrite_frontend(int nothing, const void *buf, size_t s);
+static gchar *get_theme_dir();
 
 tartype_t funcs = {
     (openfunc_t) gzopen_frontend,
@@ -36,6 +37,23 @@ tartype_t funcs = {
     (writefunc_t) gzwrite_frontend
 };
 
+static gchar *get_theme_dir()
+{
+    gchar *dir;
+
+    dir = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".themes", NULL);
+    r = mkdir(dir, 0777);
+    if (r == -1 && errno != EEXIST) {
+        gtk_msg(GTK_MESSAGE_ERROR,
+                _("Unable to create directory \"%s\": %s"),
+                dir, strerror(errno));
+        g_free(dir);
+        dir = NULL;
+    }
+
+    return dir;
+}
+
 gboolean install_theme(char *path, char *theme)
 {
     TAR *t;
@@ -44,14 +62,9 @@ gboolean install_theme(char *path, char *theme)
     gchar *glob;
     gchar *curdir;
 
-    dest = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".themes", NULL);
-    r = mkdir(dest, 0777);
-    if (r == -1 && errno != EEXIST) {
-        gtk_msg(GTK_MESSAGE_ERROR,
-                _("Unable to create directory \"%s\": %s"),
-                dest, strerror(errno));
+    if (!(dest = get_theme_dir()))
         return FALSE;
-    }
+
     curdir = g_get_current_dir();
     if (chdir(dest) == -1) {
         gtk_msg(GTK_MESSAGE_ERROR,