From: Adam Sampson Date: Sun, 26 Jan 2014 19:22:06 +0000 (+0000) Subject: When renaming a splitstate file, don't fail if it doesn't exist. X-Git-Tag: v2.19~2 X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=da122cbdc16210118f37501b818f78b24d7c86d6;p=rawdog%2F.git When renaming a splitstate file, don't fail if it doesn't exist. This has just occurred to me when a feed got a redirect on its first fetch. Also rename the lock file along with the state file. --- diff --git a/NEWS b/NEWS index 1513ab0..7be35f5 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ Make test-rawdog not depend on having a host it can test connection timeouts against, and add a -T option if you do have one. +When renaming a feed's state file in splitstate mode, don't fail if the +state file doesn't exist -- which can happen if we get a 301 response +for a feed the first time we fetch it. Also rename the lock file along +with the state file. + Add some more comprehensive tests for the changeconfig option; in particular, test it more thoroughly with splitstate both on and off. diff --git a/rawdoglib/persister.py b/rawdoglib/persister.py index bda6c75..40169da 100644 --- a/rawdoglib/persister.py +++ b/rawdoglib/persister.py @@ -1,5 +1,5 @@ # persister: persist Python objects safely to pickle files -# Copyright 2003, 2004, 2005, 2013 Adam Sampson +# Copyright 2003, 2004, 2005, 2013, 2014 Adam Sampson # # rawdog is free software; you can redistribute and/or modify it # under the terms of that license as published by the Free Software @@ -52,7 +52,15 @@ class Persisted: currently open or not.""" self.persister._rename(self.filename, new_filename) - os.rename(self.filename, new_filename) + for ext in ("", ".lock"): + try: + os.rename(self.filename + ext, + new_filename + ext) + except OSError, e: + # If the file doesn't exist (yet), + # that's OK. + if e.errno != errno.ENOENT: + raise e self.filename = new_filename def __enter__(self): @@ -177,8 +185,8 @@ class Persister: def delete(self, filename): """Delete a persisted file, along with its lock file, if they exist.""" - for fn in (filename, filename + ".lock"): + for ext in ("", ".lock"): try: - os.unlink(fn) + os.unlink(filename + ext) except OSError: pass