+2007-05-13
+Evan Battaglia <gtoevan@gmx.net>
+ * Fix problem of "bad" tiles showing up when downloading. The problem was loading of incomplete tiles. Fixed this by first downloading to a temporary file, then moving when complete.
+
2007-05-11
Evan Battaglia <gtoevan@gmx.net>
* Fix removal of redownloaded tiles from memory cache.
{
FILE *f;
int ret;
+ char *tmpfilename;
/* Check file */
if ( access ( fn, F_OK ) == 0 )
#endif
g_free ( tmp );
}
+ /* create placeholder file */
if ( ! (f = fopen ( fn, "w+b" )) ) /* immediately open file so other threads won't -- prevents race condition */
return -4;
+ fclose ( f );
+ }
+
+ tmpfilename = g_strdup_printf("%s.tmp", fn);
+ f = fopen ( tmpfilename, "w+b" );
+ if ( ! f ) {
+ g_free ( tmpfilename );
+ remove ( fn ); /* couldn't create temporary. delete 0-byte file. */
+ return -4;
}
/* Call the backend function */
if (ret == -1 || ret == 1 || ret == -2)
{
fclose ( f );
- remove ( fn );
+ remove ( tmpfilename );
+ g_free ( tmpfilename );
return -1;
}
fclose ( f );
+ rename ( tmpfilename, fn ); /* move completely-downloaded file to permanent location */
+ g_free ( tmpfilename );
return ret;
}