Don't check for file type in _find_base_file
Firstly, _find_base_file was differentiating between 2 different types of 'non-original', but the caller was then treating them identically. This differentiation was obviously redundant. However, the caller was using them to populate originals. Note that _scan_base_files has been called previously, and therefore originals is already correctly populated. This means that _find_base_file does not need to identify 'originals' at all. Additionally, originals is only tracked at all so that 'originals' and 'non-originals' can be aged with different frequencies. This doesn't really make any sense anyway, so this is a small step towards removing a redundant config variable. Change-Id: I893cfe23b48ee135ac6c14870d50d7f734c25247
This commit is contained in:
@@ -258,7 +258,7 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
||||
res = list(image_cache_manager._find_base_file(base_dir, fingerprint))
|
||||
|
||||
base_file = os.path.join(base_dir, fingerprint + '_sm')
|
||||
self.assertEqual(res, [(base_file, True, False)])
|
||||
self.assertEqual([base_file], res)
|
||||
|
||||
def test_find_base_file_resized(self):
|
||||
fingerprint = '968dd6cc49e01aaa044ed11c0cce733e0fa44a6a'
|
||||
@@ -278,7 +278,7 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
||||
res = list(image_cache_manager._find_base_file(base_dir, fingerprint))
|
||||
|
||||
base_file = os.path.join(base_dir, fingerprint + '_10737418240')
|
||||
self.assertEqual(res, [(base_file, False, True)])
|
||||
self.assertEqual([base_file], res)
|
||||
|
||||
def test_find_base_file_all(self):
|
||||
fingerprint = '968dd6cc49e01aaa044ed11c0cce733e0fa44a6a'
|
||||
@@ -300,9 +300,7 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
||||
base_file1 = os.path.join(base_dir, fingerprint)
|
||||
base_file2 = os.path.join(base_dir, fingerprint + '_sm')
|
||||
base_file3 = os.path.join(base_dir, fingerprint + '_10737418240')
|
||||
self.assertEqual(res, [(base_file1, False, False),
|
||||
(base_file2, True, False),
|
||||
(base_file3, False, True)])
|
||||
self.assertEqual([base_file1, base_file2, base_file3], res)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _make_base_file(self, lock=True, info=False):
|
||||
|
||||
@@ -209,8 +209,7 @@ class ImageCacheManager(imagecache.ImageCacheManager):
|
||||
def _find_base_file(self, base_dir, fingerprint):
|
||||
"""Find the base file matching this fingerprint.
|
||||
|
||||
Yields the name of the base file, a boolean which is True if the image
|
||||
is "small", and a boolean which indicates if this is a resized image.
|
||||
Yields the name of a base file which exists.
|
||||
Note that it is possible for more than one yield to result from this
|
||||
check.
|
||||
|
||||
@@ -219,19 +218,19 @@ class ImageCacheManager(imagecache.ImageCacheManager):
|
||||
# The original file from glance
|
||||
base_file = os.path.join(base_dir, fingerprint)
|
||||
if os.path.exists(base_file):
|
||||
yield base_file, False, False
|
||||
yield base_file
|
||||
|
||||
# An older naming style which can be removed sometime after Folsom
|
||||
base_file = os.path.join(base_dir, fingerprint + '_sm')
|
||||
if os.path.exists(base_file):
|
||||
yield base_file, True, False
|
||||
yield base_file
|
||||
|
||||
# Resized images
|
||||
# Resized images (also legacy)
|
||||
resize_re = re.compile('.*/%s_[0-9]+$' % fingerprint)
|
||||
for img in self.unexplained_images:
|
||||
m = resize_re.match(img)
|
||||
if m:
|
||||
yield img, False, True
|
||||
yield img
|
||||
|
||||
@staticmethod
|
||||
def _get_age_of_file(base_file):
|
||||
@@ -358,13 +357,9 @@ class ImageCacheManager(imagecache.ImageCacheManager):
|
||||
LOG.debug('Image id %(id)s yields fingerprint %(fingerprint)s',
|
||||
{'id': img,
|
||||
'fingerprint': fingerprint})
|
||||
for result in self._find_base_file(base_dir, fingerprint):
|
||||
base_file, image_small, image_resized = result
|
||||
for base_file in self._find_base_file(base_dir, fingerprint):
|
||||
self._mark_in_use(img, base_file)
|
||||
|
||||
if not image_small and not image_resized:
|
||||
self.originals.append(base_file)
|
||||
|
||||
# Elements remaining in unexplained_images might be in use
|
||||
inuse_backing_images = self._list_backing_images()
|
||||
for backing_path in inuse_backing_images:
|
||||
|
||||
Reference in New Issue
Block a user