Browse Source

fix throttling on slow machines

David Rose 23 years ago
parent
commit
e5c2fc201e
2 changed files with 23 additions and 1 deletions
  1. 14 0
      panda/src/downloader/decompressor.cxx
  2. 9 1
      panda/src/downloader/httpChannel.cxx

+ 14 - 0
panda/src/downloader/decompressor.cxx

@@ -116,6 +116,20 @@ initiate(const Filename &source_file, const Filename &dest_file) {
 
 
   ofstream *dest_fstream = new ofstream;
   ofstream *dest_fstream = new ofstream;
   _dest = dest_fstream;
   _dest = dest_fstream;
+  if (dest_filename.exists()) {
+    downloader_cat.info()
+      << dest_filename << " already exists, removing.\n";
+    if (!dest_filename.unlink()) {
+      downloader_cat.error()
+        << "Unable to remove old " << dest_filename << "\n";
+      return get_write_error();
+    }
+  } else {
+    if (downloader_cat.is_debug()) {
+      downloader_cat.debug()
+        << dest_filename << " does not already exist.\n";
+    }
+  }
   if (!dest_filename.open_write(*dest_fstream)) {
   if (!dest_filename.open_write(*dest_fstream)) {
     downloader_cat.error()
     downloader_cat.error()
       << "Unable to write to " << dest_filename << "\n";
       << "Unable to write to " << dest_filename << "\n";

+ 9 - 1
panda/src/downloader/httpChannel.cxx

@@ -224,8 +224,15 @@ run() {
         // Come back later.
         // Come back later.
         return true;
         return true;
       }
       }
+      int num_potential_updates = (int)(elapsed / _seconds_per_update);
       _last_run_time = now;
       _last_run_time = now;
-      _bytes_requested += _bytes_per_update;
+      _bytes_requested += _bytes_per_update * num_potential_updates;
+      if (downloader_cat.is_spam()) {
+        downloader_cat.spam()
+          << "elapsed = " << elapsed << " num_potential_updates = " 
+          << num_potential_updates << " bytes_requested = " 
+          << _bytes_requested << "\n";
+      }
     }
     }
     switch (_download_dest) {
     switch (_download_dest) {
     case DD_none:
     case DD_none:
@@ -568,6 +575,7 @@ reached_done_state() {
       return false;
       return false;
     } else {
     } else {
       _started_download = true;
       _started_download = true;
+      _last_run_time = ClockObject::get_global_clock()->get_real_time();
       return true;
       return true;
     }
     }
   }
   }