From: Andy Spencer Date: Tue, 9 Feb 2010 17:17:57 +0000 (+0000) Subject: Use .part files for downloads X-Git-Tag: v0.4~43 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=d1e2d70c4f601f09d2df0f728a6ea4eb1c12f8de Use .part files for downloads --- diff --git a/src/data/gis-http.c b/src/data/gis-http.c index fb742c7..d9f29a5 100644 --- a/src/data/gis-http.c +++ b/src/data/gis-http.c @@ -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.. */ diff --git a/src/data/gis-wms.c b/src/data/gis-wms.c index 35eb988..e1de457 100644 --- a/src/data/gis-wms.c +++ b/src/data/gis-wms.c @@ -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);