chore: use go-copy

Use go-copy and drop `pkg/copy`.

Signed-off-by: Noel Georgi <git@frezbo.dev>
This commit is contained in:
Noel Georgi 2024-03-07 00:13:29 +05:30
parent 3c8f51d707
commit 1ec6683e0c
No known key found for this signature in database
GPG Key ID: 21A9F444075C9E36
12 changed files with 12 additions and 133 deletions

1
go.mod
View File

@ -114,6 +114,7 @@ require (
github.com/siderolabs/go-blockdevice v0.4.7
github.com/siderolabs/go-circular v0.1.0
github.com/siderolabs/go-cmd v0.1.1
github.com/siderolabs/go-copy v0.1.0
github.com/siderolabs/go-debug v0.3.0
github.com/siderolabs/go-kmsg v0.1.4
github.com/siderolabs/go-kubeconfig v0.1.0

2
go.sum
View File

@ -671,6 +671,8 @@ github.com/siderolabs/go-circular v0.1.0 h1:zpBJNUbCZSh0odZxA4Dcj0d3ShLLR2WxKW6h
github.com/siderolabs/go-circular v0.1.0/go.mod h1:14XnLf/I3J0VjzTgmwWNGjp58/bdIi4zXppAEx8plfw=
github.com/siderolabs/go-cmd v0.1.1 h1:nTouZUSxLeiiEe7hFexSVvaTsY/3O8k1s08BxPRrsps=
github.com/siderolabs/go-cmd v0.1.1/go.mod h1:6hY0JG34LxEEwYE8aH2iIHkHX/ir12VRLqfwAf2yJIY=
github.com/siderolabs/go-copy v0.1.0 h1:OIWCtSg+rhOtnIZTpT31Gfpn17rv5kwJqQHG+QUEgC8=
github.com/siderolabs/go-copy v0.1.0/go.mod h1:4bF2rZOZAR/ags/U4AVSpjFE5RPGdEeSkOq6yR9YOkU=
github.com/siderolabs/go-debug v0.3.0 h1:C8t7jbac5Va2eYu9QRXXEGsy3Vz5xOEVo0TDwVJH268=
github.com/siderolabs/go-debug v0.3.0/go.mod h1:DonqzIQOm3+qof020meFwJ2gXI5Jv/x4Dj27FyUW4aE=
github.com/siderolabs/go-kmsg v0.1.4 h1:RLAa90O9bWuhA3pXPAYAdrI+kzcqTshZASRA5yso/mo=

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -9,11 +9,11 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"golang.org/x/sys/unix"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -10,10 +10,10 @@ import (
"os"
"path/filepath"
"github.com/siderolabs/go-copy/copy"
"github.com/siderolabs/go-procfs/procfs"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/copy"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

View File

@ -1,124 +0,0 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Package copy provides a file copy utility implementation.
package copy //nolint:predeclared
import (
"io"
"io/fs"
"os"
"path"
)
// File copies the `src` file to the `dst` file.
func File(src, dst string, setters ...Option) error {
var (
err error
s *os.File
d *os.File
info os.FileInfo
options Options
)
for _, setter := range setters {
setter(&options)
}
if s, err = os.Open(src); err != nil {
return err
}
//nolint:errcheck
defer s.Close()
if d, err = os.Create(dst); err != nil {
return err
}
//nolint:errcheck
defer d.Close()
//nolint:errcheck
defer d.Sync()
if _, err = io.Copy(d, s); err != nil {
return err
}
if info, err = os.Stat(src); err != nil {
return err
}
mode := info.Mode()
if options.Mode != 0 {
mode = options.Mode
}
return os.Chmod(dst, mode)
}
// Dir copies the `src` directory to the `dst` directory.
func Dir(src, dst string, setters ...Option) error {
var (
err error
files []fs.DirEntry
info os.FileInfo
options Options
)
for _, setter := range setters {
setter(&options)
}
if info, err = os.Stat(src); err != nil {
return err
}
mode := info.Mode()
if options.Mode != 0 {
mode = options.Mode
}
if err = os.MkdirAll(dst, mode); err != nil {
return err
}
if files, err = os.ReadDir(src); err != nil {
return err
}
for _, file := range files {
s := path.Join(src, file.Name())
d := path.Join(dst, file.Name())
if file.IsDir() {
if err = Dir(s, d, setters...); err != nil {
return err
}
} else {
if err = File(s, d, setters...); err != nil {
return err
}
}
}
return nil
}
// Option represents copy option.
type Option func(o *Options)
// Options represents copy options.
type Options struct {
Mode os.FileMode
}
// WithMode sets destination files filemode.
func WithMode(m os.FileMode) Option {
return func(o *Options) {
o.Mode = m
}
}