Changeset 860
- Timestamp:
- 01/26/08 13:25:16
- Files:
-
- trunk/include/vpb/FileUtils (modified) (1 diff)
- trunk/src/vpb/DataSet.cpp (modified) (3 diffs)
- trunk/src/vpb/FileUtils.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/include/vpb/FileUtils
r858 r860 65 65 extern VPB_EXPORT int gethostname(char *name, size_t namelen); 66 66 extern VPB_EXPORT int getdtablesize(); 67 extern VPB_EXPORT int mkdir(const char *__path, int mode); 67 extern VPB_EXPORT int mkdir(const char *path, int mode); 68 69 extern VPB_EXPORT int mkpath(const char *path, int mode); 68 70 69 71 }; trunk/src/vpb/DataSet.cpp
r859 r860 35 35 #include <vpb/TaskManager> 36 36 #include <vpb/System> 37 #include <vpb/FileUtils> 37 38 38 39 #include <vpb/ShapeFilePlacer> … … 2790 2791 } 2791 2792 } 2792 2793 2794 int result = 0; 2795 osgDB::FileType type = osgDB::fileType(getDirectory()); 2796 if (type==osgDB::DIRECTORY) 2797 { 2798 log(osg::NOTICE," Base Directory already created"); 2799 } 2800 else if (type==osgDB::REGULAR_FILE) 2801 { 2802 log(osg::NOTICE," Error cannot create directory as a conventional file already exists with that name"); 2803 return 1; 2804 } 2805 else // FILE_NOT_FOUND 2806 { 2807 // need to create directory. 2808 result = vpb::mkpath(getDirectory().c_str(), S_IRWXU | S_IRWXG | S_IRWXO); 2809 } 2810 2811 if (result) 2812 { 2813 log(osg::NOTICE,"Error: could not create directory %i",errno); 2814 return 1; 2815 } 2816 2817 2793 2818 if (getOutputTaskDirectories()) 2794 2819 { 2795 2820 _taskOutputDirectory = getDirectory() + getTaskName(getSubtileLevel(), getSubtileX(), getSubtileY()); 2796 2821 log(osg::NOTICE,"Need to create output task directory = %s", _taskOutputDirectory.c_str()); 2797 intresult = 0;2798 osgDB::FileTypetype = osgDB::fileType(_taskOutputDirectory);2822 result = 0; 2823 type = osgDB::fileType(_taskOutputDirectory); 2799 2824 if (type==osgDB::DIRECTORY) 2800 2825 { … … 2804 2829 { 2805 2830 log(osg::NOTICE," Error cannot create directory as a conventional file already exists with that name"); 2806 re sult =1;2831 return 1; 2807 2832 } 2808 2833 else // FILE_NOT_FOUND 2809 2834 { 2810 2835 // need to create directory. 2811 result = mkdir(_taskOutputDirectory.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);2836 result = vpb::mkpath(_taskOutputDirectory.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); 2812 2837 } 2813 2838 trunk/src/vpb/FileUtils.cpp
r858 r860 1 1 #include <vpb/FileUtils> 2 #include <vpb/BuildLog> 3 #include <osgDB/FileUtils> 2 4 3 5 #ifdef WIN32 … … 62 64 63 65 #endif // WIN32 66 67 68 int vpb::mkpath(const char *path, int mode) 69 { 70 if (path==0) return 0; 71 72 std::string fullpath(path); 73 typedef std::list<std::string> Directories; 74 Directories directories; 75 int pos_start = 0; 76 for(int pos_current = 0; pos_current<fullpath.size(); ++pos_current) 77 { 78 if (fullpath[pos_current]=='\\' || fullpath[pos_current]=='/') 79 { 80 int size = pos_current-pos_start; 81 if (size>1) 82 { 83 directories.push_back(std::string(fullpath,0, pos_current)); 84 } 85 pos_start = pos_current+1; 86 } 87 } 88 int size = fullpath.size()-pos_start; 89 if (size>1) 90 { 91 directories.push_back(fullpath); 92 } 93 94 vpb::log(osg::NOTICE,"mkpath(%s)",path); 95 for(Directories::iterator itr = directories.begin(); 96 itr != directories.end(); 97 ++itr) 98 { 99 vpb::log(osg::NOTICE," directory %s",(*itr).c_str()); 100 101 int result = 0; 102 osgDB::FileType type = osgDB::fileType((*itr)); 103 if (type==osgDB::DIRECTORY) 104 { 105 log(osg::NOTICE," Base Directory already created"); 106 } 107 else if (type==osgDB::REGULAR_FILE) 108 { 109 log(osg::NOTICE," Error cannot create directory as a conventional file already exists with that name"); 110 return 1; 111 } 112 else // FILE_NOT_FOUND 113 { 114 // need to create directory. 115 result = vpb::mkdir((*itr).c_str(), mode); 116 if (result) return result; 117 } 118 } 119 120 return 0; 121 122 }
