summaryrefslogtreecommitdiff
path: root/tools
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 /tools
parent755f299eccee79aa91ce6d935b85d2b00fe74974 (diff)
fix SvStream to not require a custom open or lstat method.
Diffstat (limited to 'tools')
-rw-r--r--tools/inc/tools/stream.hxx4
-rw-r--r--tools/source/stream/strmunx.cxx71
2 files changed, 36 insertions, 39 deletions
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 )
{