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 = {
soup_message_headers_set_range(message->request_headers, ftell(fp), -1);
soup_session_send_message(http->soup, message);
+ /* Close file */
+ fclose(fp);
+ if (path != part && SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
+ g_rename(part, path);
+ g_free(part);
+ }
+
/* Finished */
if (message->status_code == 416) {
/* Range unsatisfiable, file already complete */
- } else if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code))
+ } else if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
g_warning("GisHttp: done_cb - error copying file, status=%d\n"
"\tsrc=%s\n"
"\tdst=%s",
message->status_code, uri, path);
+ return NULL;
+ }
}
/* TODO: free everything.. */