[ooo-build-commit] Branch 'ooo/OOO320' - sal/osl

Jan Holesovsky kendy at kemper.freedesktop.org
Wed Dec 16 22:45:12 PST 2009


 sal/osl/unx/file_misc.cxx |  114 ++++++++++++++++++++++++++--------------------
 sal/osl/unx/makefile.mk   |    8 ++-
 2 files changed, 70 insertions(+), 52 deletions(-)

New commits:
commit 55a238362bbc33d02d016a9589652ac012eeebb0
Author: Oliver Bolte <obo at openoffice.org>
Date:   Mon Dec 14 11:14:52 2009 +0000

    CWS-TOOLING: integrate CWS fwk132
    2009-12-12 22:36:36 +0100 mav  r277797 : #i107638# in some case no transfer is expected
    2009-12-12 20:38:55 +0100 jsk  r277796 : fwk132: <no issue> Found coding error, corrected
    2009-12-12 02:22:18 +0100 mav  r277795 : #i104974# workaround linux smb-client problem, be ready for errors while using mmap
    2009-12-12 01:46:25 +0100 mav  r277794 : #i104974# workaround impossibility to copy opened file

diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index a04d4b4..29edab3 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 0e728c2..eac4c24 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\


More information about the ooo-build-commit mailing list