From 399314a37b9040b3c4d5eabae89c0edab936dee6 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Wed, 27 Dec 2023 01:43:09 +0200 Subject: [PATCH] fixup: missed a few spots when updating dependencies --- pkg/ipdr/ipdr_dest.go | 11 +++++------ pkg/ipdr/ipdr_src.go | 13 ++++++++++--- pkg/ipdr/ipdr_transport.go | 8 ++++---- pkg/ipfs/files.go | 16 ++++++++-------- pkg/ipfs/images.go | 6 +++--- pkg/ipfs/secrets.go | 6 +++--- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/pkg/ipdr/ipdr_dest.go b/pkg/ipdr/ipdr_dest.go index 83ca61da..f8842423 100644 --- a/pkg/ipdr/ipdr_dest.go +++ b/pkg/ipdr/ipdr_dest.go @@ -70,10 +70,10 @@ func (d *ipdrImageDestination) PutBlob(ctx context.Context, stream io.Reader, in if err != nil { return inputInfo, err } - inputInfo.URLs = append(inputInfo.URLs, fmt.Sprintf("ipfs://%s", path.Cid().String())) - inputInfo.URLs = append(inputInfo.URLs, fmt.Sprintf("https://ipfs.io/ipfs/%s", path.Cid().String())) + inputInfo.URLs = append(inputInfo.URLs, fmt.Sprintf("ipfs://%s", path.RootCid().String())) + inputInfo.URLs = append(inputInfo.URLs, fmt.Sprintf("https://ipfs.io/ipfs/%s", path.RootCid().String())) - d.cidsToRemove = append(d.cidsToRemove, path.Cid()) + d.cidsToRemove = append(d.cidsToRemove, path.RootCid()) node, err := d.ipfs.Unixfs().Get(ctx, path) if err != nil { @@ -100,9 +100,8 @@ func (d *ipdrImageDestination) TryReusingBlob(ctx context.Context, info types.Bl for _, v := range info.URLs { u, err := url.Parse(v) if err == nil && (u.Scheme == "ipfs" || u.Host == "ipfs.io") { - p := path.New(u.Path) - if p.IsValid() == nil { - var err error + p, err := path.NewPath(u.Path) + if err == nil { node, err = d.ipfs.Unixfs().Get(ctx, p) if err != nil { return false, info, err diff --git a/pkg/ipdr/ipdr_src.go b/pkg/ipdr/ipdr_src.go index b5e55a62..3c3f7e7a 100644 --- a/pkg/ipdr/ipdr_src.go +++ b/pkg/ipdr/ipdr_src.go @@ -38,10 +38,14 @@ func (s *ipdrImageSource) Close() error { func (s *ipdrImageSource) GetManifest(ctx context.Context, instanceDigest *digest.Digest) ([]byte, string, error) { var p path.Path + var err error if instanceDigest == nil { - p = path.Join(s.reference.path, "manifests", s.reference.tag) + p, err = path.Join(s.reference.path, "manifests", s.reference.tag) } else { - p = path.Join(s.reference.path, "manifests", instanceDigest.String()) + p, err = path.Join(s.reference.path, "manifests", instanceDigest.String()) + } + if err != nil { + return nil, "", err } manifestNode, err := s.ipfs.Unixfs().Get(ctx, p) if err != nil { @@ -59,7 +63,10 @@ func (s *ipdrImageSource) GetManifest(ctx context.Context, instanceDigest *diges } func (s *ipdrImageSource) GetBlob(ctx context.Context, blobInfo types.BlobInfo, _ types.BlobInfoCache) (io.ReadCloser, int64, error) { - p := path.Join(s.reference.path, "blobs", blobInfo.Digest.String()) + p, err := path.Join(s.reference.path, "blobs", blobInfo.Digest.String()) + if err != nil { + return nil, 0, err + } blobNode, err := s.ipfs.Unixfs().Get(ctx, p) if err != nil { return nil, 0, err diff --git a/pkg/ipdr/ipdr_transport.go b/pkg/ipdr/ipdr_transport.go index 24d3fe38..d53aa3c0 100644 --- a/pkg/ipdr/ipdr_transport.go +++ b/pkg/ipdr/ipdr_transport.go @@ -40,9 +40,9 @@ func (t *ipdrTransport) ParseReference(reference string) (types.ImageReference, if tag == "" { tag = "latest" } - path := path.New(base) - if path.IsValid() != nil && base != "" { - return nil, path.IsValid() + path, err := path.NewPath(base) + if err != nil && base != "" { + return nil, err } return &ipdrImageReference{transport: t, path: path, tag: tag}, nil } @@ -51,7 +51,7 @@ func (t *ipdrTransport) NewDestinationReference(tag string) IpdrImageReference { if tag == "" { tag = "latest" } - return &ipdrImageReference{transport: t, path: path.New(""), tag: tag} + return &ipdrImageReference{transport: t, path: nil, tag: tag} } func (t *ipdrTransport) NewReference(p path.Path, tag string) IpdrImageReference { diff --git a/pkg/ipfs/files.go b/pkg/ipfs/files.go index b0fddffa..b0e9a956 100644 --- a/pkg/ipfs/files.go +++ b/pkg/ipfs/files.go @@ -17,14 +17,14 @@ import ( ) // Adds a file (or a directory) from the local filesystem to IPFS -func AddFsFile(node iface.CoreAPI, path string) (path.Resolved, error) { - stats, err := os.Stat(path) +func AddFsFile(node iface.CoreAPI, pth string) (path.ImmutablePath, error) { + stats, err := os.Stat(pth) if err != nil { - return nil, err + return path.ImmutablePath{}, err } - serialFile, err := files.NewSerialFile(path, false, stats) + serialFile, err := files.NewSerialFile(pth, false, stats) if err != nil { - return nil, err + return path.ImmutablePath{}, err } return node.Unixfs().Add(context.Background(), serialFile) } @@ -48,7 +48,7 @@ func AddProtobufFile(node iface.CoreAPI, msg proto.Message) (cid.Cid, error) { if err != nil { return cid.Cid{}, err } - return path.Cid(), nil + return path.RootCid(), nil } func AddBytes(node iface.CoreAPI, msg []byte) (cid.Cid, error) { @@ -56,11 +56,11 @@ func AddBytes(node iface.CoreAPI, msg []byte) (cid.Cid, error) { if err != nil { return cid.Cid{}, err } - return path.Cid(), nil + return path.RootCid(), nil } func GetBytes(node iface.CoreAPI, cid cid.Cid) ([]byte, error) { - fileNode, err := node.Unixfs().Get(context.Background(), path.IpfsPath(cid)) + fileNode, err := node.Unixfs().Get(context.Background(), path.FromCid(cid)) if err != nil { return nil, err } diff --git a/pkg/ipfs/images.go b/pkg/ipfs/images.go index 6772ad20..17646867 100644 --- a/pkg/ipfs/images.go +++ b/pkg/ipfs/images.go @@ -100,13 +100,13 @@ func UploadImageToIpdr(ctx context.Context, ipfs iface.CoreAPI, sys *types.Syste return } - resolved, ok := destinationRef.Path().(path.Resolved) + resolved, ok := destinationRef.Path().(path.ImmutablePath) if !ok { err = errors.New("Destination path not resolved") // Shouldn't get here return } - imageCid = resolved.Cid().Bytes() + imageCid = resolved.RootCid().Bytes() return } @@ -147,7 +147,7 @@ func ReuploadImageFromIpdr(ctx context.Context, ipfs iface.CoreAPI, localRegistr if err != nil { return nil, err } - sourceRef := ipdrTransport.NewReference(path.IpfsPath(c), "") + sourceRef := ipdrTransport.NewReference(path.FromCid(c), "") url := localRegistryUrl + "/" + c.Hash().HexString() destinationRef, err := registryTransport.ParseReference("//" + url) diff --git a/pkg/ipfs/secrets.go b/pkg/ipfs/secrets.go index 8aca5cd0..d893216e 100644 --- a/pkg/ipfs/secrets.go +++ b/pkg/ipfs/secrets.go @@ -77,12 +77,12 @@ func UploadSecret(ctx context.Context, ipfs iface.CoreAPI, contents []byte) (cid if err != nil { return nil, err } - return secretPath.Cid().Bytes(), nil + return secretPath.RootCid().Bytes(), nil } func RemoveSecret(ctx context.Context, ipfs iface.CoreAPI, cidBytes []byte) error { secretCid, err := cid.Cast(cidBytes) - err = ipfs.Pin().Rm(ctx, ifacepath.IpfsPath(secretCid)) + err = ipfs.Pin().Rm(ctx, ifacepath.FromCid(secretCid)) if err != nil { return err } @@ -97,7 +97,7 @@ func DownloadSecret(ctx context.Context, ipfs iface.CoreAPI, secret *pb.Volume_S if err != nil { return nil, err } - secretNode, err := ipfs.Unixfs().Get(ctx, ifacepath.IpfsPath(secretCid)) + secretNode, err := ipfs.Unixfs().Get(ctx, ifacepath.FromCid(secretCid)) if err != nil { return nil, err }