mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-24 08:44:48 -07:00
Fix approval hook build
This commit is contained in:
committed by
Lawrence, Rendall
parent
04f1a9efb9
commit
e7c5263dd7
@@ -20,8 +20,8 @@ const PeerIDLen = 20
|
|||||||
// PeerID represents a peer ID.
|
// PeerID represents a peer ID.
|
||||||
type PeerID [PeerIDLen]byte
|
type PeerID [PeerIDLen]byte
|
||||||
|
|
||||||
// InvalidPeerIDSizeError holds error about invalid PeerID size
|
// ErrInvalidPeerIDSize holds error about invalid PeerID size
|
||||||
var InvalidPeerIDSizeError = errors.New("peer ID must be 20 bytes")
|
var ErrInvalidPeerIDSize = errors.New("peer ID must be 20 bytes")
|
||||||
|
|
||||||
// NewPeerID creates a PeerID from a byte slice.
|
// NewPeerID creates a PeerID from a byte slice.
|
||||||
//
|
//
|
||||||
@@ -29,7 +29,7 @@ var InvalidPeerIDSizeError = errors.New("peer ID must be 20 bytes")
|
|||||||
func NewPeerID(b []byte) (PeerID, error) {
|
func NewPeerID(b []byte) (PeerID, error) {
|
||||||
var p PeerID
|
var p PeerID
|
||||||
if len(b) != PeerIDLen {
|
if len(b) != PeerIDLen {
|
||||||
return p, InvalidPeerIDSizeError
|
return p, ErrInvalidPeerIDSize
|
||||||
}
|
}
|
||||||
copy(p[:], b)
|
copy(p[:], b)
|
||||||
return p, nil
|
return p, nil
|
||||||
@@ -58,10 +58,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// InvalidHashTypeError holds error about invalid InfoHash input type
|
// ErrInvalidHashType holds error about invalid InfoHash input type
|
||||||
InvalidHashTypeError = errors.New("info hash must be provided as byte slice or raw/hex string")
|
ErrInvalidHashType = errors.New("info hash must be provided as byte slice or raw/hex string")
|
||||||
// InvalidHashSizeError holds error about invalid InfoHash size
|
// ErrInvalidHashSize holds error about invalid InfoHash size
|
||||||
InvalidHashSizeError = errors.New("info hash must be either 20 (for torrent V1) or 32 (V2) bytes")
|
ErrInvalidHashSize = errors.New("info hash must be either 20 (for torrent V1) or 32 (V2) bytes")
|
||||||
)
|
)
|
||||||
|
|
||||||
// TruncateV1 returns truncated to 20-bytes length array of the corresponding InfoHash.
|
// TruncateV1 returns truncated to 20-bytes length array of the corresponding InfoHash.
|
||||||
@@ -74,7 +74,7 @@ func (i InfoHash) TruncateV1() InfoHash {
|
|||||||
// NewInfoHash creates an InfoHash from a byte slice or raw/hex string.
|
// NewInfoHash creates an InfoHash from a byte slice or raw/hex string.
|
||||||
func NewInfoHash(b interface{}) (InfoHash, error) {
|
func NewInfoHash(b interface{}) (InfoHash, error) {
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return NoneInfoHash, InvalidHashTypeError
|
return NoneInfoHash, ErrInvalidHashType
|
||||||
}
|
}
|
||||||
var ba []byte
|
var ba []byte
|
||||||
switch t := b.(type) {
|
switch t := b.(type) {
|
||||||
@@ -97,7 +97,7 @@ func NewInfoHash(b interface{}) (InfoHash, error) {
|
|||||||
}
|
}
|
||||||
l := len(ba)
|
l := len(ba)
|
||||||
if l != InfoHashV1Len && l != InfoHashV2Len {
|
if l != InfoHashV1Len && l != InfoHashV2Len {
|
||||||
return NoneInfoHash, InvalidHashSizeError
|
return NoneInfoHash, ErrInvalidHashSize
|
||||||
}
|
}
|
||||||
return InfoHash(ba), nil
|
return InfoHash(ba), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,14 @@ func (d driver) NewHook(optionBytes []byte, storage storage.Storage) (middleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
var confBytes []byte
|
var confBytes []byte
|
||||||
if confBytes, err = yaml.Marshal(cfg.Options); err != nil {
|
var h *hook
|
||||||
return nil, err
|
if confBytes, err = yaml.Marshal(cfg.Options); err == nil {
|
||||||
}
|
var c container.Container
|
||||||
|
if c, err = container.GetContainer(cfg.Name, confBytes, storage); err == nil {
|
||||||
if c, err := container.GetContainer(cfg.Name, confBytes, storage); err == nil {
|
h = &hook{c}
|
||||||
return &hook{c}, nil
|
}
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
return h, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrTorrentUnapproved is the error returned when a torrent hash is invalid.
|
// ErrTorrentUnapproved is the error returned when a torrent hash is invalid.
|
||||||
|
|||||||
Reference in New Issue
Block a user