mirror of
https://github.com/golang/go
synced 2024-11-22 02:14:40 -07:00
godoc: atomically update filter file
R=rsc CC=golang-dev https://golang.org/cl/2206041
This commit is contained in:
parent
bce8f51b2b
commit
4398768b84
@ -170,10 +170,8 @@ func updateFilterFile() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// update filter file
|
// update filter file
|
||||||
// TODO(gri) should write a tmp file and atomically rename
|
if err := writeFileAtomically(*filter, buf.Bytes()); err != nil {
|
||||||
err := ioutil.WriteFile(*filter, buf.Bytes(), 0666)
|
log.Stderrf("writeFileAtomically(%s): %s", *filter, err)
|
||||||
if err != nil {
|
|
||||||
log.Stderrf("ioutil.Writefile(%s): %s", *filter, err)
|
|
||||||
filterDelay.backoff(24 * 60) // back off exponentially, but try at least once a day
|
filterDelay.backoff(24 * 60) // back off exponentially, but try at least once a day
|
||||||
} else {
|
} else {
|
||||||
filterDelay.set(*filterMin) // revert to regular filter update schedule
|
filterDelay.set(*filterMin) // revert to regular filter update schedule
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
pathutil "path"
|
pathutil "path"
|
||||||
"sort"
|
"sort"
|
||||||
@ -85,3 +87,23 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string {
|
|||||||
|
|
||||||
return list[0:i]
|
return list[0:i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// writeFileAtomically writes data to a temporary file and then
|
||||||
|
// atomically renames that file to the file named by filename.
|
||||||
|
//
|
||||||
|
func writeFileAtomically(filename string, data []byte) os.Error {
|
||||||
|
f, err := ioutil.TempFile(cwd, filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n, err := f.Write(data)
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if n < len(data) {
|
||||||
|
return io.ErrShortWrite
|
||||||
|
}
|
||||||
|
return os.Rename(f.Name(), filename)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user