]> git.street.me.uk Git - andy/viking.git/commitdiff
Fix "corrupted tile" problem -- was really just that incomplete tiles were being...
authorEvan Battaglia <gtoevan@gmx.net>
Sun, 13 May 2007 18:10:25 +0000 (18:10 +0000)
committerEvan Battaglia <gtoevan@gmx.net>
Sun, 13 May 2007 18:10:25 +0000 (18:10 +0000)
ChangeLog
src/download.c

index 053af4f197275714485fc228ea790322f8a35362..11b3418cadb28bf0fbe256289710c29bbbb1c435 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+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.
index e23e7863becb0d42be52f7dbda54f6af9bafa4b2..9884337017b0f0cca98f89c5eb8336797e9687bb 100644 (file)
@@ -66,6 +66,7 @@ static int download( const char *hostname, const char *uri, const char *fn, int
 {
   FILE *f;
   int ret;
+  char *tmpfilename;
 
   /* Check file */
   if ( access ( fn, F_OK ) == 0 )
@@ -87,8 +88,18 @@ static int download( const char *hostname, const char *uri, const char *fn, int
 #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 */
@@ -101,11 +112,14 @@ static int download( const char *hostname, const char *uri, const char *fn, int
   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;
 }