summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2008-04-15 13:29:16 +0000
committerVladimir Glazounov <vg@openoffice.org>2008-04-15 13:29:16 +0000
commit224a899e94c18c03febe6d7e9b86792c1efaaf60 (patch)
tree91a815b272061717d3d8bd25d895cb819af883e3 /sal
parentdf89f8bd5c4e3bace03c892a03eebe8203aed152 (diff)
INTEGRATION: CWS calcshare2 (1.17.26); FILE MERGED
2008/03/14 20:00:52 mav 1.17.26.1: #i85794# new file locking prototype
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/file.cxx63
1 files changed, 39 insertions, 24 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 5bf2f4097b2e..a22e80f5551a 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: file.cxx,v $
- * $Revision: 1.18 $
+ * $Revision: 1.19 $
*
* This file is part of OpenOffice.org.
*
@@ -173,6 +173,7 @@ typedef struct
{
rtl_uString* ustrFilePath; /* holds native file path */
int fd;
+ sal_Bool bLocked;
} oslFileHandleImpl;
@@ -550,6 +551,9 @@ oslFileHandle osl_createFileHandleFromFD( int fd )
pHandleImpl->ustrFilePath = NULL;
rtl_uString_new( &pHandleImpl->ustrFilePath );
pHandleImpl->fd = fd;
+
+ /* FIXME: it should be detected whether the file has been locked */
+ pHandleImpl->bLocked = sal_True;
}
}
@@ -655,31 +659,38 @@ oslFileError osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal
fd = open( buffer, flags, mode );
if ( fd >= 0 )
{
-#ifndef HAVE_O_EXLOCK
- /* check if file lock is enabled and clear l_type member of flock otherwise */
- if( (char *) -1 == pFileLockEnvVar )
+ sal_Bool bNeedsLock = ( ( uFlags & osl_File_OpenFlag_NoLock ) == 0 );
+ sal_Bool bLocked = sal_False;
+ if( bNeedsLock )
{
- /* FIXME: this is not MT safe */
- pFileLockEnvVar = getenv("SAL_ENABLE_FILE_LOCKING");
+#ifndef HAVE_O_EXLOCK
+ /* check if file lock is enabled and clear l_type member of flock otherwise */
+ if( (char *) -1 == pFileLockEnvVar )
+ {
+ /* FIXME: this is not MT safe */
+ pFileLockEnvVar = getenv("SAL_ENABLE_FILE_LOCKING");
- if( NULL == pFileLockEnvVar)
- pFileLockEnvVar = getenv("STAR_ENABLE_FILE_LOCKING");
- }
+ if( NULL == pFileLockEnvVar)
+ pFileLockEnvVar = getenv("STAR_ENABLE_FILE_LOCKING");
+ }
#else
- /* disable range based locking */
- pFileLockEnvVar = NULL;
+ /* disable range based locking */
+ pFileLockEnvVar = NULL;
- /* remove the NONBLOCK flag again */
- flags = fcntl(fd, F_GETFL, NULL);
- flags &= ~O_NONBLOCK;
- if( 0 > fcntl(fd, F_GETFL, flags) )
- return oslTranslateFileError(OSL_FET_ERROR, errno);
+ /* remove the NONBLOCK flag again */
+ flags = fcntl(fd, F_GETFL, NULL);
+ flags &= ~O_NONBLOCK;
+ if( 0 > fcntl(fd, F_GETFL, flags) )
+ return oslTranslateFileError(OSL_FET_ERROR, errno);
#endif
- if( NULL == pFileLockEnvVar )
- aflock.l_type = 0;
+ if( NULL == pFileLockEnvVar )
+ aflock.l_type = 0;
+
+ /* lock the file if flock.l_type is set */
+ bLocked = ( F_WRLCK != aflock.l_type || -1 != fcntl( fd, F_SETLK, &aflock ) );
+ }
- /* lock the file if flock.l_type is set */
- if( F_WRLCK != aflock.l_type || -1 != fcntl( fd, F_SETLK, &aflock ) )
+ if ( !bNeedsLock || bLocked )
{
/* allocate memory for impl structure */
pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) );
@@ -687,6 +698,7 @@ oslFileError osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal
{
pHandleImpl->ustrFilePath = ustrFilePath;
pHandleImpl->fd = fd;
+ pHandleImpl->bLocked = bLocked;
*pHandle = (oslFileHandle) pHandleImpl;
@@ -737,11 +749,14 @@ oslFileError osl_closeFile( oslFileHandle Handle )
aflock.l_start = 0;
aflock.l_len = 0;
- /* FIXME: check if file is really locked ? */
+ if ( pHandleImpl->bLocked )
+ {
+ /* FIXME: check if file is really locked ? */
- /* release the file share lock on this file */
- if( -1 == fcntl( pHandleImpl->fd, F_SETLK, &aflock ) )
- PERROR( "osl_closeFile", "unlock failed" );
+ /* release the file share lock on this file */
+ if( -1 == fcntl( pHandleImpl->fd, F_SETLK, &aflock ) )
+ PERROR( "osl_closeFile", "unlock failed" );
+ }
}
if( 0 > close( pHandleImpl->fd ) )