Changeset 14218

Show
Ignore:
Timestamp:
04/07/08 12:46:38 (3 months ago)
Author:
warmerdam
Message:

added path normalization so everything is converted to forward slashes (#2318)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/port/cpl_vsi_mem.cpp

    r13644 r14218  
    139139    virtual int      Rmdir( const char *pszDirname ); 
    140140    virtual char   **ReadDir( const char *pszDirname ); 
     141    static  void     NormalizePath( CPLString & ); 
    141142}; 
    142143 
     
    372373    CPLMutexHolder oHolder( &hMutex ); 
    373374    VSIMemFile *poFile; 
     375    CPLString osFilename = pszFilename; 
     376    NormalizePath( osFilename ); 
    374377 
    375378/* -------------------------------------------------------------------- */ 
    376379/*      Get the filename we are opening, create if needed.              */ 
    377380/* -------------------------------------------------------------------- */ 
    378     if( oFileList.find(pszFilename) == oFileList.end() ) 
     381    if( oFileList.find(osFilename) == oFileList.end() ) 
    379382        poFile = NULL; 
    380383    else 
    381         poFile = oFileList[pszFilename]; 
     384        poFile = oFileList[osFilename]; 
    382385 
    383386    if( strstr(pszAccess,"w") == NULL && poFile == NULL ) 
     
    394397        { 
    395398            poFile = new VSIMemFile; 
    396             poFile->osFilename = pszFilename; 
     399            poFile->osFilename = osFilename; 
    397400            oFileList[poFile->osFilename] = poFile; 
    398401            poFile->nRefCount++; // for file list 
     
    432435    CPLMutexHolder oHolder( &hMutex ); 
    433436 
    434     if( oFileList.find(pszFilename) == oFileList.end() ) 
     437    CPLString osFilename = pszFilename; 
     438    NormalizePath( osFilename ); 
     439 
     440    if( oFileList.find(osFilename) == oFileList.end() ) 
    435441    { 
    436442        errno = ENOENT; 
     
    438444    } 
    439445 
    440     VSIMemFile *poFile = oFileList[pszFilename]; 
     446    VSIMemFile *poFile = oFileList[osFilename]; 
    441447 
    442448    memset( pStatBuf, 0, sizeof(VSIStatBufL) ); 
     
    465471    CPLMutexHolder oHolder( &hMutex ); 
    466472 
     473    CPLString osFilename = pszFilename; 
     474    NormalizePath( osFilename ); 
     475 
    467476    VSIMemFile *poFile; 
    468477 
    469     if( oFileList.find(pszFilename) == oFileList.end() ) 
     478    if( oFileList.find(osFilename) == oFileList.end() ) 
    470479    { 
    471480        errno = ENOENT; 
     
    474483    else 
    475484    { 
    476         poFile = oFileList[pszFilename]; 
     485        poFile = oFileList[osFilename]; 
    477486 
    478487        if( --(poFile->nRefCount) == 0 ) 
    479488            delete poFile; 
    480489 
    481         oFileList.erase( oFileList.find(pszFilename) ); 
     490        oFileList.erase( oFileList.find(osFilename) ); 
    482491 
    483492        return 0; 
     
    495504    CPLMutexHolder oHolder( &hMutex ); 
    496505 
    497     if( oFileList.find(pszPathname) != oFileList.end() ) 
     506    CPLString osPathname = pszPathname; 
     507 
     508    NormalizePath( osPathname ); 
     509 
     510    if( oFileList.find(osPathname) != oFileList.end() ) 
    498511    { 
    499512        errno = EEXIST; 
     
    503516    VSIMemFile *poFile = new VSIMemFile; 
    504517 
    505     poFile->osFilename = pszPathname; 
     518    poFile->osFilename = osPathname; 
    506519    poFile->bIsDirectory = TRUE; 
    507     oFileList[pszPathname] = poFile; 
     520    oFileList[osPathname] = poFile; 
    508521    poFile->nRefCount++; /* referenced by file list */ 
    509522 
     
    531544{ 
    532545    CPLMutexHolder oHolder( &hMutex ); 
     546 
     547    CPLString osPath = pszPath; 
     548 
     549    NormalizePath( osPath ); 
    533550 
    534551    std::map<CPLString,VSIMemFile*>::const_iterator iter; 
    535552    char **papszDir = NULL; 
    536     int nPathLen = strlen(pszPath); 
    537  
    538     if( pszPath[nPathLen-1] == '/' ) 
     553    int nPathLen = strlen(osPath); 
     554 
     555    if( osPath[nPathLen-1] == '/' ) 
    539556        nPathLen--; 
    540557 
     
    547564    { 
    548565        const char *pszFilePath = iter->second->osFilename.c_str(); 
    549         if( EQUALN(pszPath,pszFilePath,nPathLen) 
     566        if( EQUALN(osPath,pszFilePath,nPathLen) 
    550567            && pszFilePath[nPathLen] == '/'  
    551568            && strstr(pszFilePath+nPathLen+1,"/") == NULL ) 
     
    574591 
    575592/************************************************************************/ 
     593/*                      NormalizePath()                                 */ 
     594/************************************************************************/ 
     595 
     596void VSIMemFilesystemHandler::NormalizePath( CPLString &oPath ) 
     597 
     598{ 
     599    int  i, nSize = oPath.size(); 
     600 
     601    for( i = 0; i < nSize; i++ ) 
     602    { 
     603        if( oPath[i] == '\\' ) 
     604            oPath[i] = '/'; 
     605    } 
     606 
     607} 
     608 
     609/************************************************************************/ 
    576610/*                     VSIInstallLargeFileHandler()                     */ 
    577611/************************************************************************/