check_download_cache

astropy.utils.data.check_download_cache(check_hashes=False, pkgname='astropy')[source]

Do a consistency check on the cache.

Because the cache is shared by all versions of astropy in all virtualenvs run by your user, possibly concurrently, it could accumulate problems. This could lead to hard-to-debug problems or wasted space. This function detects a number of incorrect conditions, including nonexistent files that are indexed, files that are indexed but in the wrong place, and, if you request it, files whose content does not match the hash that is indexed.

This function also returns a list of non-indexed files. A few will be associated with the shelve object; their exact names depend on the backend used but will probably be based on urlmap. The presence of other files probably indicates that something has gone wrong and inaccessible files have accumulated in the cache. These can be removed with clear_download_cache, either passing the filename returned here, or with no arguments to empty the entire cache and return it to a reasonable, if empty, state.

Parameters
check_hashesbool, optional

Whether to compute the hashes of the contents of all files in the cache and compare them to the names. This can take some time if the cache contains large files.

pkgnamestr, optional

The package name to use to locate the download cache. i.e. for pkgname='astropy' the default cache location is ~/.astropy/cache.

Returns
straysset of strings

This is the set of files in the cache directory that do not correspond to known URLs. This may include some files associated with the cache index.

Raises
CacheDamaged

To indicate a problem with the cache contents; the exception contains a .bad_url or a .bad_file attribute to allow the user to use clear_download_cache to remove the offending item.

OSError, RuntimeError

To indicate some problem with the cache structure. This may need a full clear_download_cache to resolve, or may indicate some kind of misconfiguration.