Commit 498d499b authored by Laurent Bachelier's avatar Laurent Bachelier

Refresh everytime the file mtime is different

And not only when it is superior, though it should not happen.
(Actually it can happen with the DATA_PATHS mechanisms, as some files
with a lower mtime could be added to a directory with higher priority.)
parent a349a8f6
......@@ -41,7 +41,7 @@ class IObject(object):
def read(self):
mtime = self.storage._get_mtime(self._confname)
if self._mtime is None or self._mtime < mtime or self.is_modified():
if self._mtime is None or self._mtime != mtime or self.is_modified():
data = self.storage._read(self._confname)
self._mtime = mtime
self.exists = data is not None
......
......@@ -67,14 +67,16 @@ class AssetAction(Action):
mtime = int(os.path.getmtime(realpath))
# first look if there is a (read-only) gzipped version of the asset
# these files may be created by installers and are supposed to be
# always up to date
realpath_gz = realpath+'.gz'
if os.path.exists(realpath_gz) and not mtime > os.path.getmtime(realpath_gz):
if os.path.exists(realpath_gz):
return realpath_gz
# then look for a local cache of that asset, if not present, create it
cachedir = os.path.join(self.ctx.storage.path, 'assets_cache')
dest = os.path.join(cachedir, filename+'.gz')
if not os.path.exists(dest) or mtime > int(os.path.getmtime(dest)):
if not os.path.exists(dest) or mtime != int(os.path.getmtime(dest)):
if not os.path.isdir(cachedir):
os.makedirs(cachedir)
with open(realpath, 'rb') as f_in:
......
......@@ -74,7 +74,7 @@ class DownloadThumbnailAction(ViewAction):
f.save()
mtime = int(os.path.getmtime(f.get_realpath()))
if not os.path.exists(thumbpath) or mtime > int(os.path.getmtime(thumbpath)):
if not os.path.exists(thumbpath) or mtime != int(os.path.getmtime(thumbpath)):
if not os.path.isdir(os.path.dirname(thumbpath)):
os.makedirs(os.path.dirname(thumbpath))
with open(f.get_realpath(), 'rb') as fp:
......
......@@ -129,7 +129,7 @@ class StorageTest(TestCase):
# cheat: alter the mtime of the saved file
cfg2.data['penguin']['gentoo'] = u"666"
cfg2.save()
mtime = cfg2._mtime - 9000
mtime = cfg._mtime
os.utime(os.path.join(self.storage.path, cfg._get_confname()), (mtime, mtime))
cfg.read()
# the file was NOT reloaded
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment