Skip to content

Commit

Permalink
fixup: missed a few spots when updating dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bojidar-bg committed Dec 26, 2023
1 parent 6d4bf6d commit 399314a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
11 changes: 5 additions & 6 deletions pkg/ipdr/ipdr_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions pkg/ipdr/ipdr_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/ipdr/ipdr_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions pkg/ipfs/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -48,19 +48,19 @@ 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) {
path, err := node.Unixfs().Add(context.Background(), files.NewBytesFile(msg))
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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/ipfs/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/ipfs/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 399314a

Please sign in to comment.