summaryrefslogtreecommitdiff
path: root/swift
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-03-27 21:23:50 +0000
committerGerrit Code Review <review@openstack.org>2014-03-27 21:23:50 +0000
commit4b075c107201e3064418d3e5dc41f0ec5ca02e7d (patch)
treecf8f217c95961e3429264af6f8c16d8d69b49af8 /swift
parent31b994560332ffa22fbe45e43471db360467434c (diff)
parentc6cebb6e621a245c9c2d5bff0df59689b0140373 (diff)
downloadswift-4b075c107201e3064418d3e5dc41f0ec5ca02e7d.tar.gz
Merge "Write out ring.gz's in a safer fashion"
Diffstat (limited to 'swift')
-rw-r--r--swift/common/ring/ring.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/swift/common/ring/ring.py b/swift/common/ring/ring.py
index 8cbcaea67..5b315285a 100644
--- a/swift/common/ring/ring.py
+++ b/swift/common/ring/ring.py
@@ -24,6 +24,7 @@ import os
from io import BufferedReader
from hashlib import md5
from itertools import chain
+from tempfile import NamedTemporaryFile
from swift.common.utils import hash_path, validate_configuration, json
from swift.common.ring.utils import tiers_for_dev
@@ -108,12 +109,18 @@ class RingData(object):
#
# This only works on Python 2.7; on 2.6, we always get the
# current time in the gzip output.
+ tempf = NamedTemporaryFile(dir=".", prefix=filename, delete=False)
try:
- gz_file = GzipFile(filename, 'wb', mtime=1300507380.0)
+ gz_file = GzipFile(filename, mode='wb', fileobj=tempf,
+ mtime=1300507380.0)
except TypeError:
- gz_file = GzipFile(filename, 'wb')
+ gz_file = GzipFile(filename, mode='wb', fileobj=tempf)
self.serialize_v1(gz_file)
gz_file.close()
+ tempf.flush()
+ os.fsync(tempf.fileno())
+ tempf.close()
+ os.rename(tempf.name, filename)
def to_dict(self):
return {'devs': self.devs,