def test_cleanup_disk(self): # Inject an item without a state.json, one is lost. Both will be deleted on # cleanup. self._free_disk = 1003 cache = self.get_cache(_get_policies(min_free_space=1000)) h_foo = self._algo('foo').hexdigest() self.assertEqual([], sorted(cache._lru._items.iteritems())) cache.write(h_foo, ['foo']) self.assertEqual([], cache.trim()) self.assertEqual([h_foo], [i[0] for i in cache._lru._items.iteritems()]) h_a = self._algo('a').hexdigest() local_caching.file_write(os.path.join(cache.cache_dir, h_a), 'a') # file_path.remove() explicitly handle the +R bit on Windows. file_path.remove(os.path.join(cache.cache_dir, h_foo)) # Still hasn't realized that the file is missing. self.assertEqual([h_foo], [i[0] for i in cache._lru._items.iteritems()]) self.assertEqual(sorted([h_a, cache.STATE_FILE]), sorted(fs.listdir(cache.cache_dir))) cache.cleanup() self.assertEqual([cache.STATE_FILE], fs.listdir(cache.cache_dir))
def test_cleanup(self): # Inject an item without a state.json, one is lost. Both will be deleted on # cleanup. self._free_disk = 1003 cache = self.get_cache() h_foo = hashlib.sha1('foo').hexdigest() self.assertEqual([], sorted(cache._lru._items.iteritems())) with cache: cache.write(h_foo, ['foo']) self.assertEqual([h_foo], [i[0] for i in cache._lru._items.iteritems()]) h_a = self.to_hash('a')[0] local_caching.file_write(os.path.join(cache.cache_dir, h_a), 'a') os.remove(os.path.join(cache.cache_dir, h_foo)) # Still hasn't realized that the file is missing. self.assertEqual([h_foo], [i[0] for i in cache._lru._items.iteritems()]) self.assertEqual(sorted([h_a, u'state.json']), sorted(os.listdir(cache.cache_dir))) cache.cleanup() self.assertEqual([u'state.json'], os.listdir(cache.cache_dir))