Browse Source

fix error handling for core API re-download case

David Rose 14 years ago
parent
commit
c17f0dce3d

+ 27 - 0
direct/src/plugin/fileSpec.cxx

@@ -301,6 +301,33 @@ full_verify(const string &package_dir) {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: FileSpec::force_get_actual_file
+//       Access: Public
+//  Description: Returns a FileSpec that represents the actual data
+//               read on disk.  This will read the disk to determine
+//               the data if necessary.
+////////////////////////////////////////////////////////////////////
+const FileSpec *FileSpec::
+force_get_actual_file(const string &pathname) {
+  if (_actual_file == NULL) {
+#ifdef _WIN32
+    struct _stat st;
+    wstring pathname_w;
+    if (string_to_wstring(pathname_w, pathname)) {
+      _wstat(pathname_w.c_str(), &st);
+    }
+#else // _WIN32
+    struct stat st;
+    stat(pathname.c_str(), &st);
+#endif  // _WIN32
+
+    priv_check_hash(pathname, &st);
+  }
+
+  return _actual_file;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: FileSpec::check_hash
 //       Access: Public

+ 1 - 0
direct/src/plugin/fileSpec.h

@@ -47,6 +47,7 @@ public:
   bool quick_verify_pathname(const string &pathname);
   bool full_verify(const string &package_dir);
   inline const FileSpec *get_actual_file() const;
+  const FileSpec *force_get_actual_file(const string &pathname);
   
   bool check_hash(const string &pathname) const;
   bool read_hash(const string &pathname);

+ 16 - 2
direct/src/plugin_npapi/ppInstance.cxx

@@ -1670,12 +1670,20 @@ downloaded_plugin(const string &filename) {
   // Make sure the DLL was correctly downloaded before continuing.
   if (!_coreapi_dll.quick_verify_pathname(filename)) {
     nout << "After download, " << _coreapi_dll.get_filename() << " is no good.\n";
+    nout << "Expected:\n";
+    _coreapi_dll.write(nout);
+    const FileSpec *actual = _coreapi_dll.force_get_actual_file(filename);
+    if (actual != NULL) {
+      nout << "Found:\n";
+      actual->write(nout);
+    }
 
     // That DLL came out wrong.  Try the next URL.
     if (!_core_urls.empty()) {
       string url = _core_urls.back();
       _core_urls.pop_back();
-      
+
+      _core_dll_temp_file.cleanup();
       PPDownloadRequest *req = new PPDownloadRequest(PPDownloadRequest::RT_core_dll);
       start_download(url, req);
       return;
@@ -3260,7 +3268,13 @@ open() {
 bool PPInstance::StreamTempFile::
 feed(size_t total_expected_data, const void *this_data,
      size_t this_data_size) {
-  assert(!_finished);
+  if (_finished) {
+    nout << "feed(" << total_expected_data << ", " << (void *)this_data
+         << ", " << this_data_size << ") to " << _filename
+         << ", but already finished at " << _current_size << "\n";
+    return false;
+  }
+
   if (!_opened) {
     open();
   }