From 6c5032f3870489ff07100aff52ff2e0b75737901 Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Fri, 19 Nov 2010 10:50:56 +0100 Subject: fwk160: #i99833# do not use ftruncate unnecessarily --- ucb/source/ucp/file/shell.cxx | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'ucb') diff --git a/ucb/source/ucp/file/shell.cxx b/ucb/source/ucp/file/shell.cxx index c0ce3bebad..52f88a4807 100644 --- a/ucb/source/ucp/file/shell.cxx +++ b/ucb/source/ucp/file/shell.cxx @@ -1805,14 +1805,26 @@ shell::write( sal_Int32 CommandId, { aFile.close(); err = aFile.open( OpenFlag_Write ); - } - if( err != osl::FileBase::E_None ) - { - installError( CommandId, - TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE, - err ); - return sal_False; + if( err != osl::FileBase::E_None ) + { + installError( CommandId, + TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE, + err ); + return sal_False; + } + + // the existing file was just opened and should be overwritten now, + // truncate it first + + err = aFile.setSize( 0 ); + if( err != osl::FileBase::E_None ) + { + installError( CommandId, + TASKHANDLING_FILESIZE_FOR_WRITE, + err ); + return sal_False; + } } } else @@ -1844,7 +1856,6 @@ shell::write( sal_Int32 CommandId, sal_Bool bSuccess = sal_True; - sal_uInt64 nTotalNumberOfBytes = 0; sal_uInt64 nWrittenBytes; sal_Int32 nReadBytes = 0, nRequestedBytes = 32768 /*32k*/; uno::Sequence< sal_Int8 > seq( nRequestedBytes ); @@ -1901,20 +1912,9 @@ shell::write( sal_Int32 CommandId, bSuccess = sal_False; break; } - - nTotalNumberOfBytes += nWrittenBytes; } } while( nReadBytes == nRequestedBytes ); - err = aFile.setSize( nTotalNumberOfBytes ); - if( err != osl::FileBase::E_None ) - { - installError( CommandId, - TASKHANDLING_FILESIZE_FOR_WRITE, - err ); - bSuccess = sal_False; - } - err = aFile.close(); if( err != osl::FileBase::E_None ) { -- cgit v1.2.3