[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.2/kdelibs/kdecore/io
From:       Nickolai Shaforostoff <shafff () ukr ! net>
Date:       2009-02-05 17:02:08
Message-ID: 1233853328.574285.21741.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 921781 by shaforo:

backport my patch so that users can get properly working Lokalize from trunk less painfully



 M  +6 -2      kautosavefile.cpp  
 M  +42 -44    klockfile_unix.cpp  


--- branches/KDE/4.2/kdelibs/kdecore/io/kautosavefile.cpp #921780:921781
@@ -106,9 +106,9 @@
 {
     if (d->lock && d->lock->isLocked()) {
         d->lock.clear();
-    }
-    if (!fileName().isEmpty()) {
+        if (!fileName().isEmpty()) {
         remove();
+        }
     }
 }
 
@@ -179,6 +179,8 @@
 
     // contruct a KAutoSaveFile for each stale file
     foreach(const QString &file, files) {
+        if (file.endsWith(".lock"))
+            continue;
         // sets managedFile
         asFile = new KAutoSaveFile(filename);
         asFile->setFileName(file);
@@ -209,6 +211,8 @@
 
     // contruct a KAutoSaveFile for each stale file
     foreach(file, files) {
+        if (file.endsWith(".lock"))
+            continue;
         sep = file.right(3);
         file.chop(KAutoSaveFilePrivate::padding);
 
--- branches/KDE/4.2/kdelibs/kdecore/io/klockfile_unix.cpp #921780:921781
@@ -272,54 +272,13 @@
            break;
         }
      }
-     else // KLockFile::Fail
+     else // KLockFile::Fail -- there is already such a file present (e.g. left by a crashed app)
      {
         if (!d->staleTimer.isNull() && d->statBuf != st_buf)
            d->staleTimer = QTime();
 
-        if (!d->staleTimer.isNull())
+        if (d->staleTimer.isNull())
         {
-           bool isStale = false;
-           if ((d->pid > 0) && !d->hostname.isEmpty())
-           {
-              // Check if hostname is us
-              char hostname[256];
-              hostname[0] = 0;
-              gethostname(hostname, 255);
-              hostname[255] = 0;
-
-              if (d->hostname == QLatin1String(hostname))
-              {
-                 // Check if pid still exists
-                 int res = ::kill(d->pid, 0);
-                 if ((res == -1) && (errno == ESRCH))
-                    isStale = true;
-              }
-           }
-           if (d->staleTimer.elapsed() > (d->staleTime*1000))
-              isStale = true;
-
-           if (isStale)
-           {
-              if ((options & ForceFlag) == 0)
-                 return KLockFile::LockStale;
-
-              result = deleteStaleLock(d->file, d->statBuf, d->linkCountSupport, d->componentData);
-
-              if (result == KLockFile::LockOK)
-              {
-                 // Lock deletion successful
-                 d->staleTimer = QTime();
-                 continue; // Now try to get the new lock
-              }
-              else if (result != KLockFile::LockFail)
-              {
-                 return result;
-              }
-           }
-        }
-        else
-        {
            memcpy(&(d->statBuf), &st_buf, sizeof(KDE_struct_stat));
            d->staleTimer.start();
 
@@ -339,9 +298,48 @@
                  d->hostname = ts.readLine();
            }
         }
+
+        bool isStale = false;
+        if ((d->pid > 0) && !d->hostname.isEmpty())
+        {
+           // Check if hostname is us
+           char hostname[256];
+           hostname[0] = 0;
+           gethostname(hostname, 255);
+           hostname[255] = 0;
+
+           if (d->hostname == QLatin1String(hostname))
+           {
+              // Check if pid still exists
+              int res = ::kill(d->pid, 0);
+              if ((res == -1) && (errno == ESRCH))
+                 isStale = true;
+           }
+        }
+        if (d->staleTimer.elapsed() > (d->staleTime*1000))
+           isStale = true;
+
+        if (isStale)
+        {
+           if ((options & ForceFlag) == 0)
+              return KLockFile::LockStale;
+
+           result = deleteStaleLock(d->file, d->statBuf, d->linkCountSupport, d->componentData);
+
+           if (result == KLockFile::LockOK)
+           {
+              // Lock deletion successful
+              d->staleTimer = QTime();
+              continue; // Now try to get the new lock
+           }
+           else if (result != KLockFile::LockFail)
+           {
+              return result;
+           }
+        }
      }
 
-     if ((options & NoBlockFlag) != 0)
+     if (options & NoBlockFlag)
         break;
 
      struct timeval tv;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic