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:
parent
b0467928df
commit
91c74810f2
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
from quixote import get_publisher
|
from quixote import get_publisher
|
||||||
|
@ -332,11 +333,21 @@ class StorableObject(object):
|
||||||
|
|
||||||
def last_modified_id(cls, id):
|
def last_modified_id(cls, id):
|
||||||
filename = os.path.join(cls.get_objects_dir(), fix_key(id))
|
filename = os.path.join(cls.get_objects_dir(), fix_key(id))
|
||||||
stat = os.stat(filename)
|
mtime = 0
|
||||||
return stat.st_mtime
|
try:
|
||||||
|
stat = os.stat(filename)
|
||||||
|
mtime = stat.st_mtime
|
||||||
|
except OSError:
|
||||||
|
mtime = int(time.time())
|
||||||
|
return mtime
|
||||||
last_modified_id = classmethod(last_modified_id)
|
last_modified_id = classmethod(last_modified_id)
|
||||||
|
|
||||||
def last_modified(cls):
|
def last_modified(cls):
|
||||||
stat = os.stat(cls.get_objects_dir())
|
mtime = 0
|
||||||
return stat.st_mtime
|
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)
|
last_modified = classmethod(last_modified)
|
||||||
|
|
Loading…
Reference in New Issue