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

List:       kde-commits
Subject:    branches/KDE/4.2/kdelibs/kio/kio
From:       David Faure <faure () kde ! org>
Date:       2009-01-20 14:32:45
Message-ID: 1232461965.596847.15224.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 914158 by dfaure:

Make KDirWatch code more robust: check all KDE_stat calls for errors, I guess it can \
happen due to a race condition  (file is created, inotify tells us about it, but \
meanwhile the file is deleted again). Interestingly, the code changed by Flavio in \
914106 is only in trunk, not in 4.2 branch, so it can't have been responsible for the \
valgrind warning _I_ saw, while this commit should fix the similar valgrind warning \
(but in the "file created" code) that auxsvr saw.

Still unlikely that this really fixes the 165548 crash, but at least future valgrind \
logs will be more helpful. (This commit is just before 4.2.0)
CCBUG: 165548


 M  +42 -39    kdirwatch.cpp  


--- branches/KDE/4.2/kdelibs/kio/kio/kdirwatch.cpp #914157:914158
@@ -94,7 +94,7 @@
 #else
     return KDirWatchPrivate::INotify;
 #endif
-  } 
+  }
 }
 
 
@@ -297,9 +297,9 @@
 
             if (sub_entry /*&& sub_entry->isDir*/) {
               removeEntry(0, e, sub_entry);
-              KDE_struct_stat stat_buf;
-              QByteArray tpath = QFile::encodeName(path);
-              KDE_stat(tpath, &stat_buf);
+              //KDE_struct_stat stat_buf;
+              //QByteArray tpath = QFile::encodeName(path);
+              //KDE_stat(tpath, &stat_buf);
 
               //sub_entry->isDir = S_ISDIR(stat_buf.st_mode);
               //sub_entry->m_ctime = stat_buf.st_ctime;
@@ -312,27 +312,29 @@
             }
             else if ((e->isDir) && (!e->m_clients.empty())) {
               KDE_struct_stat stat_buf;
-              QByteArray tpath = QFile::encodeName(e->path+'/'+path);
-              KDE_stat(tpath, &stat_buf);
-              bool isDir = S_ISDIR(stat_buf.st_mode);
+              const QByteArray tpath = QFile::encodeName(e->path+'/'+path);
+              if (KDE_stat(tpath, &stat_buf) == 0) {
+                const bool isDir = S_ISDIR(stat_buf.st_mode);
+                const KDirWatch::WatchModes flag =
+                  isDir ? KDirWatch::WatchSubDirs : KDirWatch::WatchFiles;
 
-              KDirWatch::WatchModes flag;
-              flag = isDir ? KDirWatch::WatchSubDirs : KDirWatch::WatchFiles;
-
-              int counter = 0;
-              Q_FOREACH(Client *client, e->m_clients) {
+                int counter = 0;
+                Q_FOREACH(Client *client, e->m_clients) {
                   if (client->m_watchModes & flag) {
                       addEntry (client->instance, tpath, 0, isDir,
                                 isDir ? client->m_watchModes : \
KDirWatch::WatchDirOnly);  counter++;
                     }
-              }
+                }
 
-              if (counter != 0)
-                emitEvent (e, Created, e->path+'/'+path);
+                if (counter != 0)
+                  emitEvent (e, Created, e->path+'/'+path);
 
-              kDebug(7001).nospace() << counter << " instance(s) monitoring the new \
                "
-                << (isDir ? "dir " : "file ") << tpath;
+                kDebug(7001).nospace() << counter << "instance(s) monitoring the \
new" +                                       << (isDir ? "dir " : "file ") << tpath;
+              } else {
+                kDebug(7001) << "ERROR: couldn't stat the new item" << tpath;
+              }
             }
           }
 
@@ -1386,28 +1388,29 @@
         }
         else if ((sub_entry == 0) && (!e->m_clients.empty())) {
           KDE_struct_stat stat_buf;
-          KDE_stat(tpath, &stat_buf);
-          bool isDir = S_ISDIR(stat_buf.st_mode);
+          if (KDE_stat(tpath, &stat_buf) == 0) {
+            const bool isDir = S_ISDIR(stat_buf.st_mode);
+            const KDirWatch::WatchModes flag =
+              isDir ? KDirWatch::WatchSubDirs : KDirWatch::WatchFiles;
+            int counter = 0;
+            Q_FOREACH(Client *client, e->m_clients) {
+              if (client->m_watchModes & flag) {
+                addEntry (client->instance, tpath, 0, isDir,
+                          isDir ? client->m_watchModes : KDirWatch::WatchDirOnly);
+                counter++;
+              }
+            }
 
-          KDirWatch::WatchModes flag;
-          flag = isDir ? KDirWatch::WatchSubDirs : KDirWatch::WatchFiles;
+            if (counter != 0)
+              emitEvent (e, Created, tpath);
 
-          int counter = 0;
-          Q_FOREACH(Client *client, e->m_clients) {
-            if (client->m_watchModes & flag) {
-              addEntry (client->instance, tpath, 0, isDir,
-                        isDir ? client->m_watchModes : KDirWatch::WatchDirOnly);
-              counter++;
-            }
+            QString msg (QString::number(counter));
+            msg += " instance/s monitoring the new ";
+            msg += (isDir ? "dir " : "file ") + tpath;
+            kDebug(7001) << msg;
+          } else {
+            kDebug(7001) << "ERROR: couldn't stat the new item" << tpath;
           }
-
-          if (counter != 0)
-            emitEvent (e, Created, tpath);
-
-          QString msg (QString::number(counter));
-          msg += " instance/s monitoring the new ";
-          msg += (isDir ? "dir " : "file ") + tpath;
-          kDebug(7001) << msg;
         }
       }
         break;
@@ -1499,9 +1502,9 @@
       }
       if (sub_entry) {
         removeEntry(0, e, sub_entry);
-        KDE_struct_stat stat_buf;
-        QByteArray tpath = QFile::encodeName(path);
-        KDE_stat(tpath, &stat_buf);
+        //KDE_struct_stat stat_buf;
+        //QByteArray tpath = QFile::encodeName(path);
+        //KDE_stat(tpath, &stat_buf);
 
         if(!useQFSWatch(sub_entry))
 #ifdef HAVE_SYS_INOTIFY_H


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

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