Do not fail in last_modified if file is absent

* wcs/qommon/storage.py:
   in last_modified generic implementations do not fail when stat fails
   (usually because the file/directory does not exist), instead return
   current time.
This commit is contained in:
Benjamin Dauvergne 2009-04-14 07:25:01 +00:00
parent b0467928df
commit 91c74810f2
1 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import os
import time
import pickle
from quixote import get_publisher
@ -332,11 +333,21 @@ class StorableObject(object):
def last_modified_id(cls, id):
filename = os.path.join(cls.get_objects_dir(), fix_key(id))
stat = os.stat(filename)
return stat.st_mtime
mtime = 0
try:
stat = os.stat(filename)
mtime = stat.st_mtime
except OSError:
mtime = int(time.time())
return mtime
last_modified_id = classmethod(last_modified_id)
def last_modified(cls):
stat = os.stat(cls.get_objects_dir())
return stat.st_mtime
mtime = 0
try:
stat = os.stat(cls.get_objects_dir())
mtime = stat.st_mtime
except OSError:
mtime = int(time.time())
return mtime
last_modified = classmethod(last_modified)