From 91c74810f2a6a13b11fea1f009298af84ecdd918 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 14 Apr 2009 07:25:01 +0000 Subject: [PATCH] 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. --- wcs/qommon/storage.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/wcs/qommon/storage.py b/wcs/qommon/storage.py index 10c8cedaf..c7ca3b4d0 100644 --- a/wcs/qommon/storage.py +++ b/wcs/qommon/storage.py @@ -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)