diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-08-10 07:34:19 -0400 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-08-10 12:17:50 -0400 |
commit | 1027ad3ff9e4d2884b6b49b0c821b06af24ecc00 (patch) | |
tree | f69e64f05a19735d884a00213aae374751027acd | |
parent | e5f62323b54210d7ad21979b989ddabf87cf35cf (diff) | |
download | evolution-data-server-1027ad3ff9e4d2884b6b49b0c821b06af24ecc00.tar.gz |
mbox_store_get_full_path(): Improve path building.
Deal with the root path not ending in a directory separator, and use a
GString for heaven sake!
(cherry picked from commit 0a9a5edcc872a75af97345e4137e98f2bceabdab)
-rw-r--r-- | camel/providers/local/camel-mbox-store.c | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c index 0354a8b41..e7ab51438 100644 --- a/camel/providers/local/camel-mbox-store.c +++ b/camel/providers/local/camel-mbox-store.c @@ -904,10 +904,9 @@ mbox_store_get_full_path (CamelLocalStore *ls, CamelLocalSettings *local_settings; CamelSettings *settings; CamelService *service; - const gchar *inptr = full_name; - gint subdirs = 0; + GString *full_path; gchar *root_path; - gchar *path, *p; + const gchar *cp; service = CAMEL_SERVICE (ls); settings = camel_service_get_settings (service); @@ -916,35 +915,29 @@ mbox_store_get_full_path (CamelLocalStore *ls, root_path = camel_local_settings_dup_path (local_settings); g_return_val_if_fail (root_path != NULL, NULL); - while (*inptr != '\0') { - if (G_IS_DIR_SEPARATOR (*inptr)) - subdirs++; - inptr++; - } - - path = g_malloc (strlen (root_path) + (inptr - full_name) + (4 * subdirs) + 1); - p = g_stpcpy (path, root_path); - - g_free (root_path); + full_path = g_string_new (root_path); - inptr = full_name; - while (*inptr != '\0') { - while (!G_IS_DIR_SEPARATOR (*inptr) && *inptr != '\0') - *p++ = *inptr++; + /* Root path may or may not have a trailing separator. */ + if (!g_str_has_suffix (root_path, G_DIR_SEPARATOR_S)) + g_string_append_c (full_path, G_DIR_SEPARATOR); - if (G_IS_DIR_SEPARATOR (*inptr)) { - p = g_stpcpy (p, ".sbd/"); - inptr++; + cp = full_name; + while (*cp != '\0') { + if (G_IS_DIR_SEPARATOR (*cp)) { + g_string_append (full_path, ".sbd"); + g_string_append_c (full_path, *cp++); - /* strip extranaeous '/'s */ - while (G_IS_DIR_SEPARATOR (*inptr)) - inptr++; + /* Skip extranaeous separators. */ + while (G_IS_DIR_SEPARATOR (*cp)) + cp++; + } else { + g_string_append_c (full_path, *cp++); } } - *p = '\0'; + g_free (root_path); - return path; + return g_string_free (full_path, FALSE); } static gchar * |