mirror of
https://github.com/golang/go
synced 2024-11-25 22:07:58 -07:00
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
This commit is contained in:
parent
a64b69da9e
commit
5223218307
@ -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();
|
r, w, err := os.Pipe();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Stderrf("os.Pipe(): %v\n", err);
|
log.Stderrf("os.Pipe(): %v\n", err);
|
||||||
return false;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bin := args[0];
|
bin := args[0];
|
||||||
@ -67,7 +67,7 @@ func exec(c *http.Conn, args []string) bool {
|
|||||||
w.Close();
|
w.Close();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Stderrf("os.ForkExec(%q): %v\n", bin, err);
|
log.Stderrf("os.ForkExec(%q): %v\n", bin, err);
|
||||||
return false;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
@ -76,12 +76,13 @@ func exec(c *http.Conn, args []string) bool {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
os.Stderr.Write(buf.Bytes());
|
os.Stderr.Write(buf.Bytes());
|
||||||
log.Stderrf("os.Wait(%d, 0): %v\n", pid, err);
|
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());
|
os.Stderr.Write(buf.Bytes());
|
||||||
log.Stderrf("executing %v failed (exit status = %d)", args, wait.ExitStatus());
|
log.Stderrf("executing %v failed (exit status = %d)", args, status);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if *verbose {
|
if *verbose {
|
||||||
@ -92,18 +93,23 @@ func exec(c *http.Conn, args []string) bool {
|
|||||||
c.Write(buf.Bytes());
|
c.Write(buf.Bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func dosync(c *http.Conn, r *http.Request) {
|
func dosync(c *http.Conn, r *http.Request) {
|
||||||
args := []string{"/bin/sh", "-c", *syncCmd};
|
args := []string{"/bin/sh", "-c", *syncCmd};
|
||||||
if exec(c, args) {
|
switch exec(c, args) {
|
||||||
// sync succeeded
|
case 0:
|
||||||
|
// sync succeeded and some files have changed
|
||||||
syncTime.set(nil);
|
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
|
syncDelay.set(*syncMin); // revert to regular sync schedule
|
||||||
} else {
|
default:
|
||||||
// sync failed - back off exponentially, but try at least once a day
|
// sync failed because of an error - back off exponentially, but try at least once a day
|
||||||
syncDelay.backoff(24*60);
|
syncDelay.backoff(24*60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user