Merge "Cached file should not be deleted if time equal to master"
This commit is contained in:
commit
e75b51d6ef
@ -407,14 +407,15 @@ def _delete_master_path_if_stale(master_path, href, ctx):
|
|||||||
"cached image up to date."), {'href': href})
|
"cached image up to date."), {'href': href})
|
||||||
return True
|
return True
|
||||||
master_mtime = utils.unix_file_modification_datetime(master_path)
|
master_mtime = utils.unix_file_modification_datetime(master_path)
|
||||||
if img_mtime < master_mtime:
|
if img_mtime <= master_mtime:
|
||||||
return True
|
return True
|
||||||
# Delete image from cache as it is outdated
|
# Delete image from cache as it is outdated
|
||||||
LOG.info(_LI('Image %(href)s was last modified at %(remote_time)s. '
|
LOG.info(_LI('Image %(href)s was last modified at %(remote_time)s. '
|
||||||
'Deleting the cached copy since it was last modified at '
|
'Deleting the cached copy "%(cached_file)s since it was '
|
||||||
'%(local_time)s and may be outdated.'),
|
'last modified at %(local_time)s and may be outdated.'),
|
||||||
{'href': href, 'remote_time': img_mtime,
|
{'href': href, 'remote_time': img_mtime,
|
||||||
'local_time': master_mtime})
|
'local_time': master_mtime, 'cached_file': master_path})
|
||||||
|
|
||||||
os.unlink(master_path)
|
os.unlink(master_path)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -243,6 +243,22 @@ class TestUpdateImages(base.TestCase):
|
|||||||
self.assertFalse(mock_unlink.called)
|
self.assertFalse(mock_unlink.called)
|
||||||
self.assertTrue(res)
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
@mock.patch.object(image_service, 'get_image_service', autospec=True)
|
||||||
|
def test__delete_master_path_if_stale_master_same_time(self, mock_gis,
|
||||||
|
mock_unlink):
|
||||||
|
# When times identical should not delete cached file
|
||||||
|
touch(self.master_path)
|
||||||
|
mtime = utils.unix_file_modification_datetime(self.master_path)
|
||||||
|
href = 'http://awesomefreeimages.al/img999'
|
||||||
|
mock_gis.return_value.show.return_value = {
|
||||||
|
'updated_at': mtime
|
||||||
|
}
|
||||||
|
res = image_cache._delete_master_path_if_stale(self.master_path, href,
|
||||||
|
None)
|
||||||
|
mock_gis.assert_called_once_with(href, context=None)
|
||||||
|
self.assertFalse(mock_unlink.called)
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
@mock.patch.object(image_service, 'get_image_service', autospec=True)
|
@mock.patch.object(image_service, 'get_image_service', autospec=True)
|
||||||
def test__delete_master_path_if_stale_out_of_date(self, mock_gis,
|
def test__delete_master_path_if_stale_out_of_date(self, mock_gis,
|
||||||
mock_unlink):
|
mock_unlink):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user