summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2012-01-19 12:23:23 +0000
committerMichael Meeks <michael.meeks@suse.com>2012-01-19 12:25:02 +0000
commit4a086fca7b0a77c20bc9f1c97507966e2861f3da (patch)
treea065ccbf7fd0adb66c4e335d181056f27f52512a
parent755f299eccee79aa91ce6d935b85d2b00fe74974 (diff)
fix SvStream to not require a custom open or lstat method.
-rw-r--r--sal/inc/osl/detail/file.h12
-rw-r--r--sal/inc/osl/file.h1
-rw-r--r--sal/osl/unx/file.cxx2
-rw-r--r--sal/osl/unx/file_stat.cxx12
-rw-r--r--sal/util/sal.map2
-rw-r--r--tools/inc/tools/stream.hxx4
-rw-r--r--tools/source/stream/strmunx.cxx71
7 files changed, 38 insertions, 66 deletions
diff --git a/sal/inc/osl/detail/file.h b/sal/inc/osl/detail/file.h
index 108d2306b36d..065c3551b108 100644
--- a/sal/inc/osl/detail/file.h
+++ b/sal/inc/osl/detail/file.h
@@ -49,25 +49,13 @@ extern "C" {
#define osl_File_OpenFlag_Trunc 0x00000010L
#define osl_File_OpenFlag_NoExcl 0x00000020L
-/* Variant of osl_openFile that takes the file pathname directly as a
- char*
-*/
-
-SAL_DLLPUBLIC oslFileError SAL_CALL osl_openFilePath(
- const char *cpFilePath,
- oslFileHandle *pHandle,
- sal_uInt32 uFlags );
-
/* Compare directory items for being the same underlying file
* this unwinds unix hard-links and symlinks etc.
*/
SAL_DLLPUBLIC sal_Bool SAL_CALL osl_identicalDirectoryItem(oslDirectory a, oslDirectory b);
-SAL_DLLPUBLIC oslFileError SAL_CALL osl_lstatFilePath( const char *cpFilePath, struct stat *statb );
-
/* Get the OS specific "handle" of an open file. */
-
SAL_DLLPUBLIC oslFileError SAL_CALL osl_getFileOSHandle(
oslFileHandle Handle,
sal_IntPtr *piFileHandle );
diff --git a/sal/inc/osl/file.h b/sal/inc/osl/file.h
index 2a8cf378330b..0e0d7657679c 100644
--- a/sal/inc/osl/file.h
+++ b/sal/inc/osl/file.h
@@ -664,6 +664,7 @@ typedef void *oslFileHandle;
#define osl_File_OpenFlag_Write 0x00000002L
#define osl_File_OpenFlag_Create 0x00000004L
#define osl_File_OpenFlag_NoLock 0x00000008L
+/* larger bit-fields reserved for internal use cf. detail/file.h */
/** Open a regular file.
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 64ce977d960e..7bb6bae051f1 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -892,7 +892,7 @@ SAL_CALL osl_openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandl
#define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR )
#endif
-oslFileError
+static oslFileError
SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags )
{
oslFileError eRet;
diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx
index 0477a52e555a..320744fc0357 100644
--- a/sal/osl/unx/file_stat.cxx
+++ b/sal/osl/unx/file_stat.cxx
@@ -462,7 +462,6 @@ SAL_CALL osl_identicalDirectoryItem( oslDirectoryItem a, oslDirectoryItem b)
return sal_True;
fprintf (stderr, "We have to do an inode compare !\n");
-
/*
int rc = stat_c( cpFilePath, statb );
@@ -475,15 +474,4 @@ SAL_CALL osl_identicalDirectoryItem( oslDirectoryItem a, oslDirectoryItem b)
return sal_False;
}
-oslFileError
-SAL_CALL osl_lstatFilePath( const char *cpFilePath, struct stat *statb )
-{
- int rc = lstat_c( cpFilePath, statb );
-
- if (rc == -1)
- return oslTranslateFileError(OSL_FET_ERROR, errno);
- else
- return osl_File_E_None;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 26c30fc03191..02610f554bd2 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -647,9 +647,7 @@ PRIVATE_textenc.1 { # LibreOffice 3.6
PRIVATE_file.1 { # LibreOffice 3.6
global:
- osl_openFilePath;
osl_identicalDirectoryItem;
- osl_lstatFilePath;
osl_getFileOSHandle;
};
diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx
index 37b7c3f96ab7..8c7fa0c58e44 100644
--- a/tools/inc/tools/stream.hxx
+++ b/tools/inc/tools/stream.hxx
@@ -576,10 +576,10 @@ class TOOLS_DLLPUBLIC SvFileStream : public SvStream
friend class FileCopier;
private:
- StreamData* pInstanceData;
+ StreamData* pInstanceData;
String aFilename;
sal_uInt16 nLockCounter;
- sal_Bool bIsOpen;
+ sal_Bool bIsOpen;
sal_uInt32 GetFileHandle() const;
// Forbidden and not implemented.
diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx
index 0fcddbd09db3..d2135fa58e34 100644
--- a/tools/source/stream/strmunx.cxx
+++ b/tools/source/stream/strmunx.cxx
@@ -223,7 +223,7 @@ class StreamData
public:
oslFileHandle rHandle;
- StreamData() { }
+ StreamData() : rHandle( 0 ) { }
};
// -----------------------------------------------------------------------
@@ -683,8 +683,6 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode )
{
sal_uInt32 uFlags;
oslFileHandle nHandleTmp;
- struct stat buf;
- sal_Bool bStatValid = sal_False;
Close();
errno = 0;
@@ -707,16 +705,22 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode )
OSL_TRACE( "%s", aTraceStr.getStr() );
#endif
- if ( osl_lstatFilePath( aLocalFilename.getStr(), &buf ) == osl_File_E_None )
- {
- bStatValid = sal_True;
- // SvFileStream soll kein Directory oeffnen
- if( S_ISDIR( buf.st_mode ) )
- {
- SetError( ::GetSvError( EISDIR ) );
- return;
- }
- }
+ rtl::OUString aFileURL;
+ osl::DirectoryItem aItem;
+ osl::FileStatus aStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_LinkTargetURL );
+
+ // FIXME: we really need to switch to a pure URL model ...
+ if ( osl::File::getFileURLFromSystemPath( aFilename, aFileURL ) != osl::FileBase::RC::E_None )
+ aFileURL = aFilename;
+ bool bStatValid = ( osl::DirectoryItem::get( aFileURL, aItem) != osl::FileBase::RC::E_None &&
+ aItem.getFileStatus( aStatus ) != osl::FileBase::RC::E_None );
+
+ // SvFileStream can't open a directory
+ if( bStatValid && aStatus.getFileType() == osl::FileStatus::Type::Directory )
+ {
+ SetError( ::GetSvError( EISDIR ) );
+ return;
+ }
if ( !( nOpenMode & STREAM_WRITE ) )
uFlags = osl_File_OpenFlag_Read;
@@ -736,44 +740,37 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode )
if ( nOpenMode & STREAM_WRITE)
{
- if ( nOpenMode & STREAM_COPY_ON_SYMLINK )
- {
- if ( bStatValid && S_ISLNK( buf.st_mode ) < 0 )
+ if ( nOpenMode & STREAM_COPY_ON_SYMLINK )
+ {
+ if ( bStatValid && aStatus.getFileType() == osl::FileStatus::Type::Link &&
+ aStatus.getLinkTargetURL().getLength() > 0 )
{
- char *pBuf = new char[ 1024+1 ];
- if ( readlink( aLocalFilename.getStr(), pBuf, 1024 ) > 0 )
+ // delete the symbolic link, and replace it with the contents of the link
+ if (osl::File::remove( aFileURL ) == osl::FileBase::RC::E_None )
{
- if ( unlink(aLocalFilename.getStr()) == 0 )
- {
-#ifdef DBG_UTIL
- fprintf( stderr,
- "Copying file on symbolic link (%s).\n",
- aLocalFilename.getStr() );
+ File::copy( aStatus.getLinkTargetURL(), aFileURL );
+#if OSL_DEBUG_LEVEL > 0
+ fprintf( stderr,
+ "Removing link and replacing with file contents (%s) -> (%s).\n",
+ rtl::OUStringToOString( aStatus.getLinkTargetURL(),
+ RTL_TEXTENCODING_UTF8).getStr(),
+ rtl::OUStringToOString( aFileURL,
+ RTL_TEXTENCODING_UTF8).getStr() );
#endif
- String aTmpString( pBuf, osl_getThreadTextEncoding() );
- const DirEntry aSourceEntry( aTmpString );
- const DirEntry aTargetEntry( aFilename );
- FileCopier aFileCopier( aSourceEntry, aTargetEntry );
- aFileCopier.Execute();
- }
}
- delete [] pBuf;
}
}
}
- oslFileError rc = osl_openFilePath( aLocalFilename.getStr(),&nHandleTmp, uFlags );
-
+ oslFileError rc = osl_openFile( aFileURL.pData, &nHandleTmp, uFlags );
if ( rc != osl_File_E_None )
{
if ( uFlags & osl_File_OpenFlag_Write )
{
// auf Lesen runterschalten
uFlags &= ~osl_File_OpenFlag_Write;
- rc = osl_openFilePath( aLocalFilename.getStr(),
- &nHandleTmp,
- uFlags );
- }
+ rc = osl_openFile( aFileURL.pData, &nHandleTmp, uFlags );
+ }
}
if ( rc == osl_File_E_None )
{