diff options
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 112b833f87..81335c117e 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -67,6 +67,7 @@ import subprocess | |||
67 | import tempfile | 67 | import tempfile |
68 | import bb | 68 | import bb |
69 | import bb.progress | 69 | import bb.progress |
70 | from contextlib import contextmanager | ||
70 | from bb.fetch2 import FetchMethod | 71 | from bb.fetch2 import FetchMethod |
71 | from bb.fetch2 import runfetchcmd | 72 | from bb.fetch2 import runfetchcmd |
72 | from bb.fetch2 import logger | 73 | from bb.fetch2 import logger |
@@ -408,6 +409,20 @@ class Git(FetchMethod): | |||
408 | bb.utils.remove(tmpdir, recurse=True) | 409 | bb.utils.remove(tmpdir, recurse=True) |
409 | 410 | ||
410 | def build_mirror_data(self, ud, d): | 411 | def build_mirror_data(self, ud, d): |
412 | |||
413 | # Create as a temp file and move atomically into position to avoid races | ||
414 | @contextmanager | ||
415 | def create_atomic(filename, d): | ||
416 | fd, tfile = tempfile.mkstemp(dir=os.path.dirname(filename)) | ||
417 | try: | ||
418 | yield tfile | ||
419 | umask = os.umask(0o666) | ||
420 | os.umask(umask) | ||
421 | os.chmod(tfile, (0o666 & ~umask)) | ||
422 | runfetchcmd("mv %s %s" % (tfile, filename), d) | ||
423 | finally: | ||
424 | os.close(fd) | ||
425 | |||
411 | if ud.shallow and ud.write_shallow_tarballs: | 426 | if ud.shallow and ud.write_shallow_tarballs: |
412 | if not os.path.exists(ud.fullshallow): | 427 | if not os.path.exists(ud.fullshallow): |
413 | if os.path.islink(ud.fullshallow): | 428 | if os.path.islink(ud.fullshallow): |
@@ -418,7 +433,8 @@ class Git(FetchMethod): | |||
418 | self.clone_shallow_local(ud, shallowclone, d) | 433 | self.clone_shallow_local(ud, shallowclone, d) |
419 | 434 | ||
420 | logger.info("Creating tarball of git repository") | 435 | logger.info("Creating tarball of git repository") |
421 | runfetchcmd("tar -czf %s ." % ud.fullshallow, d, workdir=shallowclone) | 436 | with create_atomic(ud.fullshallow, d) as tfile: |
437 | runfetchcmd("tar -czf %s ." % tfile, d, workdir=shallowclone) | ||
422 | runfetchcmd("touch %s.done" % ud.fullshallow, d) | 438 | runfetchcmd("touch %s.done" % ud.fullshallow, d) |
423 | finally: | 439 | finally: |
424 | bb.utils.remove(tempdir, recurse=True) | 440 | bb.utils.remove(tempdir, recurse=True) |
@@ -427,7 +443,8 @@ class Git(FetchMethod): | |||
427 | os.unlink(ud.fullmirror) | 443 | os.unlink(ud.fullmirror) |
428 | 444 | ||
429 | logger.info("Creating tarball of git repository") | 445 | logger.info("Creating tarball of git repository") |
430 | runfetchcmd("tar -czf %s ." % ud.fullmirror, d, workdir=ud.clonedir) | 446 | with create_atomic(ud.fullmirror, d) as tfile: |
447 | runfetchcmd("tar -czf %s ." % tfile, d, workdir=ud.clonedir) | ||
431 | runfetchcmd("touch %s.done" % ud.fullmirror, d) | 448 | runfetchcmd("touch %s.done" % ud.fullmirror, d) |
432 | 449 | ||
433 | def clone_shallow_local(self, ud, dest, d): | 450 | def clone_shallow_local(self, ud, dest, d): |