Phil Dawson pushed to branch phil/source-checkout-options at BuildStream / buildstream
Commits:
-
1ba0c880
by Phil Dawson at 2018-12-04T11:25:43Z
1 changed file:
Changes:
... | ... | @@ -1127,10 +1127,14 @@ class Stream(): |
1127 | 1127 |
# Create a tarball from the content of directory
|
1128 | 1128 |
def _create_tarball(self, directory, tar_name):
|
1129 | 1129 |
try:
|
1130 |
- with tarfile.open(name=tar_name, mode='w') as tf:
|
|
1130 |
+ with utils.save_file_atomic(tar_name, mode='wb') as f:
|
|
1131 |
+ # This TarFile does not need to be explicitly closed
|
|
1132 |
+ # as the underlying file object will be closed be the
|
|
1133 |
+ # save_file_atomic contect manager
|
|
1134 |
+ tarball = tarfile.open(fileobj=f, mode='w')
|
|
1131 | 1135 |
for item in os.listdir(str(directory)):
|
1132 | 1136 |
file_to_add = os.path.join(directory, item)
|
1133 |
- tf.add(file_to_add, arcname=item)
|
|
1137 |
+ tarball.add(file_to_add, arcname=item)
|
|
1134 | 1138 |
except OSError as e:
|
1135 | 1139 |
# If we have a partially constructed tar file, clean up after ourselves
|
1136 | 1140 |
try:
|