backup

package
v0.0.50 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0, NCSA Imports: 6 Imported by: 2

Documentation

Overview

Package backup is a simple library for backing up a config file and restoring it using a temporary file.

Example usage:

tmp, err := backup.Save(someFile)
if err != nil {
   return fmt.Errorf("backing up %q: %v", somePath, err)
}
defer tmp.Release()
// ... do real work ...
tmp.Restore()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

A File records the locations of an original file and a backup copy of that file. The Restore method replaces the contents of the original with the backup, overwriting any changes that were made since the backup was created.

func New

func New(orig string) (*File, error)

New creates a backup copy of the specified file, located in the same directory. The caller should ensure the Release method is called when the backup is no longer needed, to clean up.

func (*File) GetDiff added in v0.0.49

func (f *File) GetDiff() (string, error)

GetDiff compares the modified file against the original and returns a diff.

func (*File) Release

func (f *File) Release()

Release removes the temporary file copy if it hasn't already been moved.

func (*File) Restore

func (f *File) Restore() error

Restore puts the original version of the backed up file back in place.

Jump to

Keyboard shortcuts

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