mirror of
https://github.com/mudler/luet.git
synced 2025-09-27 15:43:17 +00:00
bump github.com/moby/buildkit to v0.13.0 (#351)
* bump github.com/moby/buildkit to v0.13.0 Signed-off-by: Nianyu Shen <nianyu@spectrocloud.com> * fix: update dep usage based on newer version Signed-off-by: Nianyu Shen <nianyu@spectrocloud.com> * remove empty line Signed-off-by: Nianyu Shen <nianyu@spectrocloud.com> * ci: bump golang to 1.21.x * Bump moby * debug --------- Signed-off-by: Nianyu Shen <nianyu@spectrocloud.com> Co-authored-by: Nianyu Shen <nianyu@spectrocloud.com>
This commit is contained in:
committed by
GitHub
parent
c47bf4833a
commit
4c788ccbd1
77
vendor/github.com/rogpeppe/go-internal/lockedfile/lockedfile.go
generated
vendored
77
vendor/github.com/rogpeppe/go-internal/lockedfile/lockedfile.go
generated
vendored
@@ -9,7 +9,7 @@ package lockedfile
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
@@ -35,7 +35,7 @@ type osFile struct {
|
||||
// OpenFile is like os.OpenFile, but returns a locked file.
|
||||
// If flag includes os.O_WRONLY or os.O_RDWR, the file is write-locked;
|
||||
// otherwise, it is read-locked.
|
||||
func OpenFile(name string, flag int, perm os.FileMode) (*File, error) {
|
||||
func OpenFile(name string, flag int, perm fs.FileMode) (*File, error) {
|
||||
var (
|
||||
f = new(File)
|
||||
err error
|
||||
@@ -82,10 +82,10 @@ func Edit(name string) (*File, error) {
|
||||
// non-nil error.
|
||||
func (f *File) Close() error {
|
||||
if f.closed {
|
||||
return &os.PathError{
|
||||
return &fs.PathError{
|
||||
Op: "close",
|
||||
Path: f.Name(),
|
||||
Err: os.ErrClosed,
|
||||
Err: fs.ErrClosed,
|
||||
}
|
||||
}
|
||||
f.closed = true
|
||||
@@ -103,12 +103,12 @@ func Read(name string) ([]byte, error) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return ioutil.ReadAll(f)
|
||||
return io.ReadAll(f)
|
||||
}
|
||||
|
||||
// Write opens the named file (creating it with the given permissions if needed),
|
||||
// then write-locks it and overwrites it with the given content.
|
||||
func Write(name string, content io.Reader, perm os.FileMode) (err error) {
|
||||
func Write(name string, content io.Reader, perm fs.FileMode) (err error) {
|
||||
f, err := OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -120,3 +120,68 @@ func Write(name string, content io.Reader, perm os.FileMode) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Transform invokes t with the result of reading the named file, with its lock
|
||||
// still held.
|
||||
//
|
||||
// If t returns a nil error, Transform then writes the returned contents back to
|
||||
// the file, making a best effort to preserve existing contents on error.
|
||||
//
|
||||
// t must not modify the slice passed to it.
|
||||
func Transform(name string, t func([]byte) ([]byte, error)) (err error) {
|
||||
f, err := Edit(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
old, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
new, err := t(old)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(new) > len(old) {
|
||||
// The overall file size is increasing, so write the tail first: if we're
|
||||
// about to run out of space on the disk, we would rather detect that
|
||||
// failure before we have overwritten the original contents.
|
||||
if _, err := f.WriteAt(new[len(old):], int64(len(old))); err != nil {
|
||||
// Make a best effort to remove the incomplete tail.
|
||||
f.Truncate(int64(len(old)))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// We're about to overwrite the old contents. In case of failure, make a best
|
||||
// effort to roll back before we close the file.
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if _, err := f.WriteAt(old, 0); err == nil {
|
||||
f.Truncate(int64(len(old)))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if len(new) >= len(old) {
|
||||
if _, err := f.WriteAt(new[:len(old)], 0); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := f.WriteAt(new, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
// The overall file size is decreasing, so shrink the file to its final size
|
||||
// after writing. We do this after writing (instead of before) so that if
|
||||
// the write fails, enough filesystem space will likely still be reserved
|
||||
// to contain the previous contents.
|
||||
if err := f.Truncate(int64(len(new))); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user