Skip to content

Commit

Permalink
remove dependencies on resumable
Browse files Browse the repository at this point in the history
Signed-off-by: David Wu <david.wu@docker.com>
  • Loading branch information
David Wu committed Sep 11, 2018
1 parent 642075f commit 877d706
Show file tree
Hide file tree
Showing 23 changed files with 27 additions and 2,741 deletions.
45 changes: 27 additions & 18 deletions registry/storage/blobwriter_resumable.go
Expand Up @@ -4,17 +4,14 @@ package storage

import (
"context"
"encoding"
"fmt"
"hash"
"path"
"strconv"

storagedriver "github.com/docker/distribution/registry/storage/driver"
"github.com/sirupsen/logrus"
"github.com/stevvooe/resumable"

// register resumable hashes with import
_ "github.com/stevvooe/resumable/sha256"
_ "github.com/stevvooe/resumable/sha512"
)

// resumeDigest attempts to restore the state of the internal hash function
Expand All @@ -24,12 +21,18 @@ func (bw *blobWriter) resumeDigest(ctx context.Context) error {
return errResumableDigestNotAvailable
}

h, ok := bw.digester.Hash().(resumable.Hash)
h, ok := bw.digester.Hash().(encoding.BinaryMarshaler)
if !ok {
return errResumableDigestNotAvailable
}

state, err := h.MarshalBinary()
if err != nil {
return err
}

offset := bw.fileWriter.Size()
if offset == h.Len() {
if offset == int64(len(state)) {
// State of digester is already at the requested offset.
return nil
}
Expand All @@ -52,20 +55,26 @@ func (bw *blobWriter) resumeDigest(ctx context.Context) error {

if hashStateMatch.offset == 0 {
// No need to load any state, just reset the hasher.
h.Reset()
h.(hash.Hash).Reset()
} else {
storedState, err := bw.driver.GetContent(ctx, hashStateMatch.path)
if err != nil {
return err
}

if err = h.Restore(storedState); err != nil {
// This type assertion is safe since we already did an assertion at the beginning
if err = h.(encoding.BinaryUnmarshaler).UnmarshalBinary(storedState); err != nil {
return err
}

state, err = h.(encoding.BinaryMarshaler).MarshalBinary()
if err != nil {
return err
}
}

// Mind the gap.
if gapLen := offset - h.Len(); gapLen > 0 {
if gapLen := offset - int64(len(state)); gapLen > 0 {
return errResumableDigestNotAvailable
}

Expand Down Expand Up @@ -120,26 +129,26 @@ func (bw *blobWriter) storeHashState(ctx context.Context) error {
return errResumableDigestNotAvailable
}

h, ok := bw.digester.Hash().(resumable.Hash)
h, ok := bw.digester.Hash().(encoding.BinaryMarshaler)
if !ok {
return errResumableDigestNotAvailable
}

state, err := h.MarshalBinary()
if err != nil {
return fmt.Errorf("could not marshal: %v", err)
}

uploadHashStatePath, err := pathFor(uploadHashStatePathSpec{
name: bw.blobStore.repository.Named().String(),
id: bw.id,
alg: bw.digester.Digest().Algorithm(),
offset: h.Len(),
offset: int64(len(state)),
})

if err != nil {
return err
}

hashState, err := h.State()
if err != nil {
return err
}

return bw.driver.PutContent(ctx, uploadHashStatePath, hashState)
return bw.driver.PutContent(ctx, uploadHashStatePath, state)
}
22 changes: 0 additions & 22 deletions registry/storage/digester_resumable_test.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor.conf
Expand Up @@ -30,7 +30,6 @@ github.com/prometheus/common 89604d197083d4781071d3c65855d24ecfb0a563
github.com/prometheus/procfs cb4147076ac75738c9a7d279075a253c0cc5acbd
github.com/spf13/cobra 312092086bed4968099259622145a0c9ae280064
github.com/spf13/pflag 5644820622454e71517561946e3d94b9f9db6842
github.com/stevvooe/resumable 2aaf90b2ceea5072cb503ef2a620b08ff3119870
github.com/xenolf/lego a9d8cec0e6563575e5868a005359ac97911b5985
github.com/yvasiyarov/go-metrics 57bccd1ccd43f94bb17fdd8bf3007059b802f85e
github.com/yvasiyarov/gorelic a9bba5b9ab508a086f9a12b8c51fab68478e2128
Expand Down
28 changes: 0 additions & 28 deletions vendor/github.com/stevvooe/resumable/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/stevvooe/resumable/README.md

This file was deleted.

51 changes: 0 additions & 51 deletions vendor/github.com/stevvooe/resumable/resumable.go

This file was deleted.

71 changes: 0 additions & 71 deletions vendor/github.com/stevvooe/resumable/sha256/resume.go

This file was deleted.

0 comments on commit 877d706

Please sign in to comment.