Skip to content

Commit eb05a2b

Browse files
committed
Create temporary file with .html extension in OpenReader
Rather than creating a temporary file and then renaming it to have a .html extension, create the temporary file with the extension directly.
1 parent a7b7a61 commit eb05a2b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

browser.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func OpenFile(path string) error {
3030
// OpenReader consumes the contents of r and presents the
3131
// results in a new browser window.
3232
func OpenReader(r io.Reader) error {
33-
f, err := ioutil.TempFile("", "browser")
33+
f, err := ioutil.TempFile("", "browser.*.html")
3434
if err != nil {
3535
return fmt.Errorf("browser: could not create temporary file: %v", err)
3636
}
@@ -41,12 +41,7 @@ func OpenReader(r io.Reader) error {
4141
if err := f.Close(); err != nil {
4242
return fmt.Errorf("browser: caching temporary file failed: %v", err)
4343
}
44-
oldname := f.Name()
45-
newname := oldname + ".html"
46-
if err := os.Rename(oldname, newname); err != nil {
47-
return fmt.Errorf("browser: renaming temporary file failed: %v", err)
48-
}
49-
return OpenFile(newname)
44+
return OpenFile(f.Name())
5045
}
5146

5247
// OpenURL opens a new browser window pointing to url.

0 commit comments

Comments
 (0)