Changeset 3065 for box/trunk/lib


Ignore:
Timestamp:
22/01/2012 16:28:01 (4 months ago)
Author:
chris
Message:

Log messages on failure to read, write, stat, seek and close files, with the filename.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/FileStream.cpp

    r2808 r3065  
    191191        else 
    192192        { 
    193                 BOX_LOG_WIN_ERROR("Failed to read from file: " << mFileName); 
    194                 r = -1; 
     193                THROW_WIN_FILE_ERROR("Failed to read from file", mFileName, 
     194                        CommonException, OSFileReadError); 
     195        } 
     196 
     197        if(r == -1) 
     198        { 
     199                THROW_EXCEPTION(CommonException, OSFileReadError) 
    195200        } 
    196201#else 
     
    198203        if(r == -1) 
    199204        { 
    200                 BOX_LOG_SYS_ERROR("Failed to read from file: " << mFileName); 
    201         } 
    202 #endif 
    203  
    204         if(r == -1) 
    205         { 
    206                 THROW_EXCEPTION(CommonException, OSFileReadError) 
    207         } 
     205                THROW_SYS_FILE_ERROR("Failed to read from file", mFileName, 
     206                        CommonException, OSFileReadError); 
     207        } 
     208#endif 
    208209 
    209210        if(r == 0) 
     
    229230        if(EMU_FSTAT(mOSFileHandle, &st) != 0) 
    230231        { 
    231                 THROW_EXCEPTION(CommonException, OSFileError) 
     232                BOX_LOG_SYS_ERROR(BOX_FILE_MESSAGE("Failed to stat file", mFileName)); 
    232233        } 
    233234         
     
    263264        if ((res == 0) || (numBytesWritten != (DWORD)NBytes)) 
    264265        { 
    265                 // DWORD err = GetLastError(); 
    266                 THROW_EXCEPTION(CommonException, OSFileWriteError) 
     266                THROW_WIN_FILE_ERROR("Failed to write to file", mFileName, 
     267                        CommonException, OSFileWriteError); 
    267268        } 
    268269#else 
    269270        if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes) 
    270271        { 
    271                 BOX_LOG_SYS_ERROR("Failed to write to file: " << mFileName); 
    272                 THROW_EXCEPTION(CommonException, OSFileWriteError) 
     272                THROW_SYS_FILE_ERROR("Failed to write to file", mFileName, 
     273                        CommonException, OSFileWriteError); 
    273274        } 
    274275#endif 
     
    293294#ifdef WIN32 
    294295        LARGE_INTEGER conv; 
    295  
    296296        conv.HighPart = 0; 
    297         conv.LowPart = 0; 
    298  
    299297        conv.LowPart = SetFilePointer(this->mOSFileHandle, 0, &conv.HighPart, FILE_CURRENT); 
     298 
     299        if(conv.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) 
     300        { 
     301                THROW_WIN_FILE_ERROR("Failed to seek in file", mFileName, 
     302                        CommonException, OSFileError); 
     303        } 
    300304 
    301305        return (IOStream::pos_type)conv.QuadPart; 
     
    304308        if(p == -1) 
    305309        { 
    306                 THROW_EXCEPTION(CommonException, OSFileError) 
     310                THROW_SYS_FILE_ERROR("Failed to seek in file", mFileName, 
     311                        CommonException, OSFileError); 
    307312        } 
    308313         
     
    329334#ifdef WIN32 
    330335        LARGE_INTEGER conv; 
    331  
    332336        conv.QuadPart = Offset; 
    333337        DWORD retVal = SetFilePointer(this->mOSFileHandle, conv.LowPart, &conv.HighPart, ConvertSeekTypeToOSWhence(SeekType)); 
     
    335339        if(retVal == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) 
    336340        { 
    337                 THROW_EXCEPTION(CommonException, OSFileError) 
     341                THROW_WIN_FILE_ERROR("Failed to seek in file", mFileName, 
     342                        CommonException, OSFileError); 
    338343        } 
    339344#else // ! WIN32 
    340345        if(::lseek(mOSFileHandle, Offset, ConvertSeekTypeToOSWhence(SeekType)) == -1) 
    341346        { 
    342                 THROW_EXCEPTION(CommonException, OSFileError) 
     347                THROW_SYS_FILE_ERROR("Failed to seek in file", mFileName, 
     348                        CommonException, OSFileError); 
    343349        } 
    344350#endif // WIN32 
     
    366372#ifdef WIN32 
    367373        if(::CloseHandle(mOSFileHandle) == 0) 
    368 #else 
     374        { 
     375                THROW_WIN_FILE_ERROR("Failed to close file", mFileName, 
     376                        CommonException, OSFileCloseError); 
     377        } 
     378#else // ! WIN32 
    369379        if(::close(mOSFileHandle) != 0) 
    370 #endif 
    371         { 
    372                 THROW_EXCEPTION(CommonException, OSFileCloseError) 
    373         } 
     380        { 
     381                THROW_SYS_FILE_ERROR("Failed to close file", mFileName, 
     382                        CommonException, OSFileCloseError); 
     383        } 
     384#endif // WIN32 
    374385 
    375386        mOSFileHandle = INVALID_FILE; 
Note: See TracChangeset for help on using the changeset viewer.