Skip to content

Commit

Permalink
[buteo-syncml] Fix profile removal - set absolute file path when call…
Browse files Browse the repository at this point in the history
…ing setDatabaseFilePath()

msyncd was failing to remove sync profiles when requested as this
fails if the plugin does not cleanUp() successfully. This was a problem
as SyncAgent::cleanUp() always failed as it was locating the database
file with a non-absolute path.

The code for creating the absolute databse file path was previously in
DatabaseHandler; this patch moves the code to SyncAgentConfig to ensure
that it sets the database file path to an absolute file path as
expected.
  • Loading branch information
Bea Lam committed Feb 12, 2014
1 parent b1904c5 commit 70864c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/DatabaseHandler.cpp
Expand Up @@ -34,13 +34,12 @@
#include "DatabaseHandler.h"

#include "LogMacros.h"
#include "SyncCommonDefs.h"

using namespace DataSync;

const QString CONNECTIONNAME( "dbhandler" );

DatabaseHandler::DatabaseHandler( const QString& aDbFile )
DatabaseHandler::DatabaseHandler( const QString& aDbFilePath )
{
FUNCTION_CALL_TRACE;

Expand All @@ -49,12 +48,7 @@ DatabaseHandler::DatabaseHandler( const QString& aDbFile )
iConnectionName = CONNECTIONNAME + QString::number( connectionNumber++ );
iDb = QSqlDatabase::addDatabase( "QSQLITE", iConnectionName );

QString path( Sync::syncCacheDir() );
path.append( QDir::separator() ).append( aDbFile );
path = QDir::toNativeSeparators( path );
QDir().mkpath( QFileInfo(path).path() );

iDb.setDatabaseName( path );
iDb.setDatabaseName( aDbFilePath );
if(!iDb.open())
LOG_CRITICAL("can not open database");

Expand Down
4 changes: 2 additions & 2 deletions src/DatabaseHandler.h
Expand Up @@ -48,10 +48,10 @@ class DatabaseHandler {

/*! \brief Constructor
*
* @param aDbFile Database filename to create and open
* @param aDbFile Path of database file to create and open
*
*/
explicit DatabaseHandler( const QString& aDbFile );
explicit DatabaseHandler( const QString& aDbFilePath );

/*! \brief Destructor
*
Expand Down
15 changes: 14 additions & 1 deletion src/SyncAgentConfig.cpp
Expand Up @@ -37,9 +37,11 @@
#include <QXmlSchemaValidator>
#include <QXmlStreamReader>
#include <QFile>
#include <QDir>
#include <QStringList>

#include "SyncAgentConfigProperties.h"
#include "SyncCommonDefs.h"
#include "datatypes.h"
#include "Transport.h"

Expand Down Expand Up @@ -400,7 +402,18 @@ bool SyncAgentConfig::parseConfFile( const QByteArray& aData )
reader.readNext();
QString dbPath = reader.text().toString();
LOG_DEBUG( "Found critical property" << DBPATH <<":" << dbPath );
setDatabaseFilePath( dbPath );

QFileInfo dbPathInfo(dbPath);
if (dbPathInfo.isAbsolute()) {
setDatabaseFilePath( dbPath );
} else {
if (QDir().mkpath(Sync::syncCacheDir())) {
setDatabaseFilePath(Sync::syncCacheDir() + QDir::separator() + dbPathInfo.fileName());
} else {
LOG_CRITICAL("Unable to create database dir");
return false;
}
}
}
else if( reader.name() == LOCALDEVICENAME )
{
Expand Down

0 comments on commit 70864c5

Please sign in to comment.