提交 501d5338 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #618 from nouiz/clear_unversioned

fix clear_unversioned. When there is no key file, we should use the comp...
......@@ -266,15 +266,20 @@ def last_access_time(path):
return os.stat(path)[stat.ST_ATIME]
def module_name_from_dir(dirname):
def module_name_from_dir(dirname, err=True):
"""
Scan the contents of a cache directory and return full path of the
dynamic lib in it.
"""
files = os.listdir(dirname)
name, = [file for file in files
names = [file for file in files
if file.endswith('.so') or file.endswith('.pyd')]
return os.path.join(dirname, name)
if len(names) == 0 and not err:
return None
elif len(names) == 1:
return os.path.join(dirname, names[0])
else:
raise Exception("More then 1 compiled module in this directory!")
def is_same_entry(entry_1, entry_2):
......@@ -1249,8 +1254,22 @@ class ModuleCache(object):
except IOError:
has_key = False
if not has_key:
age = time_now - last_access_time(
os.path.join(self.dirname, filename))
# Use the compiled file by default
path = module_name_from_dir(os.path.join(self.dirname,
filename),
False)
# If it don't exist, use any file in the directory.
if path is None:
path = os.path.join(self.dirname, filename)
files = os.listdir(path)
if files:
path = os.path.join(path, files[0])
else:
# If the directory is empty skip it.
# They are deleted elsewhere.
continue
age = time_now - last_access_time(path)
# In normal case, the processus that created this
# directory will delete it. However, if this processus
# crashes, it will not be cleaned up.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论