// Note that when trying to Commit again after a failed Commit when the file
// has been closed, but not renamed to its original name (the new commit will
// try again to rename it), safefile cannot guarantee that the temporary file
// has not been changed, or that it is the same temporary file we were dealing
// with.  However, since the temporary name is unpredictable, it is unlikely
// that this happened accidentally. If complete atomicity is needed, do not
// Commit again after error, write the file again.

Note that when trying to Commit again after a failed Commit when the file
has been closed, but not renamed to its original name (the new commit will
try again to rename it), safefile cannot guarantee that the temporary file
has not been changed, or that it is the same temporary file we were dealing
with.  However, since the temporary name is unpredictable, it is unlikely
that this happened accidentally. If complete atomicity is needed, do not
Commit again after error, write the file again.
// Note that when trying to Commit again after a failed Commit when the file // has been closed but not renamed to its original name ( the new commit will // try again to rename it ) safefile cannot guarantee that the temporary file // has not been changed or that it is the same temporary file we were dealing // with . However since the temporary name is unpredictable it is unlikely // that this happened accidentally . If complete atomicity is needed do not // Commit again after error write the file again .
func (f *File) Commit() error {
	if f.isCommitted {
		return ErrAlreadyCommitted
	}
	if !f.isClosed {
		err := f.Sync()
		if err != nil {
			return err
		}
		err = f.File.Close()
		if err != nil {
			return err
		}
		f.isClosed = true
	}
	err := rename(f.Name(), f.origName)
	if err != nil {
		f.closeFunc = closeAfterFailedRename
		return err
	}
	f.closeFunc = closeCommitted
	f.isCommitted = true
	return nil
}
func ( f * File ) Commit ( ) error { if f . isCommitted { return ErrAlreadyCommitted } if ! f . isClosed { err := f . Sync ( ) if err != nil { return err } err = f . File . Close ( ) if err != nil { return err } f . isClosed = true } err := rename ( f . Name ( ) , f . origName ) if err != nil { f . closeFunc = closeAfterFailedRename return err } f . closeFunc = closeCommitted f . isCommitted = true return nil }
Note that when trying to Commit again after a failed Commit when the file
has been closed, but not renamed to its original name (the new commit will
try again to rename it), safefile cannot guarantee that the temporary file
has not been changed, or that it is the same temporary file we were dealing
with.
Note that when trying to Commit again after a failed Commit when the file has been closed but not renamed to its original name ( the new commit will try again to rename it ) safefile cannot guarantee that the temporary file has not been changed or that it is the same temporary file we were dealing with .
// Sync to disk.
 // Close underlying os.File.
 // Rename.
