diff --git a/go.mod b/go.mod index f297c36d..2822e5ad 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/coreos/ignition/v2 -go 1.25 +go 1.24.0 + +toolchain go1.24.1 require ( cloud.google.com/go/compute/metadata v0.9.0 @@ -17,7 +19,7 @@ require ( github.com/coreos/go-semver v0.3.1 github.com/coreos/go-systemd/v22 v22.6.0 github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 - github.com/google/renameio/v2 v2.0.2 + github.com/google/renameio/v2 v2.0.1 github.com/google/uuid v1.6.0 github.com/mdlayher/vsock v1.2.1 github.com/mitchellh/copystructure v1.2.0 diff --git a/go.sum b/go.sum index cbe0a830..fd027529 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc= github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0= -github.com/google/renameio/v2 v2.0.2 h1:qKZs+tfn+arruZZhQ7TKC/ergJunuJicWS6gLDt/dGw= -github.com/google/renameio/v2 v2.0.2/go.mod h1:OX+G6WHHpHq3NVj7cAOleLOwJfcQ1s3uUJQCrr78SWo= +github.com/google/renameio/v2 v2.0.1 h1:HyOM6qd9gF9sf15AvhbptGHUnaLTpEI9akAFFU3VyW0= +github.com/google/renameio/v2 v2.0.1/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4= github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= diff --git a/vendor/github.com/google/renameio/v2/option.go b/vendor/github.com/google/renameio/v2/option.go index 39bfe0b8..a86906f4 100644 --- a/vendor/github.com/google/renameio/v2/option.go +++ b/vendor/github.com/google/renameio/v2/option.go @@ -13,6 +13,7 @@ // limitations under the License. //go:build !windows +// +build !windows package renameio @@ -85,14 +86,3 @@ func WithReplaceOnClose() Option { c.renameOnClose = true }) } - -// WithRoot specifies a root directory to use when working with files. -// See [os.Root] and https://go.dev/blog/osroot for more details. -// -// When WithRoot is used, WithTempDir (and the $TMPDIR environment variable) are -// ignored, as temporary files must be created in the specified root directory. -func WithRoot(root *os.Root) Option { - return optionFunc(func(c *config) { - c.root = root - }) -} diff --git a/vendor/github.com/google/renameio/v2/tempfile.go b/vendor/github.com/google/renameio/v2/tempfile.go index e101e4e7..98114e53 100644 --- a/vendor/github.com/google/renameio/v2/tempfile.go +++ b/vendor/github.com/google/renameio/v2/tempfile.go @@ -13,11 +13,13 @@ // limitations under the License. //go:build !windows +// +build !windows package renameio import ( - "math/rand/v2" + "io/ioutil" + "math/rand" "os" "path/filepath" "strconv" @@ -27,10 +29,10 @@ import ( const defaultPerm os.FileMode = 0o600 // nextrandom is a function generating a random number. -var nextrandom = rand.Int64 +var nextrandom = rand.Int63 // openTempFile creates a randomly named file and returns an open handle. It is -// similar to os.CreateTemp except that the directory must be given, the file +// similar to ioutil.TempFile except that the directory must be given, the file // permissions can be controlled and patterns in the name are not supported. // The name is always suffixed with a random number. func openTempFile(dir, name string, perm os.FileMode) (*os.File, error) { @@ -56,33 +58,6 @@ func openTempFile(dir, name string, perm os.FileMode) (*os.File, error) { } } -// openTempFileRoot creates a randomly named file in root and returns an open -// handle. It is similar to os.CreateTemp except that the directory must be -// given, the file permissions can be controlled and patterns in the name are -// not supported. The name is always suffixed with a random number. -func openTempFileRoot(root *os.Root, name string, perm os.FileMode) (string, *os.File, error) { - prefix := name - - for attempt := 0; ; { - // Generate a reasonably random name which is unlikely to already - // exist. O_EXCL ensures that existing files generate an error. - name := prefix + strconv.FormatInt(nextrandom(), 10) - - f, err := root.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, perm) - if !os.IsExist(err) { - return name, f, err - } - - if attempt++; attempt > 10000 { - return "", nil, &os.PathError{ - Op: "tempfile", - Path: name, - Err: os.ErrExist, - } - } - } -} - // TempDir checks whether os.TempDir() can be used as a temporary directory for // later atomically replacing files within dest. If no (os.TempDir() resides on // a different mount point), dest is returned. @@ -108,7 +83,7 @@ func tempDir(dir, dest string) string { // the TMPDIR environment variable. tmpdir := os.TempDir() - testsrc, err := os.CreateTemp(tmpdir, "."+filepath.Base(dest)) + testsrc, err := ioutil.TempFile(tmpdir, "."+filepath.Base(dest)) if err != nil { return fallback } @@ -120,7 +95,7 @@ func tempDir(dir, dest string) string { }() testsrc.Close() - testdest, err := os.CreateTemp(filepath.Dir(dest), "."+filepath.Base(dest)) + testdest, err := ioutil.TempFile(filepath.Dir(dest), "."+filepath.Base(dest)) if err != nil { return fallback } @@ -143,8 +118,6 @@ type PendingFile struct { done bool closed bool replaceOnClose bool - root *os.Root - tmpname string } // Cleanup is a no-op if CloseAtomicallyReplace succeeded, and otherwise closes @@ -161,14 +134,8 @@ func (t *PendingFile) Cleanup() error { if !t.closed { closeErr = t.File.Close() } - if t.root != nil { - if err := t.root.Remove(t.tmpname); err != nil { - return err - } - } else { - if err := os.Remove(t.Name()); err != nil { - return err - } + if err := os.Remove(t.Name()); err != nil { + return err } t.done = true return closeErr @@ -196,14 +163,8 @@ func (t *PendingFile) CloseAtomicallyReplace() error { if err := t.File.Close(); err != nil { return err } - if t.root != nil { - if err := t.root.Rename(t.tmpname, t.path); err != nil { - return err - } - } else { - if err := os.Rename(t.Name(), t.path); err != nil { - return err - } + if err := os.Rename(t.Name(), t.path); err != nil { + return err } t.done = true return nil @@ -239,7 +200,6 @@ type config struct { ignoreUmask bool chmod *os.FileMode renameOnClose bool - root *os.Root } // NewPendingFile creates a temporary file destined to atomically creating or @@ -267,15 +227,8 @@ func NewPendingFile(path string, opts ...Option) (*PendingFile, error) { } if cfg.attemptPermCopy { - var existing os.FileInfo - var err error - if cfg.root != nil { - existing, err = cfg.root.Lstat(cfg.path) - } else { - existing, err = os.Lstat(cfg.path) - } // Try to determine permissions from an existing file. - if err == nil && existing.Mode().IsRegular() { + if existing, err := os.Lstat(cfg.path); err == nil && existing.Mode().IsRegular() { perm := existing.Mode() & os.ModePerm cfg.chmod = &perm @@ -287,14 +240,7 @@ func NewPendingFile(path string, opts ...Option) (*PendingFile, error) { } } - var f *os.File - var err error - var tmpname string - if cfg.root != nil { - tmpname, f, err = openTempFileRoot(cfg.root, "."+filepath.Base(cfg.path), cfg.createPerm) - } else { - f, err = openTempFile(tempDir(cfg.dir, cfg.path), "."+filepath.Base(cfg.path), cfg.createPerm) - } + f, err := openTempFile(tempDir(cfg.dir, cfg.path), "."+filepath.Base(cfg.path), cfg.createPerm) if err != nil { return nil, err } @@ -309,13 +255,7 @@ func NewPendingFile(path string, opts ...Option) (*PendingFile, error) { } } - return &PendingFile{ - File: f, - path: cfg.path, - replaceOnClose: cfg.renameOnClose, - root: cfg.root, - tmpname: tmpname, - }, nil + return &PendingFile{File: f, path: cfg.path, replaceOnClose: cfg.renameOnClose}, nil } // Symlink wraps os.Symlink, replacing an existing symlink with the same name @@ -327,9 +267,9 @@ func Symlink(oldname, newname string) error { return err } - // We need to use os.MkdirTemp, as we cannot overwrite a os.CreateTemp file, + // We need to use ioutil.TempDir, as we cannot overwrite a ioutil.TempFile, // and removing+symlinking creates a TOCTOU race. - d, err := os.MkdirTemp(filepath.Dir(newname), "."+filepath.Base(newname)) + d, err := ioutil.TempDir(filepath.Dir(newname), "."+filepath.Base(newname)) if err != nil { return err } @@ -352,41 +292,3 @@ func Symlink(oldname, newname string) error { cleanup = false return os.RemoveAll(d) } - -// SymlinkRoot wraps os.Symlink, replacing an existing symlink with the same -// name atomically (os.Symlink fails when newname already exists, at least on -// Linux). -func SymlinkRoot(root *os.Root, oldname, newname string) error { - // Fast path: if newname does not exist yet, we can skip the whole dance - // below. - if err := root.Symlink(oldname, newname); err == nil || !os.IsExist(err) { - return err - } - - // We need to use os.MkdirTemp, as we cannot overwrite a os.CreateTemp file, - // and removing+symlinking creates a TOCTOU race. - // - // There is no os.Root-compatible os.MkdirTemp, so we use the path directly. - d, err := os.MkdirTemp(root.Name(), "."+filepath.Base(newname)) - if err != nil { - return err - } - cleanup := true - defer func() { - if cleanup { - os.RemoveAll(d) - } - }() - - symlink := filepath.Join(filepath.Base(d), "tmp.symlink") - if err := root.Symlink(oldname, symlink); err != nil { - return err - } - - if err := root.Rename(symlink, newname); err != nil { - return err - } - - cleanup = false - return os.RemoveAll(d) -} diff --git a/vendor/github.com/google/renameio/v2/writefile.go b/vendor/github.com/google/renameio/v2/writefile.go index 097817f0..54504210 100644 --- a/vendor/github.com/google/renameio/v2/writefile.go +++ b/vendor/github.com/google/renameio/v2/writefile.go @@ -13,12 +13,13 @@ // limitations under the License. //go:build !windows +// +build !windows package renameio import "os" -// WriteFile mirrors os.WriteFile, replacing an existing file with the same +// WriteFile mirrors ioutil.WriteFile, replacing an existing file with the same // name atomically. func WriteFile(filename string, data []byte, perm os.FileMode, opts ...Option) error { opts = append([]Option{ diff --git a/vendor/modules.txt b/vendor/modules.txt index 1d1c6bd5..36c02885 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -334,8 +334,8 @@ github.com/godbus/dbus/v5 # github.com/golang-jwt/jwt/v5 v5.3.0 ## explicit; go 1.21 github.com/golang-jwt/jwt/v5 -# github.com/google/renameio/v2 v2.0.2 -## explicit; go 1.25 +# github.com/google/renameio/v2 v2.0.1 +## explicit; go 1.13 github.com/google/renameio/v2 # github.com/google/s2a-go v0.1.9 ## explicit; go 1.20