[Box Backup-commit] COMMIT r3065 - box/trunk/lib/common

subversion at boxbackup.org subversion at boxbackup.org
Sun Jan 22 16:28:01 GMT 2012


Author: chris
Date: 2012-01-22 16:28:01 +0000 (Sun, 22 Jan 2012)
New Revision: 3065

Modified:
   box/trunk/lib/common/FileStream.cpp
Log:
Log messages on failure to read, write, stat, seek and close files, with the filename.


Modified: box/trunk/lib/common/FileStream.cpp
===================================================================
--- box/trunk/lib/common/FileStream.cpp	2012-01-22 16:26:38 UTC (rev 3064)
+++ box/trunk/lib/common/FileStream.cpp	2012-01-22 16:28:01 UTC (rev 3065)
@@ -190,22 +190,23 @@
 	}
 	else
 	{
-		BOX_LOG_WIN_ERROR("Failed to read from file: " << mFileName);
-		r = -1;
+		THROW_WIN_FILE_ERROR("Failed to read from file", mFileName,
+			CommonException, OSFileReadError);
 	}
+
+	if(r == -1)
+	{
+		THROW_EXCEPTION(CommonException, OSFileReadError)
+	}
 #else
 	int r = ::read(mOSFileHandle, pBuffer, NBytes);
 	if(r == -1)
 	{
-		BOX_LOG_SYS_ERROR("Failed to read from file: " << mFileName);
+		THROW_SYS_FILE_ERROR("Failed to read from file", mFileName,
+			CommonException, OSFileReadError);
 	}
 #endif
 
-	if(r == -1)
-	{
-		THROW_EXCEPTION(CommonException, OSFileReadError)
-	}
-
 	if(r == 0)
 	{
 		mIsEOF = true;
@@ -228,7 +229,7 @@
 	EMU_STRUCT_STAT st;
 	if(EMU_FSTAT(mOSFileHandle, &st) != 0)
 	{
-		THROW_EXCEPTION(CommonException, OSFileError)
+		BOX_LOG_SYS_ERROR(BOX_FILE_MESSAGE("Failed to stat file", mFileName));
 	}
 	
 	return st.st_size - GetPosition();
@@ -262,14 +263,14 @@
 
 	if ((res == 0) || (numBytesWritten != (DWORD)NBytes))
 	{
-		// DWORD err = GetLastError();
-		THROW_EXCEPTION(CommonException, OSFileWriteError)
+		THROW_WIN_FILE_ERROR("Failed to write to file", mFileName,
+			CommonException, OSFileWriteError);
 	}
 #else
 	if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes)
 	{
-		BOX_LOG_SYS_ERROR("Failed to write to file: " << mFileName);
-		THROW_EXCEPTION(CommonException, OSFileWriteError)
+		THROW_SYS_FILE_ERROR("Failed to write to file", mFileName,
+			CommonException, OSFileWriteError);
 	}
 #endif
 }
@@ -292,18 +293,22 @@
 
 #ifdef WIN32
 	LARGE_INTEGER conv;
-
 	conv.HighPart = 0;
-	conv.LowPart = 0;
-
 	conv.LowPart = SetFilePointer(this->mOSFileHandle, 0, &conv.HighPart, FILE_CURRENT);
 
+	if(conv.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
+	{
+		THROW_WIN_FILE_ERROR("Failed to seek in file", mFileName,
+			CommonException, OSFileError);
+	}
+
 	return (IOStream::pos_type)conv.QuadPart;
 #else // ! WIN32
 	off_t p = ::lseek(mOSFileHandle, 0, SEEK_CUR);
 	if(p == -1)
 	{
-		THROW_EXCEPTION(CommonException, OSFileError)
+		THROW_SYS_FILE_ERROR("Failed to seek in file", mFileName,
+			CommonException, OSFileError);
 	}
 	
 	return (IOStream::pos_type)p;
@@ -328,18 +333,19 @@
 
 #ifdef WIN32
 	LARGE_INTEGER conv;
-
 	conv.QuadPart = Offset;
 	DWORD retVal = SetFilePointer(this->mOSFileHandle, conv.LowPart, &conv.HighPart, ConvertSeekTypeToOSWhence(SeekType));
 
 	if(retVal == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
 	{
-		THROW_EXCEPTION(CommonException, OSFileError)
+		THROW_WIN_FILE_ERROR("Failed to seek in file", mFileName,
+			CommonException, OSFileError);
 	}
 #else // ! WIN32
 	if(::lseek(mOSFileHandle, Offset, ConvertSeekTypeToOSWhence(SeekType)) == -1)
 	{
-		THROW_EXCEPTION(CommonException, OSFileError)
+		THROW_SYS_FILE_ERROR("Failed to seek in file", mFileName,
+			CommonException, OSFileError);
 	}
 #endif // WIN32
 
@@ -365,12 +371,17 @@
 
 #ifdef WIN32
 	if(::CloseHandle(mOSFileHandle) == 0)
-#else
+	{
+		THROW_WIN_FILE_ERROR("Failed to close file", mFileName,
+			CommonException, OSFileCloseError);
+	}
+#else // ! WIN32
 	if(::close(mOSFileHandle) != 0)
-#endif
 	{
-		THROW_EXCEPTION(CommonException, OSFileCloseError)
+		THROW_SYS_FILE_ERROR("Failed to close file", mFileName,
+			CommonException, OSFileCloseError);
 	}
+#endif // WIN32
 
 	mOSFileHandle = INVALID_FILE;
 	mIsEOF = true;




More information about the Boxbackup-commit mailing list