postgres_exporter/tools/vendor/github.com/dchest/safefile
Will Rouesnel e2b6c973a1 Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
..
LICENSE Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
README.md Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
appveyor.yml Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
rename.go Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
rename_nonatomic.go Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00
safefile.go Add self-contained gometalinter build tooling. 2017-06-07 00:53:19 +10:00

README.md

safefile

Build Status Windows Build status

Go package safefile implements safe "atomic" saving of files.

Instead of truncating and overwriting the destination file, it creates a temporary file in the same directory, writes to it, and then renames the temporary file to the original name when calling Commit.

Installation

$ go get github.com/dchest/safefile

Documentation

https://godoc.org/github.com/dchest/safefile

Example

f, err := safefile.Create("/home/ken/report.txt", 0644)
if err != nil {
	// ...
}
// Created temporary file /home/ken/sf-ppcyksu5hyw2mfec.tmp

defer f.Close()

_, err = io.WriteString(f, "Hello world")
if err != nil {
	// ...
}
// Wrote "Hello world" to /home/ken/sf-ppcyksu5hyw2mfec.tmp

err = f.Commit()
if err != nil {
    // ...
}
// Renamed /home/ken/sf-ppcyksu5hyw2mfec.tmp to /home/ken/report.txt