summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Glazunov <vg@openoffice.org>2009-12-15 12:36:38 +0100
committerVladimir Glazunov <vg@openoffice.org>2009-12-15 12:36:38 +0100
commit925fe19488f73b78df72f2721c5209213f25ecc4 (patch)
treefb9af9796404f530fcebdc0862b0d68680f428e3
parentd63780b2122551b9c8aa050e92af01a4d9090c88 (diff)
parent89455204e6c06511912fbd150e4abd4ff7986609 (diff)
CWS-TOOLING: integrate CWS fwk132_DEV300ooo/DEV300_m68
-rw-r--r--sal/osl/unx/file_misc.cxx114
-rw-r--r--sal/osl/unx/makefile.mk8
2 files changed, 70 insertions, 52 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index a04d4b4c9..29edab385 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -29,6 +29,7 @@
#include "osl/diagnose.h"
#include "osl/thread.h"
+#include <osl/signal.h>
#include "rtl/alloc.h"
#include "system.h"
@@ -48,6 +49,8 @@
#include <sys/stat.h>
#include <sys/mman.h>
+#include <algorithm>
+
/************************************************************************
* ToDo
*
@@ -1002,7 +1005,6 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
int SourceFileFD=0;
int DestFileFD=0;
int nRet=0;
- void* pSourceFile=0;
SourceFileFD=open(pszSourceFileName,O_RDONLY);
if ( SourceFileFD < 0 )
@@ -1010,7 +1012,19 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
nRet=errno;
return nRet;
}
-
+
+ // read and lseek are used to check the possibility to access the data
+ // not a nice solution, but it allows to avoid a crash in case it is an opened samba file
+ // generally, reading of one byte should not affect the performance
+ char nCh;
+ if ( 1 != read( SourceFileFD, &nCh, 1 )
+ || -1 == lseek( SourceFileFD, 0, SEEK_SET ) )
+ {
+ nRet = errno;
+ (void) close( SourceFileFD );
+ return nRet;
+ }
+
DestFileFD=open(pszDestFileName, O_WRONLY | O_CREAT, mode);
if ( DestFileFD < 0 )
@@ -1028,57 +1042,59 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
close(DestFileFD);
return 0;
}
-
- /* FIXME doCopy: fall back code for systems not having mmap */
- /* mmap file -- open dest file -- write once -- fsync it */
- pSourceFile=mmap(0,nSourceSize,PROT_READ,MAP_PRIVATE,SourceFileFD,0);
-
- if ( pSourceFile == MAP_FAILED )
+
+ size_t nWritten = 0;
+ size_t nRemains = nSourceSize;
+
+ /* mmap file -- open dest file -- write -- fsync it at the end */
+ void* pSourceFile = mmap( 0, nSourceSize, PROT_READ, MAP_SHARED, SourceFileFD, 0 );
+ if ( pSourceFile != MAP_FAILED )
+ {
+ nWritten = write( DestFileFD, pSourceFile, nSourceSize );
+ nRemains -= nWritten;
+ munmap( (char*)pSourceFile, nSourceSize );
+ }
+
+ if ( nRemains )
{
- /* it's important to set nRet before the hack
- otherwise errno may be changed by lstat */
- nRet = errno;
- close(SourceFileFD);
- close(DestFileFD);
-
- return nRet;
+ /* mmap has problems, try the direct streaming */
+ char pBuffer[32000];
+ size_t nRead = 0;
+
+ nRemains = nSourceSize;
+
+ if ( -1 != lseek( SourceFileFD, 0, SEEK_SET )
+ && -1 != lseek( DestFileFD, 0, SEEK_SET ) )
+ {
+ do
+ {
+ nRead = 0;
+ nWritten = 0;
+
+ size_t nToRead = std::min( (size_t)32000, nRemains );
+ nRead = read( SourceFileFD, pBuffer, nToRead );
+ if ( (size_t)-1 != nRead )
+ nWritten = write( DestFileFD, pBuffer, nRead );
+
+ if ( (size_t)-1 != nWritten )
+ nRemains -= nWritten;
+ }
+ while( nRemains && (size_t)-1 != nRead && nRead == nWritten );
+ }
}
- nRet = write(DestFileFD,pSourceFile,nSourceSize);
-
- /* #112584# if 'write' could not write the requested number of bytes
- we have to fail of course; because it's not exactly specified if 'write'
- sets errno if less than requested byte could be written we set nRet
- explicitly to ENOSPC */
- if ((nRet < 0) || (nRet != sal::static_int_cast< int >(nSourceSize)))
- {
- if (nRet < 0)
+ if ( nRemains )
+ {
+ if ( errno )
nRet = errno;
- else
+ else
nRet = ENOSPC;
-
- close(SourceFileFD);
- close(DestFileFD);
- munmap((char*)pSourceFile,nSourceSize);
- return nRet;
- }
-
- nRet = munmap((char*)pSourceFile,nSourceSize);
- if ( nRet < 0 )
- {
- nRet=errno;
- close(SourceFileFD);
- close(DestFileFD);
- return nRet;
}
-
- close(SourceFileFD);
-
- // Removed call to 'fsync' again (#112584#) and instead
- // evaluate the return value of 'close' in order to detect
- // and report ENOSPC and other erronous conditions on close
- if (close(DestFileFD) == -1)
- return errno;
- else
- return 0;
+
+ close( SourceFileFD );
+ if ( close( DestFileFD ) == -1 && nRet == 0 )
+ nRet = errno;
+
+ return nRet;
}
+
diff --git a/sal/osl/unx/makefile.mk b/sal/osl/unx/makefile.mk
index 0e728c29d..eac4c24cd 100644
--- a/sal/osl/unx/makefile.mk
+++ b/sal/osl/unx/makefile.mk
@@ -55,7 +55,8 @@ CXXFLAGS+= $(LFS_CFLAGS)
# --- Files --------------------------------------------------------
-SLOFILES= $(SLO)$/conditn.obj \
+SLOFILES= \
+ $(SLO)$/conditn.obj \
$(SLO)$/diagnose.obj \
$(SLO)$/semaphor.obj \
$(SLO)$/socket.obj \
@@ -74,7 +75,7 @@ SLOFILES= $(SLO)$/conditn.obj \
$(SLO)$/util.obj \
$(SLO)$/tempfile.obj\
$(SLO)$/file.obj \
- $(SLO)$/file_misc.obj \
+ $(SLO)$/file_misc.obj\
$(SLO)$/file_url.obj\
$(SLO)$/file_error_transl.obj\
$(SLO)$/file_path_helper.obj\
@@ -84,6 +85,7 @@ SLOFILES= $(SLO)$/conditn.obj \
$(SLO)$/process_impl.obj\
$(SLO)$/salinit.obj
+
#.IF "$(UPDATER)"=="YES"
OBJFILES= $(OBJ)$/conditn.obj \
$(OBJ)$/diagnose.obj \
@@ -104,7 +106,7 @@ OBJFILES= $(OBJ)$/conditn.obj \
$(OBJ)$/util.obj \
$(OBJ)$/tempfile.obj\
$(OBJ)$/file.obj \
- $(OBJ)$/file_misc.obj \
+ $(OBJ)$/file_misc.obj\
$(OBJ)$/file_url.obj\
$(OBJ)$/file_error_transl.obj\
$(OBJ)$/file_path_helper.obj\