[oe-commits] [openembedded-core] branch master-next updated: externalsrc: avoid race in temporary git index file

git at git.openembedded.org git at git.openembedded.org
Tue Apr 5 13:39:18 UTC 2016


rpurdie pushed a commit to branch master-next
in repository openembedded-core.

The following commit(s) were added to refs/heads/master-next by this push:
       new  f81c641   externalsrc: avoid race in temporary git index file
f81c641 is described below

commit f81c641022c26a9b89fac769e0f2889eaec5d32f
Author: Markus Lehtonen <markus.lehtonen at linux.intel.com>
AuthorDate: Tue Apr 5 16:21:49 2016 +0300

    externalsrc: avoid race in temporary git index file
    
    Use a unique tempfile as the temporary git index file when determining
    the git hash of the source tree. A fixed filename was obviously causing
    races (with the git index.lock file) under oe-selftest where multiple
    bitbake instances were run against the same source tree at the same
    time.
    
    Signed-off-by: Markus Lehtonen <markus.lehtonen at linux.intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/classes/externalsrc.bbclass | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/meta/classes/externalsrc.bbclass b/meta/classes/externalsrc.bbclass
index dff6184..da7eb478 100644
--- a/meta/classes/externalsrc.bbclass
+++ b/meta/classes/externalsrc.bbclass
@@ -130,21 +130,22 @@ python externalsrc_compile_prefunc() {
 def srctree_hash_files(d):
     import shutil
     import subprocess
+    import tempfile
 
     s_dir = d.getVar('EXTERNALSRC', True)
     git_dir = os.path.join(s_dir, '.git')
-    oe_index_file = os.path.join(git_dir, 'oe-devtool-index')
     oe_hash_file = os.path.join(git_dir, 'oe-devtool-tree-sha1')
 
     ret = " "
     if os.path.exists(git_dir):
-        # Clone index
-        shutil.copy2(os.path.join(git_dir, 'index'), oe_index_file)
-        # Update our custom index
-        env = os.environ.copy()
-        env['GIT_INDEX_FILE'] = oe_index_file
-        subprocess.check_output(['git', 'add', '.'], cwd=s_dir, env=env)
-        sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env)
+        with tempfile.NamedTemporaryFile(dir=git_dir, prefix='oe-devtool-index') as tmp_index:
+            # Clone index
+            shutil.copy2(os.path.join(git_dir, 'index'), tmp_index.name)
+            # Update our custom index
+            env = os.environ.copy()
+            env['GIT_INDEX_FILE'] = tmp_index.name
+            subprocess.check_output(['git', 'add', '.'], cwd=s_dir, env=env)
+            sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env)
         with open(oe_hash_file, 'w') as fobj:
             fobj.write(sha1)
         ret = oe_hash_file + ':True'

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list