Rex Dieter 332884
--- branches/akonadi/1.1/server/src/akonadi.cpp	2009/01/03 16:17:31	905029
Rex Dieter 332884
+++ branches/akonadi/1.1/server/src/akonadi.cpp	2009/02/25 10:55:29	931467
Rex Dieter 332884
@@ -225,23 +225,30 @@
Rex Dieter 332884
   const QString actualConfig = XdgBaseDirs::saveDir( "data", QLatin1String( "akonadi" ) ) + QLatin1String("/mysql.conf");
Rex Dieter 332884
   if ( globalConfig.isEmpty() )
Rex Dieter 332884
     akFatal() << "Did not find MySQL server default configuration (mysql-global.conf)";
Rex Dieter 332884
-  QFile globalFile( globalConfig );
Rex Dieter 332884
-  QFile actualFile( actualConfig );
Rex Dieter 332884
-  if ( globalFile.open( QFile::ReadOnly ) && actualFile.open( QFile::WriteOnly ) ) {
Rex Dieter 332884
-    actualFile.write( globalFile.readAll() );
Rex Dieter 332884
-    if ( !localConfig.isEmpty() ) {
Rex Dieter 332884
-      QFile localFile( localConfig );
Rex Dieter 332884
-      if ( localFile.open( QFile::ReadOnly ) ) {
Rex Dieter 332884
-        actualFile.write( localFile.readAll() );
Rex Dieter 332884
-        localFile.close();
Rex Dieter 332884
+  bool confUpdate = false;
Rex Dieter 332884
+  QFile actualFile ( actualConfig );
Rex Dieter 332884
+  // update conf only if either global (or local) is newer than actual
Rex Dieter 332884
+  if ( (QFileInfo( globalConfig ).lastModified() > QFileInfo( actualFile ).lastModified()) ||
Rex Dieter 332884
+       (QFileInfo( localConfig ).lastModified()  > QFileInfo( actualFile ).lastModified()) )
Rex Dieter 332884
+  {
Rex Dieter 332884
+    QFile globalFile( globalConfig );
Rex Dieter 332884
+    QFile localFile ( localConfig );
Rex Dieter 332884
+    if ( globalFile.open( QFile::ReadOnly ) && actualFile.open( QFile::WriteOnly ) ) {
Rex Dieter 332884
+      actualFile.write( globalFile.readAll() );
Rex Dieter 332884
+      if ( !localConfig.isEmpty() ) {
Rex Dieter 332884
+        if ( localFile.open( QFile::ReadOnly ) ) {
Rex Dieter 332884
+          actualFile.write( localFile.readAll() );
Rex Dieter 332884
+          localFile.close();
Rex Dieter 332884
+        }
Rex Dieter 332884
       }
Rex Dieter 332884
+      globalFile.close();
Rex Dieter 332884
+      actualFile.close();
Rex Dieter 332884
+      confUpdate = true;
Rex Dieter 332884
+    } else {
Rex Dieter 332884
+      akError() << "Unable to create MySQL server configuration file.";
Rex Dieter 332884
+      akError() << "This means that either the default configuration file (mysql-global.conf) was not readable";
Rex Dieter 332884
+      akFatal() << "or the target file (mysql.conf) could not be written.";
Rex Dieter 332884
     }
Rex Dieter 332884
-    actualFile.close();
Rex Dieter 332884
-    globalFile.close();
Rex Dieter 332884
-  } else {
Rex Dieter 332884
-    akError() << "Unable to create MySQL server configuration file.";
Rex Dieter 332884
-    akError() << "This means that either the default configuration file (mysql-global.conf) was not readable";
Rex Dieter 332884
-    akFatal() << "or the target file (mysql.conf) could not be written.";
Rex Dieter 332884
   }
Rex Dieter 332884
 
Rex Dieter 332884
   // MySQL doesn't like world writeable config files (which makes sense), but
Rex Dieter 332884
@@ -276,6 +283,12 @@
Rex Dieter 332884
     }
Rex Dieter 332884
   }
Rex Dieter 332884
 
Rex Dieter 332884
+  // clear mysql ib_logfile's in case innodb_log_file_size option changed in last confUpdate
Rex Dieter 332884
+  if ( confUpdate ) {
Rex Dieter 332884
+      QFile(dataDir + QDir::separator() + QString::fromLatin1( "ib_logfile0" )).remove();
Rex Dieter 332884
+      QFile(dataDir + QDir::separator() + QString::fromLatin1( "ib_logfile1" )).remove();
Rex Dieter 332884
+  }
Rex Dieter 332884
+
Rex Dieter 332884
   // synthesize the mysqld command
Rex Dieter 332884
   QStringList arguments;
Rex Dieter 332884
   arguments << QString::fromLatin1( "--defaults-file=%1/mysql.conf" ).arg( akDir );