Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove github.com/otiai10/copy dependency #2239

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/opencontainers/selinux v1.11.0
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f
github.com/otiai10/copy v1.14.0
github.com/proglottis/gpgme v0.1.3
github.com/secure-systems-lab/go-securesystemslib v0.8.0
github.com/sigstore/fulcio v1.4.3
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,6 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f h1:/UDgs8FGMqwnHagNDPGOlts35QkhAZ8by3DR7nMih7M=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f/go.mod h1:J6OG6YJVEWopen4avK3VNQSnALmmjvniMmni/YFYAwc=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
53 changes: 50 additions & 3 deletions oci/layout/oci_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package layout

import (
"context"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"testing"

"github.com/containers/image/v5/types"
digest "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
cp "github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestReferenceDeleteImage_multipleImages_twoIdenticalReferences(t *testing.T

func loadFixture(t *testing.T, fixtureName string) string {
tmpDir := t.TempDir()
err := cp.Copy(fmt.Sprintf("fixtures/%v/", fixtureName), tmpDir)
err := copyDir(filepath.Join("fixtures", fixtureName), tmpDir)
require.NoError(t, err)
return tmpDir
}
Expand All @@ -296,3 +296,50 @@ func assertBlobDoesNotExist(t *testing.T, blobsDir string, blobDigest string) {
_, err = os.Stat(blobPath)
require.True(t, os.IsNotExist(err))
}

// copyDir copies a whole directory src recursively to dst.
func copyDir(src, dst string) error {
return filepath.WalkDir(src, func(srcPath string, srcDirEntry fs.DirEntry, err error) error {
if err != nil {
return err
}

srcRel, err := filepath.Rel(src, srcPath)
if err != nil {
return err
}

dstPath := filepath.Join(dst, srcRel)
if srcDirEntry.IsDir() {
return os.MkdirAll(dstPath, os.ModePerm)
}

return copyFile(srcPath, dstPath)
})
}

// copyFile copies src file to dst file.
func copyFile(src, dst string) error {
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()

dstFile, err := os.Create(dst)
if err != nil {
return err
}
defer dstFile.Close()

if _, err := io.Copy(dstFile, srcFile); err != nil {
return err
}

info, err := os.Stat(src)
if err != nil {
return err
}

return os.Chmod(dst, info.Mode())
}