From cb5fa67f52ab82165d9cfcbe9a1e0b71b493cbbf Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 27 Jul 2004 15:47:38 +0000 Subject: [PATCH] Keep a version number in the state file, so we don't use state files from an incompatible version accidentally. --- NEWS | 3 +++ rawdoglib/rawdog.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/NEWS b/NEWS index 8c0435e..d56de05 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ internals; state files from old versions will no longer work with rawdog 2.0 (and external programs that manipulate rawdog state files will also be broken). +rawdog now keeps track of a version number in the state file, and will +complain if you use a state file from an incompatible version. + The old option syntax ("rawdog update write") is no longer supported. - rawdog 1.13 diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 9971ba8..da5e7e4 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -19,6 +19,7 @@ # MA 02111-1307 USA, or see http://www.gnu.org/. VERSION = "2.0rc1" +STATE_VERSION = 2 import feedparser from persister import Persistable, Persister import os, time, sha, getopt, sys, re, urlparse, cgi, socket, urllib2 @@ -548,6 +549,16 @@ class Rawdog(Persistable): def __init__(self): self.feeds = {} self.articles = {} + self.state_version = STATE_VERSION + + def check_state_version(self): + """Check the version of the state file.""" + try: + version = self.state_version + except AttributeError: + # rawdog 1.x didn't keep track of this. + version = 1 + return version == STATE_VERSION def list(self): for url in self.feeds.keys(): @@ -888,6 +899,12 @@ def main(argv): print "This usually means the file is corrupt, and removing it will fix the problem." return 1 + if not rawdog.check_state_version(): + print "The state file " + statedir + "/state was created by an older" + print "version of rawdog, and cannot be read by this version." + print "Removing the state file will fix it." + return 1 + for o, a in optlist: if o in ("-u", "--update"): rawdog.update(config) -- 2.35.1