Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrOverWriteRejected = errors.New("overwrite rejected")
)
Functions ¶
func RestorePerm ¶ added in v0.3.0
RestorePerm restores the file permissions of a file that was replaced by safewrite.Open and finalized by Close.
This function is intended to be called explicitly *after* Close, using the value returned from Open as its argument.
safewrite does not automatically restore permissions during Close, because changing permissions immediately may cause subsequent overwrite operations within the same process to fail (for example, when a file becomes read-only after the first save).
By requiring an explicit call, applications can control when and whether the original permissions should be restored, such as once at process exit.
Types ¶
type BackupError ¶ added in v0.2.0
type BackupError struct {
Target string
Backup string
Err error
// Tmp is the path to a temporary file that may be left on disk
// when the backup operation fails.
// It is provided for diagnostic or recovery purposes and does not
// affect the error condition itself.
Tmp string
}
BackupError reports a failure that occurred while creating or replacing a backup file before overwriting the target file.
The error indicates that the original file was not replaced. In this case, a temporary file may remain on disk.
func (*BackupError) Error ¶ added in v0.2.0
func (e *BackupError) Error() string
func (*BackupError) Unwrap ¶ added in v0.2.0
func (e *BackupError) Unwrap() error
func (*BackupError) WorkingFile ¶ added in v0.2.0
func (e *BackupError) WorkingFile() string
type ReplaceError ¶ added in v0.2.0
ReplaceError is returned when replacing the target file with a temporary file fails during a safe overwrite operation.
It typically wraps an underlying *os.LinkError or filesystem-related error.
func (*ReplaceError) Error ¶ added in v0.2.0
func (e *ReplaceError) Error() string
func (*ReplaceError) Unwrap ¶ added in v0.2.0
func (e *ReplaceError) Unwrap() error
func (*ReplaceError) WorkingFile ¶ added in v0.2.0
func (e *ReplaceError) WorkingFile() string
type Status ¶ added in v0.3.0
type Status int
Status represents how a target file has been handled by safewrite within the current process.
It does NOT describe the state of the file on disk. Instead, it records the history of how the file was opened or replaced by safewrite during the lifetime of this process.
This information is primarily intended to help applications decide whether to prompt the user again for overwrite confirmation.
const ( // NONE indicates that, within the current process, safewrite has not yet // written to this file. // // This means there is no prior record of the file being created or // overwritten by safewrite in this process. NONE Status = iota // CREATE indicates that, within the current process, the file was previously // created using os.Create via safewrite.Open. // // In other words, the file did not exist at the time of the first write // performed by this process. CREATE // OVERWRITE indicates that, within the current process, an existing regular // file was previously replaced using a temporary file created by // os.CreateTemp and then renamed into place. // // This means safewrite has already performed a safe overwrite operation // for this file in this process. OVERWRITE )