diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index f7d8023c01..707783215a 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -74,7 +74,7 @@ def read_metadata(fd): """ Helper function to read the pickled metadata from an object file. - :param fd: file descriptor to load the metadata from + :param fd: file descriptor or filename to load the metadata from :returns: dictionary of metadata """ @@ -93,7 +93,7 @@ def write_metadata(fd, metadata): """ Helper function to write pickled metadata for an object file. - :param fd: file descriptor to write the metadata + :param fd: file descriptor or filename to write the metadata :param metadata: metadata to write """ metastr = pickle.dumps(metadata, PICKLE_PROTOCOL) @@ -849,8 +849,7 @@ class DiskFile(object): if not ts_file: exc = DiskFileNotExist() else: - with open(ts_file) as fp: - metadata = read_metadata(fp) + metadata = read_metadata(ts_file) # All well and good that we have found a tombstone file, but # we don't have a data file so we are just going to raise an # exception that we could not find the object, providing the @@ -941,8 +940,7 @@ class DiskFile(object): fp = open(data_file, 'rb') datafile_metadata = read_metadata(fp) if meta_file: - with open(meta_file) as mfp: - self._metadata = read_metadata(mfp) + self._metadata = read_metadata(meta_file) sys_metadata = dict( [(key, val) for key, val in datafile_metadata.iteritems() if key.lower() in DATAFILE_SYSTEM_META]) diff --git a/test/probe/test_object_failures.py b/test/probe/test_object_failures.py index fe5ee17eb6..4ad8a28af1 100755 --- a/test/probe/test_object_failures.py +++ b/test/probe/test_object_failures.py @@ -67,11 +67,9 @@ class TestObjectFailures(TestCase): obj = 'object-%s' % uuid4() onode, opart, data_file = self._setup_data_file(container, obj, 'VERIFY') - with open(data_file) as fpointer: - metadata = read_metadata(fpointer) + metadata = read_metadata(data_file) metadata['ETag'] = 'badetag' - with open(data_file) as fpointer: - write_metadata(fpointer, metadata) + write_metadata(data_file, metadata) odata = direct_client.direct_get_object( onode, opart, self.account, container, obj)[-1] @@ -88,11 +86,10 @@ class TestObjectFailures(TestCase): obj = 'object-range-%s' % uuid4() onode, opart, data_file = self._setup_data_file(container, obj, 'RANGE') - with open(data_file) as fpointer: - metadata = read_metadata(fpointer) + + metadata = read_metadata(data_file) metadata['ETag'] = 'badetag' - with open(data_file) as fpointer: - write_metadata(fpointer, metadata) + write_metadata(data_file, metadata) for header, result in [({'Range': 'bytes=0-2'}, 'RAN'), ({'Range': 'bytes=1-11'}, 'ANGE'), ({'Range': 'bytes=0-11'}, 'RANGE')]: @@ -111,8 +108,7 @@ class TestObjectFailures(TestCase): container = 'container-zbyte-%s' % uuid4() obj = 'object-zbyte-%s' % uuid4() onode, opart, data_file = self._setup_data_file(container, obj, 'DATA') - with open(data_file) as fpointer: - metadata = read_metadata(fpointer) + metadata = read_metadata(data_file) unlink(data_file) with open(data_file, 'w') as fpointer: @@ -129,8 +125,7 @@ class TestObjectFailures(TestCase): container = 'container-zbyte-%s' % uuid4() obj = 'object-zbyte-%s' % uuid4() onode, opart, data_file = self._setup_data_file(container, obj, 'DATA') - with open(data_file) as fpointer: - metadata = read_metadata(fpointer) + metadata = read_metadata(data_file) unlink(data_file) with open(data_file, 'w') as fpointer: @@ -147,8 +142,7 @@ class TestObjectFailures(TestCase): container = 'container-zbyte-%s' % uuid4() obj = 'object-zbyte-%s' % uuid4() onode, opart, data_file = self._setup_data_file(container, obj, 'DATA') - with open(data_file) as fpointer: - metadata = read_metadata(fpointer) + metadata = read_metadata(data_file) unlink(data_file) with open(data_file, 'w') as fpointer: