]> code.ossystems Code Review - openembedded-core.git/commitdiff
externalsrc: avoid race in temporary git index file
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 5 Apr 2016 13:21:49 +0000 (16:21 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 5 Apr 2016 13:37:43 +0000 (14:37 +0100)
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@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/externalsrc.bbclass

index dff61842f2a1b2fb32e76fea4ba92b01e0177477..da7eb4781c51a4a0cf44ef5f7c30777971fcb0ac 100644 (file)
@@ -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'