]> Pileus Git - grits/commitdiff
Use .part files for downloads
authorAndy Spencer <andy753421@gmail.com>
Tue, 9 Feb 2010 17:17:57 +0000 (17:17 +0000)
committerAndy Spencer <andy753421@gmail.com>
Tue, 9 Feb 2010 17:17:57 +0000 (17:17 +0000)
src/data/gis-http.c
src/data/gis-wms.c

index fb742c7e0e8d1d8b5c0d3981226c7e45cc197902..d9f29a5d52c1f87ce06c69b69ca218b6780bc9c9 100644 (file)
@@ -133,7 +133,10 @@ gchar *gis_http_fetch(GisHttp *http, const gchar *uri, const char *local,
                g_debug("GisHttp: do_cache - Caching file %s", local);
 
                /* Open the file for writting */
-               FILE *fp = fopen_p(path, "a");
+               gchar *part = path;
+               if (!g_file_test(path, G_FILE_TEST_EXISTS))
+                       part = g_strdup_printf("%s.part", path);
+               FILE *fp = fopen_p(part, "a");
 
                /* Make temp data */
                struct _CacheInfo info = {
@@ -159,6 +162,13 @@ gchar *gis_http_fetch(GisHttp *http, const gchar *uri, const char *local,
                                        "\tsrc=%s\n"
                                        "\tdst=%s",
                                        message->status_code, uri, path);
+
+               /* Close file */
+               fclose(fp);
+               if (path != part && SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
+                       g_rename(part, path);
+                       g_free(part);
+               }
        }
 
        /* TODO: free everything.. */
index 35eb988d13243cd7b56ed6608e778acf0c5e1d0c..e1de457e05b3a9938bbc5add2cff97c551a65658 100644 (file)
@@ -119,7 +119,6 @@ gchar *gis_wms_fetch(GisWms *wms, GisTile *tile, GisCacheType mode,
        gchar *uri   = _make_uri(wms, tile);
        gchar *tilep = gis_tile_get_path(tile);
        gchar *local = g_strdup_printf("%s%s", tilep, wms->extension);
-       mode = GIS_ONCE;
        gchar *path  = gis_http_fetch(wms->http, uri, local,
                        mode, callback, user_data);
        g_free(uri);