Browse Source

*** empty log message ***

Mike Goslin 25 years ago
parent
commit
8ff24f8f4f

+ 25 - 0
dtool/src/dtoolutil/filename.cxx

@@ -810,6 +810,31 @@ rename_to(const Filename &other) const {
 		 other.to_os_specific().c_str()) == 0);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::mkdir
+//       Access: Public
+//  Description: Creates all the directories in the path to the file
+//		 specified in the filename (useful for writing).
+////////////////////////////////////////////////////////////////////
+bool Filename::
+make_dir() const {
+  size_t p = 0;
+  while (p < _filename.length()) {
+    size_t slash = _filename.find('/', p);
+    if (slash != string::npos) {
+      string component = _filename.substr(0, slash);
+      if (!(component == ".") || 
+          !(component == "..")) {
+        mkdir(component.c_str(), 0xffff);
+      }
+    }
+    p = slash;
+    while (p < _filename.length() && _filename[p] == '/')
+      p++;
+  }
+  return true;
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Filename::locate_basename

+ 2 - 0
dtool/src/dtoolutil/filename.h

@@ -134,6 +134,8 @@ public:
   bool unlink() const;
   bool rename_to(const Filename &other) const;
 
+  bool make_dir() const;
+
   // Comparison operators are handy.
   INLINE bool operator == (const string &other) const;
   INLINE bool operator != (const string &other) const;

+ 2 - 0
panda/src/express/multifile.cxx

@@ -236,6 +236,7 @@ bool Multifile::Memfile::
 write(void) {
   ofstream write_stream;
   _name.set_binary();
+  _name.make_dir();
   if (!_name.open_write(write_stream)) {
     express_cat.error()
       << "Multifile::Memfile::write() - Failed to open output file: "
@@ -287,6 +288,7 @@ write(char *&start, int &size) {
   // Try to open the file for writing
   if (_file_open == false) {
     _name.set_binary();
+    _name.make_dir();
     if ((_file_open = _name.open_write(_write_stream)) == false) {
       express_cat.error()
         << "Multfile::Memfile::write() - Couldn't open file: "