1- package ioutils // import "github.com/docker/docker/pkg/ioutils"
1+ package atomicwriter
22
33import (
44 "io"
55 "os"
66 "path/filepath"
77)
88
9- // NewAtomicFileWriter returns WriteCloser so that writing to it writes to a
9+ // New returns a WriteCloser so that writing to it writes to a
1010// temporary file and closing it atomically changes the temporary file to
1111// destination path. Writing and closing concurrently is not allowed.
1212// NOTE: umask is not considered for the file's permissions.
13- func NewAtomicFileWriter (filename string , perm os.FileMode ) (io.WriteCloser , error ) {
13+ func New (filename string , perm os.FileMode ) (io.WriteCloser , error ) {
1414 f , err := os .CreateTemp (filepath .Dir (filename ), ".tmp-" + filepath .Base (filename ))
1515 if err != nil {
1616 return nil , err
@@ -27,10 +27,10 @@ func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, err
2727 }, nil
2828}
2929
30- // AtomicWriteFile atomically writes data to a file named by filename and with the specified permission bits.
30+ // WriteFile atomically writes data to a file named by filename and with the specified permission bits.
3131// NOTE: umask is not considered for the file's permissions.
32- func AtomicWriteFile (filename string , data []byte , perm os.FileMode ) error {
33- f , err := NewAtomicFileWriter (filename , perm )
32+ func WriteFile (filename string , data []byte , perm os.FileMode ) error {
33+ f , err := New (filename , perm )
3434 if err != nil {
3535 return err
3636 }
@@ -82,32 +82,32 @@ func (w *atomicFileWriter) Close() (retErr error) {
8282 return nil
8383}
8484
85- // AtomicWriteSet is used to atomically write a set
85+ // WriteSet is used to atomically write a set
8686// of files and ensure they are visible at the same time.
8787// Must be committed to a new directory.
88- type AtomicWriteSet struct {
88+ type WriteSet struct {
8989 root string
9090}
9191
92- // NewAtomicWriteSet creates a new atomic write set to
92+ // NewWriteSet creates a new atomic write set to
9393// atomically create a set of files. The given directory
9494// is used as the base directory for storing files before
9595// commit. If no temporary directory is given the system
9696// default is used.
97- func NewAtomicWriteSet (tmpDir string ) (* AtomicWriteSet , error ) {
97+ func NewWriteSet (tmpDir string ) (* WriteSet , error ) {
9898 td , err := os .MkdirTemp (tmpDir , "write-set-" )
9999 if err != nil {
100100 return nil , err
101101 }
102102
103- return & AtomicWriteSet {
103+ return & WriteSet {
104104 root : td ,
105105 }, nil
106106}
107107
108108// WriteFile writes a file to the set, guaranteeing the file
109109// has been synced.
110- func (ws * AtomicWriteSet ) WriteFile (filename string , data []byte , perm os.FileMode ) error {
110+ func (ws * WriteSet ) WriteFile (filename string , data []byte , perm os.FileMode ) error {
111111 f , err := ws .FileWriter (filename , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , perm )
112112 if err != nil {
113113 return err
@@ -136,7 +136,7 @@ func (w syncFileCloser) Close() error {
136136
137137// FileWriter opens a file writer inside the set. The file
138138// should be synced and closed before calling commit.
139- func (ws * AtomicWriteSet ) FileWriter (name string , flag int , perm os.FileMode ) (io.WriteCloser , error ) {
139+ func (ws * WriteSet ) FileWriter (name string , flag int , perm os.FileMode ) (io.WriteCloser , error ) {
140140 f , err := os .OpenFile (filepath .Join (ws .root , name ), flag , perm )
141141 if err != nil {
142142 return nil , err
@@ -146,18 +146,18 @@ func (ws *AtomicWriteSet) FileWriter(name string, flag int, perm os.FileMode) (i
146146
147147// Cancel cancels the set and removes all temporary data
148148// created in the set.
149- func (ws * AtomicWriteSet ) Cancel () error {
149+ func (ws * WriteSet ) Cancel () error {
150150 return os .RemoveAll (ws .root )
151151}
152152
153153// Commit moves all created files to the target directory. The
154154// target directory must not exist and the parent of the target
155155// directory must exist.
156- func (ws * AtomicWriteSet ) Commit (target string ) error {
156+ func (ws * WriteSet ) Commit (target string ) error {
157157 return os .Rename (ws .root , target )
158158}
159159
160160// String returns the location the set is writing to.
161- func (ws * AtomicWriteSet ) String () string {
161+ func (ws * WriteSet ) String () string {
162162 return ws .root
163163}
0 commit comments