From: Richard Kettlewell Date: Sun, 2 Dec 2007 12:04:26 +0000 (+0000) Subject: get and get-global now return 555 for not found. The Python interface X-Git-Tag: 1.5.99+dev10~29 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/fb1bc1f52d207b6405c966840dd46560c8bec739 get and get-global now return 555 for not found. The Python interface understands this and returns None. Further tests and fixes for disorder-dump. --- diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index bf293e9..b98c0f5 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -83,9 +83,13 @@ If \fIREGEXP\fR is present only matching files are returned. .B get \fITRACK\fR \fIPREF\fR Gets a preference value. On success the second field of the response line will have the value. +.IP +If the track or preference do not exist then the response code is 555. .TP .B get-global \fIKEY\fR Get a global preference. +.IP +If the preference does not exist then the response code is 555. .TP .B length \fITRACK\fR Gets the length of the track in seconds. On success the second field of the @@ -293,6 +297,10 @@ Text part is just commentary; a dot-stuffed body follows. Text part is just commentary; an indefinite dot-stuffed body follows. (Used for \fBlog\fR.) .TP +.B 5 +Used with "normal" errors, for instance a preference not being found. The text +part is commentary. +.TP .B 9 The text part is just commentary (but would normally be a response for this command) e.g. \fBplaying\fR. diff --git a/python/disorder.py.in b/python/disorder.py.in index 01b92ed..2ad2b44 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -585,7 +585,10 @@ class client: The return value is the preference """ ret, details = self._simple("get", track, key) - return details + if ret == 555: + return None + else: + return details def prefs(self, track): """Get all the preferences for a track. @@ -781,7 +784,10 @@ class client: The return value is the preference """ ret, details = self._simple("get-global", key) - return details + if ret == 555: + return None + else: + return details ######################################################################## # I/O infrastructure @@ -837,7 +843,7 @@ class client: # # If an I/O error occurs, disconnect from the server. # - # On success returns response as a (code, details) tuple + # On success or 'normal' errors returns response as a (code, details) tuple # # On error raise operationError if self.state == 'disconnected': @@ -847,7 +853,7 @@ class client: else: cmd = None res, details = self._response() - if res / 100 == 2: + if res / 100 == 2 or res == 555: return res, details raise operationError(res, details, cmd) diff --git a/server/dump.c b/server/dump.c index 9363a34..7e49111 100644 --- a/server/dump.c +++ b/server/dump.c @@ -281,7 +281,9 @@ static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) { if(fseek(fp, 0, SEEK_SET) < 0) fatal(errno, "error calling fseek on %s", tag); if((err = truncdb(tid, trackdb_prefsdb))) return err; + if((err = truncdb(tid, trackdb_globaldb))) return err; if((err = truncdb(tid, trackdb_searchdb))) return err; + if((err = truncdb(tid, trackdb_tagsdb))) return err; c = getc(fp); while(!ferror(fp) && !feof(fp)) { switch(c) { diff --git a/server/server.c b/server/server.c index c8b4a62..5d88db4 100644 --- a/server/server.c +++ b/server/server.c @@ -580,7 +580,7 @@ static int c_get(struct conn *c, if(vec[1][0] != '_' && (v = trackdb_get(vec[0], vec[1]))) sink_printf(ev_writer_sink(c->w), "252 %s\n", v); else - sink_writes(ev_writer_sink(c->w), "550 not found\n"); + sink_writes(ev_writer_sink(c->w), "555 not found\n"); return 1; } @@ -924,7 +924,7 @@ static int c_get_global(struct conn *c, if(s) sink_printf(ev_writer_sink(c->w), "252 %s\n", s); else - sink_writes(ev_writer_sink(c->w), "550 not found\n"); + sink_writes(ev_writer_sink(c->w), "555 not found\n"); return 1; } diff --git a/tests/dump.py b/tests/dump.py index 99d29b6..d308b84 100755 --- a/tests/dump.py +++ b/tests/dump.py @@ -41,6 +41,10 @@ def test(): print "changing global pref" c.setglobal("foo", "after"); assert c.getglobal("foo") == "after", "checking global foo=before" + print "adding fresh track pref" + c.set(track, "bar", "after") + print "adding fresh global pref" + c.setglobal("bar", "after") dtest.stop_daemon(); print "restoring database" print dtest.command(["disorder-dump", "--config", disorder._configfile, @@ -51,6 +55,10 @@ def test(): assert c.get(track, "foo") == "before", "checking track foo=before after undump" print "checking global pref" assert c.getglobal("foo") == "before", "checking global foo=before after undump" + print "checking fresh track pref" + assert c.get(track, "bar") is None, "checking fresh track pref has gone" + print "checking fresh global pref" + assert c.getglobal("bar") is None, "checking fresh global pref has gone" if __name__ == '__main__': dtest.run()