From c3d9a66ea751eb956cdad5d298895214187ed2eb Mon Sep 17 00:00:00 2001 From: gholt Date: Tue, 7 Jan 2014 23:58:47 +0000 Subject: [PATCH] Mute hash_suffix rmdir failures Change-Id: I10acfb1a3005ef988ac8a88819bf754b98cea63a --- swift/obj/diskfile.py | 5 ++++- test/unit/obj/test_diskfile.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index c9e5c7ccb8..49ef3b603d 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -196,7 +196,10 @@ def hash_suffix(path, reclaim_age): continue raise if not files: - os.rmdir(hsh_path) + try: + os.rmdir(hsh_path) + except OSError: + pass for filename in files: md5.update(filename) try: diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index 7ce39a1d62..491c88919e 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -185,6 +185,24 @@ class TestDiskFileModuleMethods(unittest.TestCase): # only the meta and data should be left self.assertEquals(len(os.listdir(whole_hsh_path)), 2) + def test_hash_suffix_hsh_path_disappearance(self): + orig_rmdir = os.rmdir + + def _rmdir(path): + # Done twice to recreate what happens when it doesn't exist. + orig_rmdir(path) + orig_rmdir(path) + + df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') + mkdirs(df._datadir) + ohash = hash_path('a', 'c', 'o') + suffix = ohash[-3:] + suffix_path = os.path.join(self.objects, '0', suffix) + with mock.patch('os.rmdir', _rmdir): + # If hash_suffix doesn't handle the exception _rmdir will raise, + # this test will fail. + diskfile.hash_suffix(suffix_path, 123) + def test_invalidate_hash(self): def assertFileData(file_path, data):