From: Robert Griesemer Date: Sun, 1 Nov 2009 18:33:16 +0000 (-0800) Subject: don't update sync time if no files have changed X-Git-Tag: weekly.2009-11-06~158 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=522321830748a99347453d94a282940562427ea1;p=gostls13.git don't update sync time if no files have changed (and thus avoid re-indexing after every sync attempt) R=rsc http://go/go-review/1016010 --- diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index b30b589987..1d4617a465 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -50,11 +50,11 @@ var ( ) -func exec(c *http.Conn, args []string) bool { +func exec(c *http.Conn, args []string) (status int) { r, w, err := os.Pipe(); if err != nil { log.Stderrf("os.Pipe(): %v\n", err); - return false; + return 2; } bin := args[0]; @@ -67,7 +67,7 @@ func exec(c *http.Conn, args []string) bool { w.Close(); if err != nil { log.Stderrf("os.ForkExec(%q): %v\n", bin, err); - return false; + return 2; } var buf bytes.Buffer; @@ -76,12 +76,13 @@ func exec(c *http.Conn, args []string) bool { if err != nil { os.Stderr.Write(buf.Bytes()); log.Stderrf("os.Wait(%d, 0): %v\n", pid, err); - return false; + return 2; } - if !wait.Exited() || wait.ExitStatus() != 0 { + status = wait.ExitStatus(); + if !wait.Exited() || status > 1 { os.Stderr.Write(buf.Bytes()); - log.Stderrf("executing %v failed (exit status = %d)", args, wait.ExitStatus()); - return false; + log.Stderrf("executing %v failed (exit status = %d)", args, status); + return; } if *verbose { @@ -92,18 +93,23 @@ func exec(c *http.Conn, args []string) bool { c.Write(buf.Bytes()); } - return true; + return; } func dosync(c *http.Conn, r *http.Request) { args := []string{"/bin/sh", "-c", *syncCmd}; - if exec(c, args) { - // sync succeeded + switch exec(c, args) { + case 0: + // sync succeeded and some files have changed syncTime.set(nil); + fallthrough; + case 1: + // sync failed because no files changed + // don't change the sync time syncDelay.set(*syncMin); // revert to regular sync schedule - } else { - // sync failed - back off exponentially, but try at least once a day + default: + // sync failed because of an error - back off exponentially, but try at least once a day syncDelay.backoff(24*60); } }