提交 13d1a703 authored 作者: Frederic's avatar Frederic

fix clear_unversioned. When there is no key file, we should use the compiled…

fix clear_unversioned. When there is no key file, we should use the compiled module to check the time. As we check access time, we won't delete them as we update the access time of the directory when we list it. It was working fine when we used the modification time.
上级 7fa8e678
...@@ -266,15 +266,20 @@ def last_access_time(path): ...@@ -266,15 +266,20 @@ def last_access_time(path):
return os.stat(path)[stat.ST_ATIME] 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 Scan the contents of a cache directory and return full path of the
dynamic lib in it. dynamic lib in it.
""" """
files = os.listdir(dirname) files = os.listdir(dirname)
name, = [file for file in files names = [file for file in files
if file.endswith('.so') or file.endswith('.pyd')] 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): def is_same_entry(entry_1, entry_2):
...@@ -1249,8 +1254,17 @@ class ModuleCache(object): ...@@ -1249,8 +1254,17 @@ class ModuleCache(object):
except IOError: except IOError:
has_key = False has_key = False
if not has_key: if not has_key:
age = time_now - last_access_time( # Use the compiled file by default
os.path.join(self.dirname, filename)) path = module_name_from_dir(os.path.join(self.dirname,
filename),
False)
# If it don't exist, use the directory to be sure
# to delete old stuff that could have been created
# by errors
if path is None:
path = os.path.join(self.dirname, filename)
age = time_now - last_access_time(path)
# In normal case, the processus that created this # In normal case, the processus that created this
# directory will delete it. However, if this processus # directory will delete it. However, if this processus
# crashes, it will not be cleaned up. # crashes, it will not be cleaned up.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论