Kaydet (Commit) 4a086fca authored tarafından Michael Meeks's avatar Michael Meeks

fix SvStream to not require a custom open or lstat method.

üst 755f299e
......@@ -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 );
......
......@@ -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.
......
......@@ -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;
......
......@@ -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: */
......@@ -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;
};
......
......@@ -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.
......
......@@ -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 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment