Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
4398768b
Commit
4398768b
authored
Sep 14, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: atomically update filter file
R=rsc CC=golang-dev
https://golang.org/cl/2206041
parent
bce8f51b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
src/cmd/godoc/godoc.go
src/cmd/godoc/godoc.go
+2
-4
src/cmd/godoc/utils.go
src/cmd/godoc/utils.go
+22
-0
No files found.
src/cmd/godoc/godoc.go
View file @
4398768b
...
...
@@ -170,10 +170,8 @@ func updateFilterFile() {
})
// update filter file
// TODO(gri) should write a tmp file and atomically rename
err
:=
ioutil
.
WriteFile
(
*
filter
,
buf
.
Bytes
(),
0666
)
if
err
!=
nil
{
log
.
Stderrf
(
"ioutil.Writefile(%s): %s"
,
*
filter
,
err
)
if
err
:=
writeFileAtomically
(
*
filter
,
buf
.
Bytes
());
err
!=
nil
{
log
.
Stderrf
(
"writeFileAtomically(%s): %s"
,
*
filter
,
err
)
filterDelay
.
backoff
(
24
*
60
)
// back off exponentially, but try at least once a day
}
else
{
filterDelay
.
set
(
*
filterMin
)
// revert to regular filter update schedule
...
...
src/cmd/godoc/utils.go
View file @
4398768b
...
...
@@ -7,6 +7,8 @@
package
main
import
(
"io"
"io/ioutil"
"os"
pathutil
"path"
"sort"
...
...
@@ -85,3 +87,23 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string {
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment