Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a6f5a288 authored by Joachim Eibl's avatar Joachim Eibl

Fix crash when changing the m_statusText

git-svn-id: https://kdiff3.svn.sourceforge.net/svnroot/kdiff3/trunk@155 c8aa9fed-2811-0410-8543-893ada326672
parent f0dadf39
......@@ -118,6 +118,17 @@ FileAccess::FileAccess(const FileAccess& other)
*this = other;
}
void FileAccess::createData()
{
if ( d() == 0 )
{
FileAccess* pParent = m_pParent; // backup because in union with m_pData
m_pData = new Data();
m_bUseData = true;
m_pData->m_pParent = pParent;
}
}
const FileAccess& FileAccess::operator=(const FileAccess& other)
{
m_size = other.m_size;
......@@ -132,9 +143,7 @@ const FileAccess& FileAccess::operator=(const FileAccess& other)
if ( other.m_bUseData )
{
if ( ! m_bUseData )
m_pData = new Data;
m_bUseData = true;
createData();
*m_pData = *other.m_pData;
}
else
......@@ -183,10 +192,9 @@ void FileAccess::setFile( const QFileInfo& fi, FileAccess* pParent )
m_filePath = nicePath( fi.filePath() ); // remove "./" at start
m_bSymLink = fi.isSymLink();
if ( ( m_bSymLink || (!m_bExists && m_filePath.contains("@@") ) )&& !m_bUseData )
if ( m_bSymLink || (!m_bExists && m_filePath.contains("@@") ) )
{
m_pData = new Data;
m_bUseData = true;
createData();
}
if ( m_bUseData )
......@@ -309,11 +317,7 @@ void FileAccess::setFile( const QString& name, bool bWantToWrite )
}
else
{
if (d()==0)
{
m_pData = new Data;
m_bUseData = true;
}
createData();
d()->m_url = url;
d()->m_name = d()->m_url.fileName();
d()->m_bLocal = false;
......@@ -883,6 +887,15 @@ QString FileAccess::getStatusText()
return d()==0 ? QString() : d()->m_statusText;
}
void FileAccess::setStatusText( const QString& s )
{
if ( ! s.isEmpty() || d() != 0 )
{
createData();
d()->m_statusText = s;
}
}
QString FileAccess::cleanPath( const QString& path ) // static
{
KUrl url(path);
......@@ -900,11 +913,7 @@ bool FileAccess::createBackup( const QString& bakExtension )
{
if ( exists() )
{
if (d()==0)
{
m_pData = new Data;
m_bUseData = true;
}
createData();
setFile( absoluteFilePath() ); // make sure Data is initialized
// First rename the existing file to the bak-file. If a bak-file file exists, delete that.
QString bakName = absoluteFilePath() + bakExtension;
......@@ -914,15 +923,15 @@ bool FileAccess::createBackup( const QString& bakExtension )
bool bSuccess = bakFile.removeFile();
if ( !bSuccess )
{
d()->m_statusText = i18n("While trying to make a backup, deleting an older backup failed. \nFilename: ") + bakName;
setStatusText( i18n("While trying to make a backup, deleting an older backup failed. \nFilename: ") + bakName );
return false;
}
}
bool bSuccess = rename( bakName );
if (!bSuccess)
{
d()->m_statusText = i18n("While trying to make a backup, renaming failed. \nFilenames: ") +
absoluteFilePath() + " -> " + bakName;
setStatusText( i18n("While trying to make a backup, renaming failed. \nFilenames: ") +
absoluteFilePath() + " -> " + bakName );
return false;
}
}
......@@ -938,7 +947,7 @@ FileAccessJobHandler::FileAccessJobHandler( FileAccess* pFileAccess )
bool FileAccessJobHandler::stat( int detail, bool bWantToWrite )
{
m_bSuccess = false;
m_pFileAccess->d()->m_statusText = QString();
m_pFileAccess->setStatusText( QString() );
KIO::StatJob* pStatJob = KIO::stat( m_pFileAccess->url(),
bWantToWrite ? KIO::StatJob::DestinationSide : KIO::StatJob::SourceSide,
detail, KIO::HideProgressInfo );
......@@ -982,7 +991,7 @@ bool FileAccessJobHandler::get(void* pDestBuffer, long maxLength )
m_pTransferBuffer = (char*)pDestBuffer;
m_maxLength = maxLength;
m_bSuccess = false;
m_pFileAccess->d()->m_statusText = QString();
m_pFileAccess->setStatusText( QString() );
connect( pJob, SIGNAL(result(KJob*)), this, SLOT(slotSimpleJobResult(KJob*)));
connect( pJob, SIGNAL(data(KJob*,const QByteArray &)), this, SLOT(slotGetData(KJob*, const QByteArray&)));
......@@ -1019,7 +1028,7 @@ bool FileAccessJobHandler::put(const void* pSrcBuffer, long maxLength, bool bOve
m_pTransferBuffer = (char*)pSrcBuffer;
m_maxLength = maxLength;
m_bSuccess = false;
m_pFileAccess->d()->m_statusText = QString();
m_pFileAccess->setStatusText( QString() );
connect( pJob, SIGNAL(result(KJob*)), this, SLOT(slotPutJobResult(KJob*)));
connect( pJob, SIGNAL(dataReq(KIO::Job*, QByteArray&)), this, SLOT(slotPutData(KIO::Job*, QByteArray&)));
......@@ -1190,7 +1199,7 @@ bool FileAccessJobHandler::copyFile( const QString& dest )
{
ProgressProxy pp;
KUrl destUrl( dest );
m_pFileAccess->d()->m_statusText = QString();
m_pFileAccess->setStatusText( QString() );
if ( ! m_pFileAccess->isLocal() || ! destUrl.isLocalFile() ) // if either url is nonlocal
{
int permissions = (m_pFileAccess->isExecutable()?0111:0)+(m_pFileAccess->isWritable()?0222:0)+(m_pFileAccess->isReadable()?0444:0);
......@@ -1213,13 +1222,13 @@ bool FileAccessJobHandler::copyFile( const QString& dest )
bool bReadSuccess = srcFile.open( QIODevice::ReadOnly );
if ( bReadSuccess == false )
{
m_pFileAccess->d()->m_statusText = i18n("Error during file copy operation: Opening file for reading failed. Filename: %1",srcName);
m_pFileAccess->setStatusText( i18n("Error during file copy operation: Opening file for reading failed. Filename: %1",srcName) );
return false;
}
bool bWriteSuccess = destFile.open( QIODevice::WriteOnly );
if ( bWriteSuccess == false )
{
m_pFileAccess->d()->m_statusText = i18n("Error during file copy operation: Opening file for writing failed. Filename: %1",destName);
m_pFileAccess->setStatusText( i18n("Error during file copy operation: Opening file for writing failed. Filename: %1",destName) );
return false;
}
......@@ -1234,7 +1243,7 @@ bool FileAccessJobHandler::copyFile( const QString& dest )
qint64 readSize = srcFile.read( &buffer[0], min2( srcSize, bufSize ) );
if ( readSize==-1 || readSize==0 )
{
m_pFileAccess->d()->m_statusText = i18n("Error during file copy operation: Reading failed. Filename: %1",srcName);
m_pFileAccess->setStatusText( i18n("Error during file copy operation: Reading failed. Filename: %1",srcName) );
return false;
}
srcSize -= readSize;
......@@ -1243,7 +1252,7 @@ bool FileAccessJobHandler::copyFile( const QString& dest )
qint64 writeSize = destFile.write( &buffer[0], readSize );
if ( writeSize==-1 || writeSize==0 )
{
m_pFileAccess->d()->m_statusText = i18n("Error during file copy operation: Writing failed. Filename: %1",destName);
m_pFileAccess->setStatusText( i18n("Error during file copy operation: Writing failed. Filename: %1",destName) );
return false;
}
readSize -= writeSize;
......@@ -1748,8 +1757,7 @@ void FileAccessJobHandler::slotListDirProcessNewEntries( KIO::Job*, const KIO::U
{
const KIO::UDSEntry& e = *i;
FileAccess fa;
fa.m_pData = new FileAccess::Data;
fa.m_bUseData = true;
fa.createData();
fa.m_pData->m_pParent = m_pFileAccess;
fa.setUdsEntry( e );
......
......@@ -92,10 +92,12 @@ public:
private:
void setUdsEntry( const KIO::UDSEntry& e );
void setFile( const QFileInfo& fi, FileAccess* pParent );
void setStatusText( const QString& s );
class Data;
Data* d();
const Data* d() const;
void createData();
union
{
......
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