Skip to content

Commit

Permalink
Remove github.com/otiai10/copy dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Redko <[email protected]>
  • Loading branch information
alexandear committed Jan 6, 2024
1 parent b6e03a0 commit f535e0f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
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
63 changes: 60 additions & 3 deletions oci/layout/oci_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package layout

import (
"context"
"fmt"
"io"
"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 +275,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 +295,61 @@ 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 {
info, err := os.Stat(src)
if err != nil {
return err
}

if err := os.MkdirAll(dst, info.Mode()); err != nil {
return err
}

dirEntries, err := os.ReadDir(src)
if err != nil {
return err
}

for _, dirEntry := range dirEntries {
srcPath := filepath.Join(src, dirEntry.Name())
dstPath := filepath.Join(dst, dirEntry.Name())

copy := copyFile
if dirEntry.IsDir() {
copy = copyDir
}

if err := copy(srcPath, dstPath); err != nil {
return err
}
}
return nil
}

// 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())
}

0 comments on commit f535e0f

Please sign in to comment.