Changeset 924

Show
Ignore:
Timestamp:
08/05/08 15:41:53
Author:
robert
Message:

Added permission check and error logging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/vpb/FileUtils

    r903 r924  
    5050#endif 
    5151 
     52#include <string> 
     53 
    5254namespace vpb 
    5355{ 
     
    7577extern VPB_EXPORT int mkpath(const char *path, int mode); 
    7678 
     79extern VPB_EXPORT bool hasWritePermission(const std::string& filename); 
     80 
    7781}; 
  • trunk/src/vpb/DataSet.cpp

    r908 r924  
    14761476 
    14771477    if (_archive.valid()) _archive->writeNode(node,filename); 
    1478     else osgDB::writeNodeFile(node, filename); 
     1478    else  
     1479    { 
     1480        if (vpb::hasWritePermission(filename)) 
     1481        { 
     1482            osgDB::ReaderWriter::WriteResult result =  
     1483                osgDB::Registry::instance()->writeNode(node, filename,osgDB::Registry::instance()->getOptions()); 
     1484                 
     1485            if (!result.success()) 
     1486            { 
     1487                log(osg::WARN, "Error: error occurred when writing out file %s",filename.c_str()); 
     1488            } 
     1489        } 
     1490        else 
     1491        { 
     1492            log(osg::WARN, "Error: do not have write permission to write out file %s",filename.c_str()); 
     1493        } 
     1494    } 
    14791495} 
    14801496 
     
    14841500 
    14851501    if (_archive.valid()) _archive->writeImage(image,filename); 
    1486     else osgDB::writeImageFile(image, filename); 
     1502    else  
     1503    { 
     1504        if (vpb::hasWritePermission(filename)) 
     1505        { 
     1506            osgDB::ReaderWriter::WriteResult result =  
     1507                osgDB::Registry::instance()->writeImage(image, filename,osgDB::Registry::instance()->getOptions()); 
     1508                 
     1509            if (!result.success()) 
     1510            { 
     1511                log(osg::WARN, "Error: error occurred when writing out file %s",filename.c_str()); 
     1512            } 
     1513        } 
     1514        else 
     1515        { 
     1516            log(osg::WARN, "Error: do not have write permission to write out file %s",filename.c_str()); 
     1517        } 
     1518    } 
    14871519} 
    14881520 
     
    28792911        if (result) 
    28802912        { 
    2881             log(osg::NOTICE,"Error: could not create directory %i",errno); 
     2913            log(osg::NOTICE,"Error: could not create directory, errorno=%i",errno); 
    28822914            return 1; 
    28832915        } 
     
    29072939            if (result) 
    29082940            { 
    2909                 log(osg::NOTICE,"Error: could not create directory %i",errno); 
     2941                log(osg::NOTICE,"Error: could not create directory, errorno=%i",errno); 
    29102942                return 1; 
    29112943            } 
  • trunk/src/vpb/DatabaseBuilderIO.cpp

    r694 r924  
    9090{ 
    9191    public: 
     92     
     93        VPBReaderWriter() 
     94        { 
     95            supportsExtension("vpb","VirtualPlanetBuilder source format"); 
     96            supportsExtension("source","VirtualPlanetBuilder source format"); 
     97        } 
     98         
    9299        virtual const char* className() const { return "VPB Reader/Writer"; } 
    93100 
  • trunk/src/vpb/FileUtils.cpp

    r920 r924  
    22#include <vpb/BuildLog> 
    33#include <osgDB/FileUtils> 
     4#include <osgDB/FileNameUtils> 
    45 
    56#ifdef WIN32 
     
    138139     
    139140} 
     141 
     142bool vpb::hasWritePermission(const std::string& filename) 
     143{ 
     144    log(osg::NOTICE,"vpb::access(%s, W_OK)=%i",filename.c_str(), vpb::access(filename.c_str(), W_OK)); 
     145 
     146    if (vpb::access(filename.c_str(), W_OK)==0) return true; 
     147 
     148    std::string path = osgDB::getFilePath(filename); 
     149    if (path.empty()) path = "."; 
     150     
     151    log(osg::NOTICE,"vpb::access(%s, W_OK)=%i",path.c_str(), vpb::access(path.c_str(), W_OK)); 
     152 
     153    return (vpb::access(path.c_str(), W_OK)==0); 
     154} 
     155