[evolution-ews/gnome-3-8] Refactor and clean up ews_download_gal() (cherry picked from commit e4a0fc5403f61b6bcb16984cbf1d9b4d



commit 47e4903598885cd386a54b123a9efb7c53eef07a
Author: David Woodhouse <David Woodhouse intel com>
Date:   Mon Jun 10 23:41:57 2013 +0100

    Refactor and clean up ews_download_gal()
    (cherry picked from commit e4a0fc5403f61b6bcb16984cbf1d9b4da291e9ac)

 src/addressbook/e-book-backend-ews.c |   42 +++++++++++++++------------------
 1 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 4490aec..b36b31c 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -1806,8 +1806,7 @@ ews_download_gal (EBookBackendEws *cbews, EwsOALDetails *full, GSList *deltas, g
 #ifdef USE_MSPACK
        EBookBackendEwsPrivate *priv = cbews->priv;
        GSList *p;
-       gchar *thisoab, *nextoab = NULL;
-       gchar *oab_file = NULL, *lzx_path = NULL;
+       gchar *thisoab = NULL;
        const gchar *cache_dir;
 
        cache_dir = e_book_backend_get_cache_dir (E_BOOK_BACKEND (cbews));
@@ -1820,54 +1819,51 @@ ews_download_gal (EBookBackendEws *cbews, EwsOALDetails *full, GSList *deltas, g
        for (p = deltas; p; p = p->next) {
                EwsOALDetails *det = p->data;
                GError *local_error = NULL;
+               gchar *oab_file, *lzx_path, *nextoab;
 
                seq++;
                if (det->seq != seq)
                        break;
 
-               if (lzx_path) {
-                       g_unlink (lzx_path);
-                       g_free (lzx_path);
-               }
                lzx_path = ews_download_gal_file (cbews, det, cancellable, NULL);
                if (!lzx_path)
                        break;
 
-               g_free (oab_file);
                oab_file = g_strdup_printf ("%s-%d.oab", priv->folder_name, seq);
                nextoab = g_build_filename (cache_dir, oab_file, NULL);
+               g_free (oab_file);
+
+               ews_oab_decompress_patch (lzx_path, thisoab, nextoab, &local_error);
+
+               /* Free the LZX file */
+               g_unlink (lzx_path);
+               g_free (lzx_path);
+
+               /* Free the previous OAB file */
+               g_unlink (thisoab);
+               g_free (thisoab);
+
+               thisoab = nextoab;
 
-               if (!ews_oab_decompress_patch (lzx_path, thisoab, nextoab, &local_error)) {
+               /* For once we are *allowed* to use the error instead of having to
+                * check the return value of the function. It's our *own* error. */
+               if (local_error) {
                        d (g_print ("Failed to apply incremental patch: %s\n",
                                    local_error->message));
                        g_error_free (local_error);
                        break;
                }
-               d (g_print ("Created %s from delta\n", oab_file));
 
-               g_unlink (thisoab);
-               g_free (thisoab);
-               thisoab = nextoab;
-               nextoab = NULL;
+               d (g_print ("Created %s from delta\n", thisoab));
 
                if (seq == full->seq)
                        return thisoab;
        }
 
-       if (nextoab) {
-               g_unlink (nextoab);
-               g_free (nextoab);
-       }
        if (thisoab) {
                g_unlink (thisoab);
                g_free (thisoab);
        }
-       g_free (oab_file);
-       if (lzx_path) {
-               g_unlink (lzx_path);
-               g_free (lzx_path);
-       }
-
  full:
 #endif
        d (printf ("Ewsgal: Downloading full gal \n"));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]