chiark / gitweb /
get and get-global now return 555 for not found. The Python interface
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 12:04:26 +0000 (12:04 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 12:04:26 +0000 (12:04 +0000)
understands this and returns None.

Further tests and fixes for disorder-dump.

doc/disorder_protocol.5.in
python/disorder.py.in
server/dump.c
server/server.c
tests/dump.py

index bf293e91b09461ada7c16297acd2fcdbbd78c510..b98c0f5ab787f16a13f1c75fd941d46eff31e090 100644 (file)
@@ -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.
index 01b92edbcdbc3bcc561c7b654456c87daf844344..2ad2b44f791c920f796f338a4032082e077ee469 100644 (file)
@@ -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)
 
index 9363a344a0d5ead7de6c78d3dd1a0f00bf2c37db..7e49111dca841b7e26dd0d952ffc64714dd894aa 100644 (file)
@@ -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) {
index c8b4a622d0238e6d5d255d088209d86e28b1677d..5d88db4f04aac15a2323c812c0eb763d3ba11388 100644 (file)
@@ -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;
 }
 
index 99d29b68626a15e3961e6f8714a8c9c128d0e9d4..d308b84ba054857c5c0296842cc7019f42eb8ac7 100755 (executable)
@@ -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()