aghrenameio

package
v0.108.0-b.56 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package aghrenameio is a wrapper around package github.com/google/renameio/v2 that provides a similar stream-based API for both Unix and Windows systems. While the Windows API is not technically atomic, it still provides a consistent stream-based interface, and atomic renames of files do not seem to be possible in all cases anyway.

See https://github.com/google/renameio/issues/1.

TODO(a.garipov): Consider moving to golibs/renameioutil once tried and tested.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDeferredCleanup

func WithDeferredCleanup(returned error, file PendingFile) (err error)

WithDeferredCleanup is a helper that performs the necessary cleanups and finalizations of the temporary files based on the returned error.

Types

type PendingFile

type PendingFile interface {
	// Cleanup closes the file, and removes it without performing the renaming.
	// To close and rename the file, use CloseReplace.
	Cleanup() (err error)

	// CloseReplace closes the temporary file and replaces the destination file
	// with it, possibly atomically.
	//
	// This method is not safe for concurrent use by multiple goroutines.
	CloseReplace() (err error)

	// Write writes len(b) bytes from b to the File.  It returns the number of
	// bytes written and an error, if any.  Write returns a non-nil error when n
	// != len(b).
	Write(b []byte) (n int, err error)
}

PendingFile is the interface for pending temporary files.

func NewPendingFile

func NewPendingFile(filePath string, mode fs.FileMode) (f PendingFile, err error)

NewPendingFile is a wrapper around renameio.NewPendingFile on Unix systems and os.CreateTemp on Windows.

Jump to

Keyboard shortcuts

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