Skip to contentSkip to conversation

A couple of fixes for the inotify code

PATCH New Paul Eggleton 1 participant 3 messages Sep 14, 2017

lore
Share & tools
lore
#0 lore raw

cover A couple of fixes for the inotify code

A fix for bbappends created in empty directories not being picked up, and a related patch for a separate minor issue I noticed at the same time.

The following changes since commit f0930f3216a8358759d561d244fa280932e8bf05:

bitbake-user-manual: Edits to "inherit" section. (2017-09-13 17:19:08 +0100)

are available in the git repository at:

git://git.openembedded.org/bitbake-contrib paule/bb-watch-fixes
http://cgit.openembedded.org/bitbake-contrib/log/?h=paule/bb-watch-fixes

Paul Eggleton (2):
cooker: fix watching empty directories
cooker: ensure monkey-patching in collect_bbfiles() gets undone on error

 lib/bb/cooker.py | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)
Signature · 1 line
2.9.5
#1 lore raw

PATCH 1/2 cooker: fix watching empty directories

The code that was supposed to watch directories along BBFILES for creation of new files wasn't working in the case where the directory did not initially contain any matching files - since in updateCache() we are passing the directory path to add_filewatch() and the latter function calls os.path.dirname() on the path on the assumption that it is a file path, and thus the parent of the directory got watched but not the directory itself. (If the directory wasn't empty everything worked fine since add_filewatch() was called elsewhere with the path to one of the files in that directory, and thus the directory got watched). Add a parameter to add_filewatch() to tell it we are passing it directory path(s) rather than file path(s).

---
 lib/bb/cooker.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/bb/cooker.py +6 -3
index 8fe36eb..6de04fc 100644
@@ -266,12 +266,15 @@ class BBCooker:
             self.inotify_modified_files.append(event.pathname)
         self.parsecache_valid = False
 
-    def add_filewatch(self, deps, watcher=None):
+    def add_filewatch(self, deps, watcher=None, dirs=False):
         if not watcher:
             watcher = self.watcher
         for i in deps:
             watcher.bbwatchedfiles.append(i[0])
-            f = os.path.dirname(i[0])
+            if dirs:
+                f = i[0]
+            else:
+                f = os.path.dirname(i[0])
             if f in watcher.bbseen:
                 continue
             watcher.bbseen.append(f)
@@ -1512,7 +1515,7 @@ class BBCooker:
 
             # Add inotify watches for directories searched for bb/bbappend files
             for dirent in searchdirs:
-                self.add_filewatch([[dirent]])
+                self.add_filewatch([[dirent]], dirs=True)
 
             self.parser = CookerParser(self, filelist, masked)
             self.parsecache_valid = True
Signature · 1 line
2.9.5
#2 lore raw

PATCH 2/2 cooker: ensure monkey-patching in collect_bbfiles() gets undone on error

In reply to Paul Eggleton

In collect_bbfiles() we're monkey-patching os.listdir in order to find which directories to watch, and then undoing that when we're finished - however if an exception occurred for any reason there was nothing to ensure the latter occurred. This may not have caused any issues, but as this kind of thing really ought to be secured using try...finally just in case, so do that.

---
 lib/bb/cooker.py | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
lib/bb/cooker.py +19 -19
index 6de04fc..73a2fef 100644
@@ -1695,25 +1695,25 @@ class CookerCollectFiles(object):
             return origlistdir(d)
 
         os.listdir = ourlistdir
-
-        # Can't use set here as order is important
-        newfiles = []
-        for f in files:
-            if os.path.isdir(f):
-                dirfiles = self.find_bbfiles(f)
-                for g in dirfiles:
-                    if g not in newfiles:
-                        newfiles.append(g)
-            else:
-                globbed = glob.glob(f)
-                if not globbed and os.path.exists(f):
-                    globbed = [f]
-                # glob gives files in order on disk. Sort to be deterministic.
-                for g in sorted(globbed):
-                    if g not in newfiles:
-                        newfiles.append(g)
-
-        os.listdir = origlistdir
+        try:
+            # Can't use set here as order is important
+            newfiles = []
+            for f in files:
+                if os.path.isdir(f):
+                    dirfiles = self.find_bbfiles(f)
+                    for g in dirfiles:
+                        if g not in newfiles:
+                            newfiles.append(g)
+                else:
+                    globbed = glob.glob(f)
+                    if not globbed and os.path.exists(f):
+                        globbed = [f]
+                    # glob gives files in order on disk. Sort to be deterministic.
+                    for g in sorted(globbed):
+                        if g not in newfiles:
+                            newfiles.append(g)
+        finally:
+            os.listdir = origlistdir
 
         bbmask = config.getVar('BBMASK')
 
Signature · 1 line
2.9.5