writefile

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2018 License: LGPL-3.0 Imports: 5 Imported by: 2

Documentation

Overview

Package writefile provides simple support routines for writing data to a temporary file before renaming it into place. This avoids pitfalls such as writing partial content to a file and then being interruted, or trying to write to a program that is currently being executed, etc.

This package will correctly dereference symlinks and in the case of overwriting will retain permissions from the original, underlying file.

Index

Constants

View Source
const (
	// MaxSymlinkDeref is the maximum number of symlinks that we will
	// dereference before giving up.
	MaxSymlinkDeref = 16
)

Variables

This section is empty.

Functions

func Abort

func Abort(f *os.File)

Abort writing to a file. Performs a Close() and unlinks the temporary file.

func Commit

func Commit(finalFname string, f *os.File) error

Commit the temporary file. This will close the file f and then rename it into place once it has been ensured the data is on disk. It will retain permissions from the original file if present.

func New

func New(targetFname string) (finalFname string, f *os.File, err error)

New opens a file for writing. It returns the final filename which should be passed to Commit; this may differ from the passed target filename if the target is actually a symlink.

Any existing file will not be altered in any way until Commit() is called. Data will be written to a temporary file in the same directory as the target.

func NewNoDeref

func NewNoDeref(finalFname string) (*os.File, error)

NewNoDeref is similar to New, but will not dereference symlinks and will allow them to be overwritten.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL