Debian Codegraph @

internal/mock/ocilayout/ocilayout.go

raw
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package ocilayout
15
16 import (
17 "context"
18 "os"
19
20 "oras.land/oras-go/v2"
21 "oras.land/oras-go/v2/content/oci"
22 )
23
24 // Copy creates a temporary OCI layout for testing
25 // and returns the path to the layout.
26 func Copy(sourcePath, destPath, tag string) error {
27 ctx := context.Background()
28
29 srcStore, err := oci.NewFromFS(ctx, os.DirFS(sourcePath))
30 if err != nil {
31 return err
32 }
33
34 // create a dest store for store the generated oci layout.
35 destStore, err := oci.New(destPath)
36 if err != nil {
37 return err
38 }
39
40 // copy data
41 _, err = oras.ExtendedCopy(ctx, srcStore, tag, destStore, "", oras.DefaultExtendedCopyOptions)
42 if err != nil {
43 return err
44 }
45
46 return nil
47 }