Skip to content

Commit

Permalink
Merge pull request #9 from nemomobile/db-filepath-fix
Browse files Browse the repository at this point in the history
[buteo-syncml] Fix profile removal - set absolute file path when calling...
  • Loading branch information
blammit committed Feb 12, 2014
2 parents b1904c5 + 70864c5 commit d4d46e9
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 d4d46e9

Please sign in to comment.