File ksycoca_global.diff of Package kdelibs3

--- kdecore/kstandarddirs.cpp
+++ kdecore/kstandarddirs.cpp	2003/02/25 15:50:23
@@ -1019,8 +1019,12 @@
 
     }
 
-    fixHomeDir(localKdeDir);
-    addPrefix(localKdeDir);
+    if (localKdeDir != "-/")
+    {
+        fixHomeDir(localKdeDir);
+//qWarning("Setting KDE home dir to %s", localKdeDir.latin1());
+        addPrefix(localKdeDir);
+    }
 
     for (QStringList::ConstIterator it = kdedirList.begin();
 	 it != kdedirList.end(); it++)
--- kdecore/ksycoca.cpp
+++ kdecore/ksycoca.cpp	2003/02/25 15:53:59
@@ -100,9 +100,23 @@
       path = KGlobal::dirs()->saveLocation("tmp") + "ksycoca";
    else
       path = QFile::decodeName(ksycoca_env);
-   //kdDebug(7011) << "Trying to open ksycoca from " << path << endl;
+
+   kdDebug(7011) << "Trying to open ksycoca from " << path << endl;
    QFile *database = new QFile(path);
-   if (database->open( IO_ReadOnly ))
+   bool bOpen = database->open( IO_ReadOnly );
+   if (!bOpen)
+   {
+     path = locate("services", "ksycoca");
+     if (!path.isEmpty())
+     {
+       kdDebug(7011) << "Trying to open global ksycoca from " << path << endl;
+       delete database;
+       database = new QFile(path);
+       bOpen = database->open( IO_ReadOnly );
+     }
+   }
+   
+   if (bOpen)
    {
      fcntl(database->handle(), F_SETFD, FD_CLOEXEC);
      m_sycoca_size = database->size();
@@ -132,6 +146,8 @@
    }
    else
    {
+     kdDebug(7011) << "Could not open ksycoca" << endl;
+
      // No database file
      delete database;
      database = 0;
--- kded/kbuildsycoca.cpp
+++ kded/kbuildsycoca.cpp	2003/02/25 15:56:58
@@ -60,6 +60,8 @@
 
 static const char *cSycocaPath = 0;
 
+static bool bGlobalDatabase = 0;
+
 void crashHandler(int)
 {
    // If we crash while reading sycoca, we delete the database
@@ -71,11 +73,19 @@
 static QString sycocaPath()
 {
   QString path;
-  QCString ksycoca_env = getenv("KDESYCOCA");
-  if (ksycoca_env.isEmpty())
-     path = KGlobal::dirs()->saveLocation("tmp")+"ksycoca";
+  
+  if (bGlobalDatabase)
+  {
+     path = KGlobal::dirs()->saveLocation("services")+"ksycoca";
+  }
   else
-     path = QFile::decodeName(ksycoca_env);
+  {
+     QCString ksycoca_env = getenv("KDESYCOCA");
+     if (ksycoca_env.isEmpty())
+        path = KGlobal::dirs()->saveLocation("tmp")+"ksycoca";
+     else
+        path = QFile::decodeName(ksycoca_env);
+  }
 
   return path;     
 }
@@ -334,13 +344,16 @@
     kdDebug(7021) << "Database is up to date" << endl;
   }
 
-  // update the timestamp file
-  QString stamppath = path + "stamp";
-  QFile ksycocastamp(stamppath);
-  ksycocastamp.open( IO_WriteOnly );
-  QDataStream str( &ksycocastamp );
-  str << newTimestamp;
-  str << existingResourceDirs();
+  if (!bGlobalDatabase)
+  {
+    // update the timestamp file
+    QString stamppath = path + "stamp";
+    QFile ksycocastamp(stamppath);
+    ksycocastamp.open( IO_WriteOnly );
+    QDataStream str( &ksycocastamp );
+    str << newTimestamp;
+    str << existingResourceDirs();
+  }
 }
 
 void KBuildSycoca::save()
@@ -368,7 +381,10 @@
    }
    (*m_str) << (Q_INT32) 0; // No more factories.
    // Write KDEDIRS
-   (*m_str) << KGlobal::dirs()->kfsstnd_prefixes();
+   if (bGlobalDatabase)
+      (*m_str) << "*:"+KGlobal::dirs()->kfsstnd_prefixes();
+   else
+      (*m_str) << KGlobal::dirs()->kfsstnd_prefixes();
    (*m_str) << newTimestamp;
    (*m_str) << KGlobal::locale()->language();
    (*m_str) << KGlobal::dirs()->calcResourceHash("services", "update_ksycoca", true);
@@ -496,7 +512,8 @@
    { "nosignal", I18N_NOOP("Don't signal applications."), 0 },
    { "incremental", I18N_NOOP("Incremental update."), 0 },
    { "checkstamps", I18N_NOOP("Check file timestamps."), 0 },
-   { 0, 0, 0 }
+   { "global", I18N_NOOP("Create global database."), 0 },
+   KCmdLineLastOption
 };
 
 static const char *appName = "kbuildsycoca";
@@ -514,6 +531,13 @@
    KCmdLineArgs::init(argc, argv, &d);
    KCmdLineArgs::addCmdLineOptions(options);
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+   bGlobalDatabase = args->isSet("global");
+
+   if (bGlobalDatabase)
+   {
+     setenv("KDEHOME", "-", 1);
+     setenv("KDEROOTHOME", "-", 1);
+   }
 
    KApplication::disableAutoDcopRegistration();
    KApplication k(false, false);
@@ -543,7 +567,8 @@
      exit(0);
    }
 
-   bool incremental = args->isSet("incremental");
+
+   bool incremental = !bGlobalDatabase && args->isSet("incremental");
    if (incremental)
    {
      QString current_kfsstnd = KGlobal::dirs()->kfsstnd_prefixes();
@@ -552,11 +577,19 @@
      QString ksycoca_language = KSycoca::self()->language();
      Q_UINT32 current_update_sig = KGlobal::dirs()->calcResourceHash("services", "update_ksycoca", true);
      Q_UINT32 ksycoca_update_sig = KSycoca::self()->updateSignature();
+
+     if (ksycoca_kfsstnd.startsWith("*:") && 
+         current_kfsstnd.endsWith(ksycoca_kfsstnd.mid(2)))
+     {
+//qWarning("Using global ksycoca database!!");
+        ksycoca_kfsstnd = current_kfsstnd;
+     }
      
      if ((current_update_sig != ksycoca_update_sig) ||
          (current_kfsstnd != ksycoca_kfsstnd) ||
          (current_language != ksycoca_language))
      {
+//qWarning("Not reusing existing database!!");
         incremental = false;
         delete KSycoca::self();
      }
@@ -568,7 +601,7 @@
    Q_UINT32 filestamp = 0;
    if( checkstamps && incremental )
        {
-       QString path = KGlobal::dirs()->saveLocation("tmp")+"ksycocastamp";
+       QString path = sycocaPath()+"stamp";
        QFile ksycocastamp(path);
        if( ksycocastamp.open( IO_ReadOnly ))
            {
openSUSE Build Service is sponsored by