David Rose 16 vuotta sitten
vanhempi
sitoutus
ac0f84ace1

+ 16 - 6
direct/src/plugin/mkdir_complete.cxx

@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>  // for mkdir()
 #include <errno.h>
+#include <string.h>     // strerror()
 #endif
 
 
@@ -54,7 +55,7 @@ get_dirname(const string &filename) {
 //               necessary.
 ////////////////////////////////////////////////////////////////////
 bool
-mkdir_complete(const string &dirname) {
+mkdir_complete(const string &dirname, ostream &logfile) {
 #ifdef _WIN32
   if (CreateDirectory(dirname.c_str(), NULL) != 0) {
     // Success!
@@ -77,6 +78,8 @@ mkdir_complete(const string &dirname) {
         // Got it!
         return true;
       }
+      logfile 
+        << "Couldn't create " << dirname << "\n";
     }
   }
   return false;
@@ -93,15 +96,18 @@ mkdir_complete(const string &dirname) {
     return true;
   }
 
-  if (errno == ENOENT) {
+  if (errno == ENOENT || errno == EACCES) {
     // We need to make the parent directory first.
     string parent = get_dirname(dirname);
-    if (!parent.empty() && mkdir_complete(parent)) {
+    if (!parent.empty() && mkdir_complete(parent, logfile)) {
       // Parent successfully created.  Try again to make the child.
       if (mkdir(dirname.c_str(), 0777) == 0) {
         // Got it!
         return true;
       }
+      // Couldn't create the directory. :(
+      logfile 
+        << "Couldn't create " << dirname << ": " << strerror(errno) << "\n";
     }
   }
   return false;
@@ -117,7 +123,7 @@ mkdir_complete(const string &dirname) {
 //               needed.
 ////////////////////////////////////////////////////////////////////
 bool
-mkfile_complete(const string &filename) {
+mkfile_complete(const string &filename, ostream &logfile) {
 #ifdef _WIN32
   HANDLE file = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
                            FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
@@ -125,13 +131,15 @@ mkfile_complete(const string &filename) {
   if (file == INVALID_HANDLE_VALUE) {
     // Try to make the parent directory first.
     string parent = get_dirname(filename);
-    if (!parent.empty() && mkdir_complete(parent)) {
+    if (!parent.empty() && mkdir_complete(parent, logfile)) {
       // Parent successfully created.  Try again to make the file.
       file = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
                         FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
                         NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
     }
     if (file == INVALID_HANDLE_VALUE) {
+      logfile
+        << "Couldn't create " << filename << "\n";
       return false;
     }
   }
@@ -143,11 +151,13 @@ mkfile_complete(const string &filename) {
   if (fd == -1) {
     // Try to make the parent directory first.
     string parent = get_dirname(filename);
-    if (!parent.empty() && mkdir_complete(parent)) {
+    if (!parent.empty() && mkdir_complete(parent, logfile)) {
       // Parent successfully created.  Try again to make the file.
       fd = creat(filename.c_str(), 0777);
     }
     if (fd == -1) {
+      logfile
+        << "Couldn't create " << filename << ": " << strerror(errno) << "\n";
       return false;
     }
   }

+ 3 - 2
direct/src/plugin/mkdir_complete.h

@@ -16,10 +16,11 @@
 #define MKDIR_COMPLETE_H
 
 #include <string>
+#include <iostream>
 using namespace std;
 
-bool mkdir_complete(const string &dirname);
-bool mkfile_complete(const string &dirname);
+bool mkdir_complete(const string &dirname, ostream &logfile);
+bool mkfile_complete(const string &dirname, ostream &logfile);
 
 #endif
 

+ 1 - 2
direct/src/plugin/p3dFileDownload.cxx

@@ -46,8 +46,7 @@ set_filename(const string &filename) {
 ////////////////////////////////////////////////////////////////////
 bool P3DFileDownload::
 open_file() {
-  if (!mkfile_complete(_filename)) {
-    nout << "Unable to create " << _filename << "\n";
+  if (!mkfile_complete(_filename, nout)) {
     return false;
   }
   

+ 0 - 1
direct/src/plugin/p3dInstanceManager.cxx

@@ -22,7 +22,6 @@
 #include "p3dNoneObject.h"
 #include "p3dBoolObject.h"
 #include "find_root_dir.h"
-#include "mkdir_complete.h"
 
 #ifdef _WIN32
 #include <shlobj.h>

+ 1 - 2
direct/src/plugin/p3dMultifileReader.cxx

@@ -106,8 +106,7 @@ extract(const string &pathname, const string &to_dir,
     const Subfile &s = (*si);
 
     string output_pathname = to_dir + "/" + s._filename;
-    if (!mkfile_complete(output_pathname)) {
-      nout << "Unable to create " << output_pathname << "\n";
+    if (!mkfile_complete(output_pathname, nout)) {
       return false;
     }
 

+ 2 - 3
direct/src/plugin/p3dPackage.cxx

@@ -60,7 +60,7 @@ P3DPackage(const string &package_name, const string &package_version,
 
   // Ensure the package directory exists; create it if it does not.
   _package_dir += string("/") + _package_version;
-  mkdir_complete(_package_dir);
+  mkdir_complete(_package_dir, nout);
 
   _desc_file_basename = _package_fullname + ".xml";
   _desc_file_pathname = _package_dir + "/" + _desc_file_basename;
@@ -389,8 +389,7 @@ uncompress_archive() {
     return;
   }
 
-  if (!mkfile_complete(target_pathname)) {
-    nout << "Unable to create " << target_pathname << "\n";
+  if (!mkfile_complete(target_pathname, nout)) {
     report_done(false);
     return;
   }

+ 1 - 1
direct/src/plugin_npapi/ppInstance.cxx

@@ -862,7 +862,7 @@ downloaded_plugin(const string &filename) {
 
   // Copy the file onto the target.
   string pathname = _core_api_dll.get_pathname(_root_dir);
-  mkfile_complete(pathname);
+  mkfile_complete(pathname, nout);
 
   ifstream in(filename.c_str(), ios::in | ios::binary);
   ofstream out(pathname.c_str(), ios::out | ios::binary);

+ 2 - 1
direct/src/plugin_standalone/panda3d.cxx

@@ -299,7 +299,7 @@ get_plugin(const string &root_url, const string &this_platform, bool force_downl
   
   HTTPClient *http = HTTPClient::get_global_ptr();
   PT(HTTPChannel) channel = http->get_document(url);
-  Ramfile rf;
+  contents.make_dir();
   if (!channel->download_to_file(contents)) {
     cerr << "Unable to download " << url << "\n";
     return false;
@@ -370,6 +370,7 @@ get_core_api(const string &root_url, TiXmlElement *xpackage) {
     Filename pathname = Filename::from_os_specific(_core_api_dll.get_pathname(_root_dir));
     HTTPClient *http = HTTPClient::get_global_ptr();
     PT(HTTPChannel) channel = http->get_document(url);
+    pathname.make_dir();
     if (!channel->download_to_file(pathname)) {
       cerr << "Unable to download " << url << "\n";
       return false;