repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
containers/image
docker/tarfile/src.go
ensureCachedDataIsPresent
func (s *Source) ensureCachedDataIsPresent() error { s.cacheDataLock.Do(func() { // Read and parse manifest.json tarManifest, err := s.loadTarManifest() if err != nil { s.cacheDataResult = err return } // Check to make sure length is 1 if len(tarManifest) != 1 { s.cacheDataResult = errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest)) return } // Read and parse config. configBytes, err := s.readTarComponent(tarManifest[0].Config) if err != nil { s.cacheDataResult = err return } var parsedConfig manifest.Schema2Image // There's a lot of info there, but we only really care about layer DiffIDs. if err := json.Unmarshal(configBytes, &parsedConfig); err != nil { s.cacheDataResult = errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config) return } knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig) if err != nil { s.cacheDataResult = err return } // Success; commit. s.tarManifest = &tarManifest[0] s.configBytes = configBytes s.configDigest = digest.FromBytes(configBytes) s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs s.knownLayers = knownLayers }) return s.cacheDataResult }
go
func (s *Source) ensureCachedDataIsPresent() error { s.cacheDataLock.Do(func() { // Read and parse manifest.json tarManifest, err := s.loadTarManifest() if err != nil { s.cacheDataResult = err return } // Check to make sure length is 1 if len(tarManifest) != 1 { s.cacheDataResult = errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest)) return } // Read and parse config. configBytes, err := s.readTarComponent(tarManifest[0].Config) if err != nil { s.cacheDataResult = err return } var parsedConfig manifest.Schema2Image // There's a lot of info there, but we only really care about layer DiffIDs. if err := json.Unmarshal(configBytes, &parsedConfig); err != nil { s.cacheDataResult = errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config) return } knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig) if err != nil { s.cacheDataResult = err return } // Success; commit. s.tarManifest = &tarManifest[0] s.configBytes = configBytes s.configDigest = digest.FromBytes(configBytes) s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs s.knownLayers = knownLayers }) return s.cacheDataResult }
[ "func", "(", "s", "*", "Source", ")", "ensureCachedDataIsPresent", "(", ")", "error", "{", "s", ".", "cacheDataLock", ".", "Do", "(", "func", "(", ")", "{", "tarManifest", ",", "err", ":=", "s", ".", "loadTarManifest", "(", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "cacheDataResult", "=", "err", "\n", "return", "\n", "}", "\n", "if", "len", "(", "tarManifest", ")", "!=", "1", "{", "s", ".", "cacheDataResult", "=", "errors", ".", "Errorf", "(", "\"Unexpected tar manifest.json: expected 1 item, got %d\"", ",", "len", "(", "tarManifest", ")", ")", "\n", "return", "\n", "}", "\n", "configBytes", ",", "err", ":=", "s", ".", "readTarComponent", "(", "tarManifest", "[", "0", "]", ".", "Config", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "cacheDataResult", "=", "err", "\n", "return", "\n", "}", "\n", "var", "parsedConfig", "manifest", ".", "Schema2Image", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "configBytes", ",", "&", "parsedConfig", ")", ";", "err", "!=", "nil", "{", "s", ".", "cacheDataResult", "=", "errors", ".", "Wrapf", "(", "err", ",", "\"Error decoding tar config %s\"", ",", "tarManifest", "[", "0", "]", ".", "Config", ")", "\n", "return", "\n", "}", "\n", "knownLayers", ",", "err", ":=", "s", ".", "prepareLayerData", "(", "&", "tarManifest", "[", "0", "]", ",", "&", "parsedConfig", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "cacheDataResult", "=", "err", "\n", "return", "\n", "}", "\n", "s", ".", "tarManifest", "=", "&", "tarManifest", "[", "0", "]", "\n", "s", ".", "configBytes", "=", "configBytes", "\n", "s", ".", "configDigest", "=", "digest", ".", "FromBytes", "(", "configBytes", ")", "\n", "s", ".", "orderedDiffIDList", "=", "parsedConfig", ".", "RootFS", ".", "DiffIDs", "\n", "s", ".", "knownLayers", "=", "knownLayers", "\n", "}", ")", "\n", "return", "s", ".", "cacheDataResult", "\n", "}" ]
// ensureCachedDataIsPresent loads data necessary for any of the public accessors.
[ "ensureCachedDataIsPresent", "loads", "data", "necessary", "for", "any", "of", "the", "public", "accessors", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/tarfile/src.go#L204-L245
test
containers/image
docker/tarfile/src.go
loadTarManifest
func (s *Source) loadTarManifest() ([]ManifestItem, error) { // FIXME? Do we need to deal with the legacy format? bytes, err := s.readTarComponent(manifestFileName) if err != nil { return nil, err } var items []ManifestItem if err := json.Unmarshal(bytes, &items); err != nil { return nil, errors.Wrap(err, "Error decoding tar manifest.json") } return items, nil }
go
func (s *Source) loadTarManifest() ([]ManifestItem, error) { // FIXME? Do we need to deal with the legacy format? bytes, err := s.readTarComponent(manifestFileName) if err != nil { return nil, err } var items []ManifestItem if err := json.Unmarshal(bytes, &items); err != nil { return nil, errors.Wrap(err, "Error decoding tar manifest.json") } return items, nil }
[ "func", "(", "s", "*", "Source", ")", "loadTarManifest", "(", ")", "(", "[", "]", "ManifestItem", ",", "error", ")", "{", "bytes", ",", "err", ":=", "s", ".", "readTarComponent", "(", "manifestFileName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "items", "[", "]", "ManifestItem", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "bytes", ",", "&", "items", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"Error decoding tar manifest.json\"", ")", "\n", "}", "\n", "return", "items", ",", "nil", "\n", "}" ]
// loadTarManifest loads and decodes the manifest.json.
[ "loadTarManifest", "loads", "and", "decodes", "the", "manifest", ".", "json", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/tarfile/src.go#L248-L259
test
containers/image
docker/tarfile/src.go
Close
func (s *Source) Close() error { if s.removeTarPathOnClose { return os.Remove(s.tarPath) } return nil }
go
func (s *Source) Close() error { if s.removeTarPathOnClose { return os.Remove(s.tarPath) } return nil }
[ "func", "(", "s", "*", "Source", ")", "Close", "(", ")", "error", "{", "if", "s", ".", "removeTarPathOnClose", "{", "return", "os", ".", "Remove", "(", "s", ".", "tarPath", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close removes resources associated with an initialized Source, if any.
[ "Close", "removes", "resources", "associated", "with", "an", "initialized", "Source", "if", "any", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/tarfile/src.go#L262-L267
test
containers/image
docker/daemon/daemon_dest.go
newImageDestination
func newImageDestination(ctx context.Context, sys *types.SystemContext, ref daemonReference) (types.ImageDestination, error) { if ref.ref == nil { return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport()) } namedTaggedRef, ok := ref.ref.(reference.NamedTagged) if !ok { return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport()) } var mustMatchRuntimeOS = true if sys != nil && sys.DockerDaemonHost != client.DefaultDockerHost { mustMatchRuntimeOS = false } c, err := newDockerClient(sys) if err != nil { return nil, errors.Wrap(err, "Error initializing docker engine client") } reader, writer := io.Pipe() // Commit() may never be called, so we may never read from this channel; so, make this buffered to allow imageLoadGoroutine to write status and terminate even if we never read it. statusChannel := make(chan error, 1) goroutineContext, goroutineCancel := context.WithCancel(ctx) go imageLoadGoroutine(goroutineContext, c, reader, statusChannel) return &daemonImageDestination{ ref: ref, mustMatchRuntimeOS: mustMatchRuntimeOS, Destination: tarfile.NewDestination(writer, namedTaggedRef), goroutineCancel: goroutineCancel, statusChannel: statusChannel, writer: writer, committed: false, }, nil }
go
func newImageDestination(ctx context.Context, sys *types.SystemContext, ref daemonReference) (types.ImageDestination, error) { if ref.ref == nil { return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport()) } namedTaggedRef, ok := ref.ref.(reference.NamedTagged) if !ok { return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport()) } var mustMatchRuntimeOS = true if sys != nil && sys.DockerDaemonHost != client.DefaultDockerHost { mustMatchRuntimeOS = false } c, err := newDockerClient(sys) if err != nil { return nil, errors.Wrap(err, "Error initializing docker engine client") } reader, writer := io.Pipe() // Commit() may never be called, so we may never read from this channel; so, make this buffered to allow imageLoadGoroutine to write status and terminate even if we never read it. statusChannel := make(chan error, 1) goroutineContext, goroutineCancel := context.WithCancel(ctx) go imageLoadGoroutine(goroutineContext, c, reader, statusChannel) return &daemonImageDestination{ ref: ref, mustMatchRuntimeOS: mustMatchRuntimeOS, Destination: tarfile.NewDestination(writer, namedTaggedRef), goroutineCancel: goroutineCancel, statusChannel: statusChannel, writer: writer, committed: false, }, nil }
[ "func", "newImageDestination", "(", "ctx", "context", ".", "Context", ",", "sys", "*", "types", ".", "SystemContext", ",", "ref", "daemonReference", ")", "(", "types", ".", "ImageDestination", ",", "error", ")", "{", "if", "ref", ".", "ref", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Invalid destination docker-daemon:%s: a destination must be a name:tag\"", ",", "ref", ".", "StringWithinTransport", "(", ")", ")", "\n", "}", "\n", "namedTaggedRef", ",", "ok", ":=", "ref", ".", "ref", ".", "(", "reference", ".", "NamedTagged", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Invalid destination docker-daemon:%s: a destination must be a name:tag\"", ",", "ref", ".", "StringWithinTransport", "(", ")", ")", "\n", "}", "\n", "var", "mustMatchRuntimeOS", "=", "true", "\n", "if", "sys", "!=", "nil", "&&", "sys", ".", "DockerDaemonHost", "!=", "client", ".", "DefaultDockerHost", "{", "mustMatchRuntimeOS", "=", "false", "\n", "}", "\n", "c", ",", "err", ":=", "newDockerClient", "(", "sys", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"Error initializing docker engine client\"", ")", "\n", "}", "\n", "reader", ",", "writer", ":=", "io", ".", "Pipe", "(", ")", "\n", "statusChannel", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n", "goroutineContext", ",", "goroutineCancel", ":=", "context", ".", "WithCancel", "(", "ctx", ")", "\n", "go", "imageLoadGoroutine", "(", "goroutineContext", ",", "c", ",", "reader", ",", "statusChannel", ")", "\n", "return", "&", "daemonImageDestination", "{", "ref", ":", "ref", ",", "mustMatchRuntimeOS", ":", "mustMatchRuntimeOS", ",", "Destination", ":", "tarfile", ".", "NewDestination", "(", "writer", ",", "namedTaggedRef", ")", ",", "goroutineCancel", ":", "goroutineCancel", ",", "statusChannel", ":", "statusChannel", ",", "writer", ":", "writer", ",", "committed", ":", "false", ",", "}", ",", "nil", "\n", "}" ]
// newImageDestination returns a types.ImageDestination for the specified image reference.
[ "newImageDestination", "returns", "a", "types", ".", "ImageDestination", "for", "the", "specified", "image", "reference", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/daemon/daemon_dest.go#L28-L63
test
containers/image
docker/daemon/daemon_dest.go
imageLoadGoroutine
func imageLoadGoroutine(ctx context.Context, c *client.Client, reader *io.PipeReader, statusChannel chan<- error) { err := errors.New("Internal error: unexpected panic in imageLoadGoroutine") defer func() { logrus.Debugf("docker-daemon: sending done, status %v", err) statusChannel <- err }() defer func() { if err == nil { reader.Close() } else { reader.CloseWithError(err) } }() resp, err := c.ImageLoad(ctx, reader, true) if err != nil { err = errors.Wrap(err, "Error saving image to docker engine") return } defer resp.Body.Close() }
go
func imageLoadGoroutine(ctx context.Context, c *client.Client, reader *io.PipeReader, statusChannel chan<- error) { err := errors.New("Internal error: unexpected panic in imageLoadGoroutine") defer func() { logrus.Debugf("docker-daemon: sending done, status %v", err) statusChannel <- err }() defer func() { if err == nil { reader.Close() } else { reader.CloseWithError(err) } }() resp, err := c.ImageLoad(ctx, reader, true) if err != nil { err = errors.Wrap(err, "Error saving image to docker engine") return } defer resp.Body.Close() }
[ "func", "imageLoadGoroutine", "(", "ctx", "context", ".", "Context", ",", "c", "*", "client", ".", "Client", ",", "reader", "*", "io", ".", "PipeReader", ",", "statusChannel", "chan", "<-", "error", ")", "{", "err", ":=", "errors", ".", "New", "(", "\"Internal error: unexpected panic in imageLoadGoroutine\"", ")", "\n", "defer", "func", "(", ")", "{", "logrus", ".", "Debugf", "(", "\"docker-daemon: sending done, status %v\"", ",", "err", ")", "\n", "statusChannel", "<-", "err", "\n", "}", "(", ")", "\n", "defer", "func", "(", ")", "{", "if", "err", "==", "nil", "{", "reader", ".", "Close", "(", ")", "\n", "}", "else", "{", "reader", ".", "CloseWithError", "(", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "resp", ",", "err", ":=", "c", ".", "ImageLoad", "(", "ctx", ",", "reader", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "errors", ".", "Wrap", "(", "err", ",", "\"Error saving image to docker engine\"", ")", "\n", "return", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "}" ]
// imageLoadGoroutine accepts tar stream on reader, sends it to c, and reports error or success by writing to statusChannel
[ "imageLoadGoroutine", "accepts", "tar", "stream", "on", "reader", "sends", "it", "to", "c", "and", "reports", "error", "or", "success", "by", "writing", "to", "statusChannel" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/daemon/daemon_dest.go#L66-L86
test
containers/image
oci/archive/oci_transport.go
NewReference
func NewReference(file, image string) (types.ImageReference, error) { resolved, err := explicitfilepath.ResolvePathToFullyExplicit(file) if err != nil { return nil, err } if err := internal.ValidateOCIPath(file); err != nil { return nil, err } if err := internal.ValidateImageName(image); err != nil { return nil, err } return ociArchiveReference{file: file, resolvedFile: resolved, image: image}, nil }
go
func NewReference(file, image string) (types.ImageReference, error) { resolved, err := explicitfilepath.ResolvePathToFullyExplicit(file) if err != nil { return nil, err } if err := internal.ValidateOCIPath(file); err != nil { return nil, err } if err := internal.ValidateImageName(image); err != nil { return nil, err } return ociArchiveReference{file: file, resolvedFile: resolved, image: image}, nil }
[ "func", "NewReference", "(", "file", ",", "image", "string", ")", "(", "types", ".", "ImageReference", ",", "error", ")", "{", "resolved", ",", "err", ":=", "explicitfilepath", ".", "ResolvePathToFullyExplicit", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "internal", ".", "ValidateOCIPath", "(", "file", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "internal", ".", "ValidateImageName", "(", "image", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "ociArchiveReference", "{", "file", ":", "file", ",", "resolvedFile", ":", "resolved", ",", "image", ":", "image", "}", ",", "nil", "\n", "}" ]
// NewReference returns an OCI reference for a file and a image.
[ "NewReference", "returns", "an", "OCI", "reference", "for", "a", "file", "and", "a", "image", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_transport.go#L62-L77
test
containers/image
oci/archive/oci_transport.go
createOCIRef
func createOCIRef(image string) (tempDirOCIRef, error) { dir, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(), "oci") if err != nil { return tempDirOCIRef{}, errors.Wrapf(err, "error creating temp directory") } ociRef, err := ocilayout.NewReference(dir, image) if err != nil { return tempDirOCIRef{}, err } tempDirRef := tempDirOCIRef{tempDirectory: dir, ociRefExtracted: ociRef} return tempDirRef, nil }
go
func createOCIRef(image string) (tempDirOCIRef, error) { dir, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(), "oci") if err != nil { return tempDirOCIRef{}, errors.Wrapf(err, "error creating temp directory") } ociRef, err := ocilayout.NewReference(dir, image) if err != nil { return tempDirOCIRef{}, err } tempDirRef := tempDirOCIRef{tempDirectory: dir, ociRefExtracted: ociRef} return tempDirRef, nil }
[ "func", "createOCIRef", "(", "image", "string", ")", "(", "tempDirOCIRef", ",", "error", ")", "{", "dir", ",", "err", ":=", "ioutil", ".", "TempDir", "(", "tmpdir", ".", "TemporaryDirectoryForBigFiles", "(", ")", ",", "\"oci\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "tempDirOCIRef", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error creating temp directory\"", ")", "\n", "}", "\n", "ociRef", ",", "err", ":=", "ocilayout", ".", "NewReference", "(", "dir", ",", "image", ")", "\n", "if", "err", "!=", "nil", "{", "return", "tempDirOCIRef", "{", "}", ",", "err", "\n", "}", "\n", "tempDirRef", ":=", "tempDirOCIRef", "{", "tempDirectory", ":", "dir", ",", "ociRefExtracted", ":", "ociRef", "}", "\n", "return", "tempDirRef", ",", "nil", "\n", "}" ]
// createOCIRef creates the oci reference of the image
[ "createOCIRef", "creates", "the", "oci", "reference", "of", "the", "image" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_transport.go#L162-L174
test
containers/image
oci/archive/oci_transport.go
createUntarTempDir
func createUntarTempDir(ref ociArchiveReference) (tempDirOCIRef, error) { tempDirRef, err := createOCIRef(ref.image) if err != nil { return tempDirOCIRef{}, errors.Wrap(err, "error creating oci reference") } src := ref.resolvedFile dst := tempDirRef.tempDirectory // TODO: This can take quite some time, and should ideally be cancellable using a context.Context. if err := archive.UntarPath(src, dst); err != nil { if err := tempDirRef.deleteTempDir(); err != nil { return tempDirOCIRef{}, errors.Wrapf(err, "error deleting temp directory %q", tempDirRef.tempDirectory) } return tempDirOCIRef{}, errors.Wrapf(err, "error untarring file %q", tempDirRef.tempDirectory) } return tempDirRef, nil }
go
func createUntarTempDir(ref ociArchiveReference) (tempDirOCIRef, error) { tempDirRef, err := createOCIRef(ref.image) if err != nil { return tempDirOCIRef{}, errors.Wrap(err, "error creating oci reference") } src := ref.resolvedFile dst := tempDirRef.tempDirectory // TODO: This can take quite some time, and should ideally be cancellable using a context.Context. if err := archive.UntarPath(src, dst); err != nil { if err := tempDirRef.deleteTempDir(); err != nil { return tempDirOCIRef{}, errors.Wrapf(err, "error deleting temp directory %q", tempDirRef.tempDirectory) } return tempDirOCIRef{}, errors.Wrapf(err, "error untarring file %q", tempDirRef.tempDirectory) } return tempDirRef, nil }
[ "func", "createUntarTempDir", "(", "ref", "ociArchiveReference", ")", "(", "tempDirOCIRef", ",", "error", ")", "{", "tempDirRef", ",", "err", ":=", "createOCIRef", "(", "ref", ".", "image", ")", "\n", "if", "err", "!=", "nil", "{", "return", "tempDirOCIRef", "{", "}", ",", "errors", ".", "Wrap", "(", "err", ",", "\"error creating oci reference\"", ")", "\n", "}", "\n", "src", ":=", "ref", ".", "resolvedFile", "\n", "dst", ":=", "tempDirRef", ".", "tempDirectory", "\n", "if", "err", ":=", "archive", ".", "UntarPath", "(", "src", ",", "dst", ")", ";", "err", "!=", "nil", "{", "if", "err", ":=", "tempDirRef", ".", "deleteTempDir", "(", ")", ";", "err", "!=", "nil", "{", "return", "tempDirOCIRef", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error deleting temp directory %q\"", ",", "tempDirRef", ".", "tempDirectory", ")", "\n", "}", "\n", "return", "tempDirOCIRef", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error untarring file %q\"", ",", "tempDirRef", ".", "tempDirectory", ")", "\n", "}", "\n", "return", "tempDirRef", ",", "nil", "\n", "}" ]
// creates the temporary directory and copies the tarred content to it
[ "creates", "the", "temporary", "directory", "and", "copies", "the", "tarred", "content", "to", "it" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_transport.go#L177-L192
test
containers/image
pkg/blobinfocache/internal/prioritize/prioritize.go
destructivelyPrioritizeReplacementCandidatesWithMax
func destructivelyPrioritizeReplacementCandidatesWithMax(cs []CandidateWithTime, primaryDigest, uncompressedDigest digest.Digest, maxCandidates int) []types.BICReplacementCandidate { // We don't need to use sort.Stable() because nanosecond timestamps are (presumably?) unique, so no two elements should // compare equal. sort.Sort(&candidateSortState{ cs: cs, primaryDigest: primaryDigest, uncompressedDigest: uncompressedDigest, }) resLength := len(cs) if resLength > maxCandidates { resLength = maxCandidates } res := make([]types.BICReplacementCandidate, resLength) for i := range res { res[i] = cs[i].Candidate } return res }
go
func destructivelyPrioritizeReplacementCandidatesWithMax(cs []CandidateWithTime, primaryDigest, uncompressedDigest digest.Digest, maxCandidates int) []types.BICReplacementCandidate { // We don't need to use sort.Stable() because nanosecond timestamps are (presumably?) unique, so no two elements should // compare equal. sort.Sort(&candidateSortState{ cs: cs, primaryDigest: primaryDigest, uncompressedDigest: uncompressedDigest, }) resLength := len(cs) if resLength > maxCandidates { resLength = maxCandidates } res := make([]types.BICReplacementCandidate, resLength) for i := range res { res[i] = cs[i].Candidate } return res }
[ "func", "destructivelyPrioritizeReplacementCandidatesWithMax", "(", "cs", "[", "]", "CandidateWithTime", ",", "primaryDigest", ",", "uncompressedDigest", "digest", ".", "Digest", ",", "maxCandidates", "int", ")", "[", "]", "types", ".", "BICReplacementCandidate", "{", "sort", ".", "Sort", "(", "&", "candidateSortState", "{", "cs", ":", "cs", ",", "primaryDigest", ":", "primaryDigest", ",", "uncompressedDigest", ":", "uncompressedDigest", ",", "}", ")", "\n", "resLength", ":=", "len", "(", "cs", ")", "\n", "if", "resLength", ">", "maxCandidates", "{", "resLength", "=", "maxCandidates", "\n", "}", "\n", "res", ":=", "make", "(", "[", "]", "types", ".", "BICReplacementCandidate", ",", "resLength", ")", "\n", "for", "i", ":=", "range", "res", "{", "res", "[", "i", "]", "=", "cs", "[", "i", "]", ".", "Candidate", "\n", "}", "\n", "return", "res", "\n", "}" ]
// destructivelyPrioritizeReplacementCandidatesWithMax is destructivelyPrioritizeReplacementCandidates with a parameter for the // number of entries to limit, only to make testing simpler.
[ "destructivelyPrioritizeReplacementCandidatesWithMax", "is", "destructivelyPrioritizeReplacementCandidates", "with", "a", "parameter", "for", "the", "number", "of", "entries", "to", "limit", "only", "to", "make", "testing", "simpler", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/pkg/blobinfocache/internal/prioritize/prioritize.go#L82-L100
test
containers/image
ostree/ostree_dest.go
newImageDestination
func newImageDestination(ref ostreeReference, tmpDirPath string) (types.ImageDestination, error) { tmpDirPath = filepath.Join(tmpDirPath, ref.branchName) if err := ensureDirectoryExists(tmpDirPath); err != nil { return nil, err } return &ostreeImageDestination{ref, "", manifestSchema{}, tmpDirPath, map[string]*blobToImport{}, "", 0, nil}, nil }
go
func newImageDestination(ref ostreeReference, tmpDirPath string) (types.ImageDestination, error) { tmpDirPath = filepath.Join(tmpDirPath, ref.branchName) if err := ensureDirectoryExists(tmpDirPath); err != nil { return nil, err } return &ostreeImageDestination{ref, "", manifestSchema{}, tmpDirPath, map[string]*blobToImport{}, "", 0, nil}, nil }
[ "func", "newImageDestination", "(", "ref", "ostreeReference", ",", "tmpDirPath", "string", ")", "(", "types", ".", "ImageDestination", ",", "error", ")", "{", "tmpDirPath", "=", "filepath", ".", "Join", "(", "tmpDirPath", ",", "ref", ".", "branchName", ")", "\n", "if", "err", ":=", "ensureDirectoryExists", "(", "tmpDirPath", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ostreeImageDestination", "{", "ref", ",", "\"\"", ",", "manifestSchema", "{", "}", ",", "tmpDirPath", ",", "map", "[", "string", "]", "*", "blobToImport", "{", "}", ",", "\"\"", ",", "0", ",", "nil", "}", ",", "nil", "\n", "}" ]
// newImageDestination returns an ImageDestination for writing to an existing ostree.
[ "newImageDestination", "returns", "an", "ImageDestination", "for", "writing", "to", "an", "existing", "ostree", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/ostree/ostree_dest.go#L78-L84
test
containers/image
directory/explicitfilepath/path.go
resolveExistingPathToFullyExplicit
func resolveExistingPathToFullyExplicit(path string) (string, error) { resolved, err := filepath.Abs(path) if err != nil { return "", err // Coverage: This can fail only if os.Getwd() fails. } resolved, err = filepath.EvalSymlinks(resolved) if err != nil { return "", err } return filepath.Clean(resolved), nil }
go
func resolveExistingPathToFullyExplicit(path string) (string, error) { resolved, err := filepath.Abs(path) if err != nil { return "", err // Coverage: This can fail only if os.Getwd() fails. } resolved, err = filepath.EvalSymlinks(resolved) if err != nil { return "", err } return filepath.Clean(resolved), nil }
[ "func", "resolveExistingPathToFullyExplicit", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "resolved", ",", "err", ":=", "filepath", ".", "Abs", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "resolved", ",", "err", "=", "filepath", ".", "EvalSymlinks", "(", "resolved", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "filepath", ".", "Clean", "(", "resolved", ")", ",", "nil", "\n", "}" ]
// resolveExistingPathToFullyExplicit is the same as ResolvePathToFullyExplicit, // but without the special case for missing final component.
[ "resolveExistingPathToFullyExplicit", "is", "the", "same", "as", "ResolvePathToFullyExplicit", "but", "without", "the", "special", "case", "for", "missing", "final", "component", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/explicitfilepath/path.go#L46-L56
test
containers/image
directory/directory_dest.go
newImageDestination
func newImageDestination(ref dirReference, compress bool) (types.ImageDestination, error) { d := &dirImageDestination{ref: ref, compress: compress} // If directory exists check if it is empty // if not empty, check whether the contents match that of a container image directory and overwrite the contents // if the contents don't match throw an error dirExists, err := pathExists(d.ref.resolvedPath) if err != nil { return nil, errors.Wrapf(err, "error checking for path %q", d.ref.resolvedPath) } if dirExists { isEmpty, err := isDirEmpty(d.ref.resolvedPath) if err != nil { return nil, err } if !isEmpty { versionExists, err := pathExists(d.ref.versionPath()) if err != nil { return nil, errors.Wrapf(err, "error checking if path exists %q", d.ref.versionPath()) } if versionExists { contents, err := ioutil.ReadFile(d.ref.versionPath()) if err != nil { return nil, err } // check if contents of version file is what we expect it to be if string(contents) != version { return nil, ErrNotContainerImageDir } } else { return nil, ErrNotContainerImageDir } // delete directory contents so that only one image is in the directory at a time if err = removeDirContents(d.ref.resolvedPath); err != nil { return nil, errors.Wrapf(err, "error erasing contents in %q", d.ref.resolvedPath) } logrus.Debugf("overwriting existing container image directory %q", d.ref.resolvedPath) } } else { // create directory if it doesn't exist if err := os.MkdirAll(d.ref.resolvedPath, 0755); err != nil { return nil, errors.Wrapf(err, "unable to create directory %q", d.ref.resolvedPath) } } // create version file err = ioutil.WriteFile(d.ref.versionPath(), []byte(version), 0644) if err != nil { return nil, errors.Wrapf(err, "error creating version file %q", d.ref.versionPath()) } return d, nil }
go
func newImageDestination(ref dirReference, compress bool) (types.ImageDestination, error) { d := &dirImageDestination{ref: ref, compress: compress} // If directory exists check if it is empty // if not empty, check whether the contents match that of a container image directory and overwrite the contents // if the contents don't match throw an error dirExists, err := pathExists(d.ref.resolvedPath) if err != nil { return nil, errors.Wrapf(err, "error checking for path %q", d.ref.resolvedPath) } if dirExists { isEmpty, err := isDirEmpty(d.ref.resolvedPath) if err != nil { return nil, err } if !isEmpty { versionExists, err := pathExists(d.ref.versionPath()) if err != nil { return nil, errors.Wrapf(err, "error checking if path exists %q", d.ref.versionPath()) } if versionExists { contents, err := ioutil.ReadFile(d.ref.versionPath()) if err != nil { return nil, err } // check if contents of version file is what we expect it to be if string(contents) != version { return nil, ErrNotContainerImageDir } } else { return nil, ErrNotContainerImageDir } // delete directory contents so that only one image is in the directory at a time if err = removeDirContents(d.ref.resolvedPath); err != nil { return nil, errors.Wrapf(err, "error erasing contents in %q", d.ref.resolvedPath) } logrus.Debugf("overwriting existing container image directory %q", d.ref.resolvedPath) } } else { // create directory if it doesn't exist if err := os.MkdirAll(d.ref.resolvedPath, 0755); err != nil { return nil, errors.Wrapf(err, "unable to create directory %q", d.ref.resolvedPath) } } // create version file err = ioutil.WriteFile(d.ref.versionPath(), []byte(version), 0644) if err != nil { return nil, errors.Wrapf(err, "error creating version file %q", d.ref.versionPath()) } return d, nil }
[ "func", "newImageDestination", "(", "ref", "dirReference", ",", "compress", "bool", ")", "(", "types", ".", "ImageDestination", ",", "error", ")", "{", "d", ":=", "&", "dirImageDestination", "{", "ref", ":", "ref", ",", "compress", ":", "compress", "}", "\n", "dirExists", ",", "err", ":=", "pathExists", "(", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error checking for path %q\"", ",", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "}", "\n", "if", "dirExists", "{", "isEmpty", ",", "err", ":=", "isDirEmpty", "(", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "isEmpty", "{", "versionExists", ",", "err", ":=", "pathExists", "(", "d", ".", "ref", ".", "versionPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error checking if path exists %q\"", ",", "d", ".", "ref", ".", "versionPath", "(", ")", ")", "\n", "}", "\n", "if", "versionExists", "{", "contents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "d", ".", "ref", ".", "versionPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "string", "(", "contents", ")", "!=", "version", "{", "return", "nil", ",", "ErrNotContainerImageDir", "\n", "}", "\n", "}", "else", "{", "return", "nil", ",", "ErrNotContainerImageDir", "\n", "}", "\n", "if", "err", "=", "removeDirContents", "(", "d", ".", "ref", ".", "resolvedPath", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error erasing contents in %q\"", ",", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"overwriting existing container image directory %q\"", ",", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "}", "\n", "}", "else", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "d", ".", "ref", ".", "resolvedPath", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"unable to create directory %q\"", ",", "d", ".", "ref", ".", "resolvedPath", ")", "\n", "}", "\n", "}", "\n", "err", "=", "ioutil", ".", "WriteFile", "(", "d", ".", "ref", ".", "versionPath", "(", ")", ",", "[", "]", "byte", "(", "version", ")", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error creating version file %q\"", ",", "d", ".", "ref", ".", "versionPath", "(", ")", ")", "\n", "}", "\n", "return", "d", ",", "nil", "\n", "}" ]
// newImageDestination returns an ImageDestination for writing to a directory.
[ "newImageDestination", "returns", "an", "ImageDestination", "for", "writing", "to", "a", "directory", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_dest.go#L28-L79
test
containers/image
directory/directory_dest.go
isDirEmpty
func isDirEmpty(path string) (bool, error) { files, err := ioutil.ReadDir(path) if err != nil { return false, err } return len(files) == 0, nil }
go
func isDirEmpty(path string) (bool, error) { files, err := ioutil.ReadDir(path) if err != nil { return false, err } return len(files) == 0, nil }
[ "func", "isDirEmpty", "(", "path", "string", ")", "(", "bool", ",", "error", ")", "{", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "len", "(", "files", ")", "==", "0", ",", "nil", "\n", "}" ]
// returns true if directory is empty
[ "returns", "true", "if", "directory", "is", "empty" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_dest.go#L239-L245
test
containers/image
directory/directory_dest.go
removeDirContents
func removeDirContents(path string) error { files, err := ioutil.ReadDir(path) if err != nil { return err } for _, file := range files { if err := os.RemoveAll(filepath.Join(path, file.Name())); err != nil { return err } } return nil }
go
func removeDirContents(path string) error { files, err := ioutil.ReadDir(path) if err != nil { return err } for _, file := range files { if err := os.RemoveAll(filepath.Join(path, file.Name())); err != nil { return err } } return nil }
[ "func", "removeDirContents", "(", "path", "string", ")", "error", "{", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "if", "err", ":=", "os", ".", "RemoveAll", "(", "filepath", ".", "Join", "(", "path", ",", "file", ".", "Name", "(", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// deletes the contents of a directory
[ "deletes", "the", "contents", "of", "a", "directory" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_dest.go#L248-L260
test
containers/image
docker/docker_image.go
GetRepositoryTags
func GetRepositoryTags(ctx context.Context, sys *types.SystemContext, ref types.ImageReference) ([]string, error) { dr, ok := ref.(dockerReference) if !ok { return nil, errors.Errorf("ref must be a dockerReference") } path := fmt.Sprintf(tagsPath, reference.Path(dr.ref)) client, err := newDockerClientFromRef(sys, dr, false, "pull") if err != nil { return nil, errors.Wrap(err, "failed to create client") } tags := make([]string, 0) for { res, err := client.makeRequest(ctx, "GET", path, nil, nil, v2Auth, nil) if err != nil { return nil, err } defer res.Body.Close() if res.StatusCode != http.StatusOK { // print url also return nil, errors.Errorf("Invalid status code returned when fetching tags list %d (%s)", res.StatusCode, http.StatusText(res.StatusCode)) } var tagsHolder struct { Tags []string } if err = json.NewDecoder(res.Body).Decode(&tagsHolder); err != nil { return nil, err } tags = append(tags, tagsHolder.Tags...) link := res.Header.Get("Link") if link == "" { break } linkURLStr := strings.Trim(strings.Split(link, ";")[0], "<>") linkURL, err := url.Parse(linkURLStr) if err != nil { return tags, err } // can be relative or absolute, but we only want the path (and I // guess we're in trouble if it forwards to a new place...) path = linkURL.Path if linkURL.RawQuery != "" { path += "?" path += linkURL.RawQuery } } return tags, nil }
go
func GetRepositoryTags(ctx context.Context, sys *types.SystemContext, ref types.ImageReference) ([]string, error) { dr, ok := ref.(dockerReference) if !ok { return nil, errors.Errorf("ref must be a dockerReference") } path := fmt.Sprintf(tagsPath, reference.Path(dr.ref)) client, err := newDockerClientFromRef(sys, dr, false, "pull") if err != nil { return nil, errors.Wrap(err, "failed to create client") } tags := make([]string, 0) for { res, err := client.makeRequest(ctx, "GET", path, nil, nil, v2Auth, nil) if err != nil { return nil, err } defer res.Body.Close() if res.StatusCode != http.StatusOK { // print url also return nil, errors.Errorf("Invalid status code returned when fetching tags list %d (%s)", res.StatusCode, http.StatusText(res.StatusCode)) } var tagsHolder struct { Tags []string } if err = json.NewDecoder(res.Body).Decode(&tagsHolder); err != nil { return nil, err } tags = append(tags, tagsHolder.Tags...) link := res.Header.Get("Link") if link == "" { break } linkURLStr := strings.Trim(strings.Split(link, ";")[0], "<>") linkURL, err := url.Parse(linkURLStr) if err != nil { return tags, err } // can be relative or absolute, but we only want the path (and I // guess we're in trouble if it forwards to a new place...) path = linkURL.Path if linkURL.RawQuery != "" { path += "?" path += linkURL.RawQuery } } return tags, nil }
[ "func", "GetRepositoryTags", "(", "ctx", "context", ".", "Context", ",", "sys", "*", "types", ".", "SystemContext", ",", "ref", "types", ".", "ImageReference", ")", "(", "[", "]", "string", ",", "error", ")", "{", "dr", ",", "ok", ":=", "ref", ".", "(", "dockerReference", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"ref must be a dockerReference\"", ")", "\n", "}", "\n", "path", ":=", "fmt", ".", "Sprintf", "(", "tagsPath", ",", "reference", ".", "Path", "(", "dr", ".", "ref", ")", ")", "\n", "client", ",", "err", ":=", "newDockerClientFromRef", "(", "sys", ",", "dr", ",", "false", ",", "\"pull\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"failed to create client\"", ")", "\n", "}", "\n", "tags", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "{", "res", ",", "err", ":=", "client", ".", "makeRequest", "(", "ctx", ",", "\"GET\"", ",", "path", ",", "nil", ",", "nil", ",", "v2Auth", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "res", ".", "Body", ".", "Close", "(", ")", "\n", "if", "res", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Invalid status code returned when fetching tags list %d (%s)\"", ",", "res", ".", "StatusCode", ",", "http", ".", "StatusText", "(", "res", ".", "StatusCode", ")", ")", "\n", "}", "\n", "var", "tagsHolder", "struct", "{", "Tags", "[", "]", "string", "\n", "}", "\n", "if", "err", "=", "json", ".", "NewDecoder", "(", "res", ".", "Body", ")", ".", "Decode", "(", "&", "tagsHolder", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "tags", "=", "append", "(", "tags", ",", "tagsHolder", ".", "Tags", "...", ")", "\n", "link", ":=", "res", ".", "Header", ".", "Get", "(", "\"Link\"", ")", "\n", "if", "link", "==", "\"\"", "{", "break", "\n", "}", "\n", "linkURLStr", ":=", "strings", ".", "Trim", "(", "strings", ".", "Split", "(", "link", ",", "\";\"", ")", "[", "0", "]", ",", "\"<>\"", ")", "\n", "linkURL", ",", "err", ":=", "url", ".", "Parse", "(", "linkURLStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "tags", ",", "err", "\n", "}", "\n", "path", "=", "linkURL", ".", "Path", "\n", "if", "linkURL", ".", "RawQuery", "!=", "\"\"", "{", "path", "+=", "\"?\"", "\n", "path", "+=", "linkURL", ".", "RawQuery", "\n", "}", "\n", "}", "\n", "return", "tags", ",", "nil", "\n", "}" ]
// GetRepositoryTags list all tags available in the repository. The tag // provided inside the ImageReference will be ignored.
[ "GetRepositoryTags", "list", "all", "tags", "available", "in", "the", "repository", ".", "The", "tag", "provided", "inside", "the", "ImageReference", "will", "be", "ignored", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/docker_image.go#L54-L107
test
containers/image
pkg/blobinfocache/default.go
DefaultCache
func DefaultCache(sys *types.SystemContext) types.BlobInfoCache { dir, err := blobInfoCacheDir(sys, getRootlessUID()) if err != nil { logrus.Debugf("Error determining a location for %s, using a memory-only cache", blobInfoCacheFilename) return memory.New() } path := filepath.Join(dir, blobInfoCacheFilename) if err := os.MkdirAll(dir, 0700); err != nil { logrus.Debugf("Error creating parent directories for %s, using a memory-only cache: %v", blobInfoCacheFilename, err) return memory.New() } logrus.Debugf("Using blob info cache at %s", path) return boltdb.New(path) }
go
func DefaultCache(sys *types.SystemContext) types.BlobInfoCache { dir, err := blobInfoCacheDir(sys, getRootlessUID()) if err != nil { logrus.Debugf("Error determining a location for %s, using a memory-only cache", blobInfoCacheFilename) return memory.New() } path := filepath.Join(dir, blobInfoCacheFilename) if err := os.MkdirAll(dir, 0700); err != nil { logrus.Debugf("Error creating parent directories for %s, using a memory-only cache: %v", blobInfoCacheFilename, err) return memory.New() } logrus.Debugf("Using blob info cache at %s", path) return boltdb.New(path) }
[ "func", "DefaultCache", "(", "sys", "*", "types", ".", "SystemContext", ")", "types", ".", "BlobInfoCache", "{", "dir", ",", "err", ":=", "blobInfoCacheDir", "(", "sys", ",", "getRootlessUID", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"Error determining a location for %s, using a memory-only cache\"", ",", "blobInfoCacheFilename", ")", "\n", "return", "memory", ".", "New", "(", ")", "\n", "}", "\n", "path", ":=", "filepath", ".", "Join", "(", "dir", ",", "blobInfoCacheFilename", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "dir", ",", "0700", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"Error creating parent directories for %s, using a memory-only cache: %v\"", ",", "blobInfoCacheFilename", ",", "err", ")", "\n", "return", "memory", ".", "New", "(", ")", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"Using blob info cache at %s\"", ",", "path", ")", "\n", "return", "boltdb", ".", "New", "(", "path", ")", "\n", "}" ]
// DefaultCache returns the default BlobInfoCache implementation appropriate for sys.
[ "DefaultCache", "returns", "the", "default", "BlobInfoCache", "implementation", "appropriate", "for", "sys", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/pkg/blobinfocache/default.go#L61-L75
test
containers/image
pkg/blobinfocache/memory/memory.go
uncompressedDigestLocked
func (mem *cache) uncompressedDigestLocked(anyDigest digest.Digest) digest.Digest { if d, ok := mem.uncompressedDigests[anyDigest]; ok { return d } // Presence in digestsByUncompressed implies that anyDigest must already refer to an uncompressed digest. // This way we don't have to waste storage space with trivial (uncompressed, uncompressed) mappings // when we already record a (compressed, uncompressed) pair. if m, ok := mem.digestsByUncompressed[anyDigest]; ok && len(m) > 0 { return anyDigest } return "" }
go
func (mem *cache) uncompressedDigestLocked(anyDigest digest.Digest) digest.Digest { if d, ok := mem.uncompressedDigests[anyDigest]; ok { return d } // Presence in digestsByUncompressed implies that anyDigest must already refer to an uncompressed digest. // This way we don't have to waste storage space with trivial (uncompressed, uncompressed) mappings // when we already record a (compressed, uncompressed) pair. if m, ok := mem.digestsByUncompressed[anyDigest]; ok && len(m) > 0 { return anyDigest } return "" }
[ "func", "(", "mem", "*", "cache", ")", "uncompressedDigestLocked", "(", "anyDigest", "digest", ".", "Digest", ")", "digest", ".", "Digest", "{", "if", "d", ",", "ok", ":=", "mem", ".", "uncompressedDigests", "[", "anyDigest", "]", ";", "ok", "{", "return", "d", "\n", "}", "\n", "if", "m", ",", "ok", ":=", "mem", ".", "digestsByUncompressed", "[", "anyDigest", "]", ";", "ok", "&&", "len", "(", "m", ")", ">", "0", "{", "return", "anyDigest", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// uncompressedDigestLocked implements types.BlobInfoCache.UncompressedDigest, but must be called only with mem.mutex held.
[ "uncompressedDigestLocked", "implements", "types", ".", "BlobInfoCache", ".", "UncompressedDigest", "but", "must", "be", "called", "only", "with", "mem", ".", "mutex", "held", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/pkg/blobinfocache/memory/memory.go#L56-L67
test
containers/image
oci/archive/oci_dest.go
Close
func (d *ociArchiveImageDestination) Close() error { defer d.tempDirRef.deleteTempDir() return d.unpackedDest.Close() }
go
func (d *ociArchiveImageDestination) Close() error { defer d.tempDirRef.deleteTempDir() return d.unpackedDest.Close() }
[ "func", "(", "d", "*", "ociArchiveImageDestination", ")", "Close", "(", ")", "error", "{", "defer", "d", ".", "tempDirRef", ".", "deleteTempDir", "(", ")", "\n", "return", "d", ".", "unpackedDest", ".", "Close", "(", ")", "\n", "}" ]
// Close removes resources associated with an initialized ImageDestination, if any // Close deletes the temp directory of the oci-archive image
[ "Close", "removes", "resources", "associated", "with", "an", "initialized", "ImageDestination", "if", "any", "Close", "deletes", "the", "temp", "directory", "of", "the", "oci", "-", "archive", "image" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_dest.go#L44-L47
test
containers/image
oci/archive/oci_dest.go
PutManifest
func (d *ociArchiveImageDestination) PutManifest(ctx context.Context, m []byte) error { return d.unpackedDest.PutManifest(ctx, m) }
go
func (d *ociArchiveImageDestination) PutManifest(ctx context.Context, m []byte) error { return d.unpackedDest.PutManifest(ctx, m) }
[ "func", "(", "d", "*", "ociArchiveImageDestination", ")", "PutManifest", "(", "ctx", "context", ".", "Context", ",", "m", "[", "]", "byte", ")", "error", "{", "return", "d", ".", "unpackedDest", ".", "PutManifest", "(", "ctx", ",", "m", ")", "\n", "}" ]
// PutManifest writes manifest to the destination
[ "PutManifest", "writes", "manifest", "to", "the", "destination" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_dest.go#L109-L111
test
containers/image
oci/archive/oci_dest.go
Commit
func (d *ociArchiveImageDestination) Commit(ctx context.Context) error { if err := d.unpackedDest.Commit(ctx); err != nil { return errors.Wrapf(err, "error storing image %q", d.ref.image) } // path of directory to tar up src := d.tempDirRef.tempDirectory // path to save tarred up file dst := d.ref.resolvedFile return tarDirectory(src, dst) }
go
func (d *ociArchiveImageDestination) Commit(ctx context.Context) error { if err := d.unpackedDest.Commit(ctx); err != nil { return errors.Wrapf(err, "error storing image %q", d.ref.image) } // path of directory to tar up src := d.tempDirRef.tempDirectory // path to save tarred up file dst := d.ref.resolvedFile return tarDirectory(src, dst) }
[ "func", "(", "d", "*", "ociArchiveImageDestination", ")", "Commit", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "err", ":=", "d", ".", "unpackedDest", ".", "Commit", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"error storing image %q\"", ",", "d", ".", "ref", ".", "image", ")", "\n", "}", "\n", "src", ":=", "d", ".", "tempDirRef", ".", "tempDirectory", "\n", "dst", ":=", "d", ".", "ref", ".", "resolvedFile", "\n", "return", "tarDirectory", "(", "src", ",", "dst", ")", "\n", "}" ]
// Commit marks the process of storing the image as successful and asks for the image to be persisted // after the directory is made, it is tarred up into a file and the directory is deleted
[ "Commit", "marks", "the", "process", "of", "storing", "the", "image", "as", "successful", "and", "asks", "for", "the", "image", "to", "be", "persisted", "after", "the", "directory", "is", "made", "it", "is", "tarred", "up", "into", "a", "file", "and", "the", "directory", "is", "deleted" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_dest.go#L119-L129
test
containers/image
oci/archive/oci_dest.go
tarDirectory
func tarDirectory(src, dst string) error { // input is a stream of bytes from the archive of the directory at path input, err := archive.Tar(src, archive.Uncompressed) if err != nil { return errors.Wrapf(err, "error retrieving stream of bytes from %q", src) } // creates the tar file outFile, err := os.Create(dst) if err != nil { return errors.Wrapf(err, "error creating tar file %q", dst) } defer outFile.Close() // copies the contents of the directory to the tar file // TODO: This can take quite some time, and should ideally be cancellable using a context.Context. _, err = io.Copy(outFile, input) return err }
go
func tarDirectory(src, dst string) error { // input is a stream of bytes from the archive of the directory at path input, err := archive.Tar(src, archive.Uncompressed) if err != nil { return errors.Wrapf(err, "error retrieving stream of bytes from %q", src) } // creates the tar file outFile, err := os.Create(dst) if err != nil { return errors.Wrapf(err, "error creating tar file %q", dst) } defer outFile.Close() // copies the contents of the directory to the tar file // TODO: This can take quite some time, and should ideally be cancellable using a context.Context. _, err = io.Copy(outFile, input) return err }
[ "func", "tarDirectory", "(", "src", ",", "dst", "string", ")", "error", "{", "input", ",", "err", ":=", "archive", ".", "Tar", "(", "src", ",", "archive", ".", "Uncompressed", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"error retrieving stream of bytes from %q\"", ",", "src", ")", "\n", "}", "\n", "outFile", ",", "err", ":=", "os", ".", "Create", "(", "dst", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"error creating tar file %q\"", ",", "dst", ")", "\n", "}", "\n", "defer", "outFile", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "outFile", ",", "input", ")", "\n", "return", "err", "\n", "}" ]
// tar converts the directory at src and saves it to dst
[ "tar", "converts", "the", "directory", "at", "src", "and", "saves", "it", "to", "dst" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/oci/archive/oci_dest.go#L132-L151
test
containers/image
storage/storage_transport.go
ParseStoreReference
func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (*storageReference, error) { if ref == "" { return nil, errors.Wrapf(ErrInvalidReference, "%q is an empty reference", ref) } if ref[0] == '[' { // Ignore the store specifier. closeIndex := strings.IndexRune(ref, ']') if closeIndex < 1 { return nil, errors.Wrapf(ErrInvalidReference, "store specifier in %q did not end", ref) } ref = ref[closeIndex+1:] } // The reference may end with an image ID. Image IDs and digests use the same "@" separator; // here we only peel away an image ID, and leave digests alone. split := strings.LastIndex(ref, "@") id := "" if split != -1 { possibleID := ref[split+1:] if possibleID == "" { return nil, errors.Wrapf(ErrInvalidReference, "empty trailing digest or ID in %q", ref) } // If it looks like a digest, leave it alone for now. if _, err := digest.Parse(possibleID); err != nil { // Otherwise… if idSum, err := digest.Parse("sha256:" + possibleID); err == nil && idSum.Validate() == nil { id = possibleID // … it is a full ID } else if img, err := store.Image(possibleID); err == nil && img != nil && len(possibleID) >= minimumTruncatedIDLength && strings.HasPrefix(img.ID, possibleID) { // … it is a truncated version of the ID of an image that's present in local storage, // so we might as well use the expanded value. id = img.ID } else { return nil, errors.Wrapf(ErrInvalidReference, "%q does not look like an image ID or digest", possibleID) } // We have recognized an image ID; peel it off. ref = ref[:split] } } // If we only have one @-delimited portion, then _maybe_ it's a truncated image ID. Only check on that if it's // at least of what we guess is a reasonable minimum length, because we don't want a really short value // like "a" matching an image by ID prefix when the input was actually meant to specify an image name. if id == "" && len(ref) >= minimumTruncatedIDLength && !strings.ContainsAny(ref, "@:") { if img, err := store.Image(ref); err == nil && img != nil && strings.HasPrefix(img.ID, ref) { // It's a truncated version of the ID of an image that's present in local storage; // we need to expand it. id = img.ID ref = "" } } var named reference.Named // Unless we have an un-named "ID" or "@ID" reference (where ID might only have been a prefix), which has been // completely parsed above, the initial portion should be a name, possibly with a tag and/or a digest.. if ref != "" { var err error named, err = reference.ParseNormalizedNamed(ref) if err != nil { return nil, errors.Wrapf(err, "error parsing named reference %q", ref) } named = reference.TagNameOnly(named) } result, err := newReference(storageTransport{store: store, defaultUIDMap: s.defaultUIDMap, defaultGIDMap: s.defaultGIDMap}, named, id) if err != nil { return nil, err } logrus.Debugf("parsed reference into %q", result.StringWithinTransport()) return result, nil }
go
func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (*storageReference, error) { if ref == "" { return nil, errors.Wrapf(ErrInvalidReference, "%q is an empty reference", ref) } if ref[0] == '[' { // Ignore the store specifier. closeIndex := strings.IndexRune(ref, ']') if closeIndex < 1 { return nil, errors.Wrapf(ErrInvalidReference, "store specifier in %q did not end", ref) } ref = ref[closeIndex+1:] } // The reference may end with an image ID. Image IDs and digests use the same "@" separator; // here we only peel away an image ID, and leave digests alone. split := strings.LastIndex(ref, "@") id := "" if split != -1 { possibleID := ref[split+1:] if possibleID == "" { return nil, errors.Wrapf(ErrInvalidReference, "empty trailing digest or ID in %q", ref) } // If it looks like a digest, leave it alone for now. if _, err := digest.Parse(possibleID); err != nil { // Otherwise… if idSum, err := digest.Parse("sha256:" + possibleID); err == nil && idSum.Validate() == nil { id = possibleID // … it is a full ID } else if img, err := store.Image(possibleID); err == nil && img != nil && len(possibleID) >= minimumTruncatedIDLength && strings.HasPrefix(img.ID, possibleID) { // … it is a truncated version of the ID of an image that's present in local storage, // so we might as well use the expanded value. id = img.ID } else { return nil, errors.Wrapf(ErrInvalidReference, "%q does not look like an image ID or digest", possibleID) } // We have recognized an image ID; peel it off. ref = ref[:split] } } // If we only have one @-delimited portion, then _maybe_ it's a truncated image ID. Only check on that if it's // at least of what we guess is a reasonable minimum length, because we don't want a really short value // like "a" matching an image by ID prefix when the input was actually meant to specify an image name. if id == "" && len(ref) >= minimumTruncatedIDLength && !strings.ContainsAny(ref, "@:") { if img, err := store.Image(ref); err == nil && img != nil && strings.HasPrefix(img.ID, ref) { // It's a truncated version of the ID of an image that's present in local storage; // we need to expand it. id = img.ID ref = "" } } var named reference.Named // Unless we have an un-named "ID" or "@ID" reference (where ID might only have been a prefix), which has been // completely parsed above, the initial portion should be a name, possibly with a tag and/or a digest.. if ref != "" { var err error named, err = reference.ParseNormalizedNamed(ref) if err != nil { return nil, errors.Wrapf(err, "error parsing named reference %q", ref) } named = reference.TagNameOnly(named) } result, err := newReference(storageTransport{store: store, defaultUIDMap: s.defaultUIDMap, defaultGIDMap: s.defaultGIDMap}, named, id) if err != nil { return nil, err } logrus.Debugf("parsed reference into %q", result.StringWithinTransport()) return result, nil }
[ "func", "(", "s", "storageTransport", ")", "ParseStoreReference", "(", "store", "storage", ".", "Store", ",", "ref", "string", ")", "(", "*", "storageReference", ",", "error", ")", "{", "if", "ref", "==", "\"\"", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidReference", ",", "\"%q is an empty reference\"", ",", "ref", ")", "\n", "}", "\n", "if", "ref", "[", "0", "]", "==", "'['", "{", "closeIndex", ":=", "strings", ".", "IndexRune", "(", "ref", ",", "']'", ")", "\n", "if", "closeIndex", "<", "1", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidReference", ",", "\"store specifier in %q did not end\"", ",", "ref", ")", "\n", "}", "\n", "ref", "=", "ref", "[", "closeIndex", "+", "1", ":", "]", "\n", "}", "\n", "split", ":=", "strings", ".", "LastIndex", "(", "ref", ",", "\"@\"", ")", "\n", "id", ":=", "\"\"", "\n", "if", "split", "!=", "-", "1", "{", "possibleID", ":=", "ref", "[", "split", "+", "1", ":", "]", "\n", "if", "possibleID", "==", "\"\"", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidReference", ",", "\"empty trailing digest or ID in %q\"", ",", "ref", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "digest", ".", "Parse", "(", "possibleID", ")", ";", "err", "!=", "nil", "{", "if", "idSum", ",", "err", ":=", "digest", ".", "Parse", "(", "\"sha256:\"", "+", "possibleID", ")", ";", "err", "==", "nil", "&&", "idSum", ".", "Validate", "(", ")", "==", "nil", "{", "id", "=", "possibleID", "\n", "}", "else", "if", "img", ",", "err", ":=", "store", ".", "Image", "(", "possibleID", ")", ";", "err", "==", "nil", "&&", "img", "!=", "nil", "&&", "len", "(", "possibleID", ")", ">=", "minimumTruncatedIDLength", "&&", "strings", ".", "HasPrefix", "(", "img", ".", "ID", ",", "possibleID", ")", "{", "id", "=", "img", ".", "ID", "\n", "}", "else", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "ErrInvalidReference", ",", "\"%q does not look like an image ID or digest\"", ",", "possibleID", ")", "\n", "}", "\n", "ref", "=", "ref", "[", ":", "split", "]", "\n", "}", "\n", "}", "\n", "if", "id", "==", "\"\"", "&&", "len", "(", "ref", ")", ">=", "minimumTruncatedIDLength", "&&", "!", "strings", ".", "ContainsAny", "(", "ref", ",", "\"@:\"", ")", "{", "if", "img", ",", "err", ":=", "store", ".", "Image", "(", "ref", ")", ";", "err", "==", "nil", "&&", "img", "!=", "nil", "&&", "strings", ".", "HasPrefix", "(", "img", ".", "ID", ",", "ref", ")", "{", "id", "=", "img", ".", "ID", "\n", "ref", "=", "\"\"", "\n", "}", "\n", "}", "\n", "var", "named", "reference", ".", "Named", "\n", "if", "ref", "!=", "\"\"", "{", "var", "err", "error", "\n", "named", ",", "err", "=", "reference", ".", "ParseNormalizedNamed", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error parsing named reference %q\"", ",", "ref", ")", "\n", "}", "\n", "named", "=", "reference", ".", "TagNameOnly", "(", "named", ")", "\n", "}", "\n", "result", ",", "err", ":=", "newReference", "(", "storageTransport", "{", "store", ":", "store", ",", "defaultUIDMap", ":", "s", ".", "defaultUIDMap", ",", "defaultGIDMap", ":", "s", ".", "defaultGIDMap", "}", ",", "named", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"parsed reference into %q\"", ",", "result", ".", "StringWithinTransport", "(", ")", ")", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ParseStoreReference takes a name or an ID, tries to figure out which it is // relative to the given store, and returns it in a reference object.
[ "ParseStoreReference", "takes", "a", "name", "or", "an", "ID", "tries", "to", "figure", "out", "which", "it", "is", "relative", "to", "the", "given", "store", "and", "returns", "it", "in", "a", "reference", "object", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/storage/storage_transport.go#L108-L177
test
containers/image
image/docker_list.go
chooseDigestFromManifestList
func chooseDigestFromManifestList(sys *types.SystemContext, blob []byte) (digest.Digest, error) { wantedArch := runtime.GOARCH if sys != nil && sys.ArchitectureChoice != "" { wantedArch = sys.ArchitectureChoice } wantedOS := runtime.GOOS if sys != nil && sys.OSChoice != "" { wantedOS = sys.OSChoice } list := manifestList{} if err := json.Unmarshal(blob, &list); err != nil { return "", err } for _, d := range list.Manifests { if d.Platform.Architecture == wantedArch && d.Platform.OS == wantedOS { return d.Digest, nil } } return "", fmt.Errorf("no image found in manifest list for architecture %s, OS %s", wantedArch, wantedOS) }
go
func chooseDigestFromManifestList(sys *types.SystemContext, blob []byte) (digest.Digest, error) { wantedArch := runtime.GOARCH if sys != nil && sys.ArchitectureChoice != "" { wantedArch = sys.ArchitectureChoice } wantedOS := runtime.GOOS if sys != nil && sys.OSChoice != "" { wantedOS = sys.OSChoice } list := manifestList{} if err := json.Unmarshal(blob, &list); err != nil { return "", err } for _, d := range list.Manifests { if d.Platform.Architecture == wantedArch && d.Platform.OS == wantedOS { return d.Digest, nil } } return "", fmt.Errorf("no image found in manifest list for architecture %s, OS %s", wantedArch, wantedOS) }
[ "func", "chooseDigestFromManifestList", "(", "sys", "*", "types", ".", "SystemContext", ",", "blob", "[", "]", "byte", ")", "(", "digest", ".", "Digest", ",", "error", ")", "{", "wantedArch", ":=", "runtime", ".", "GOARCH", "\n", "if", "sys", "!=", "nil", "&&", "sys", ".", "ArchitectureChoice", "!=", "\"\"", "{", "wantedArch", "=", "sys", ".", "ArchitectureChoice", "\n", "}", "\n", "wantedOS", ":=", "runtime", ".", "GOOS", "\n", "if", "sys", "!=", "nil", "&&", "sys", ".", "OSChoice", "!=", "\"\"", "{", "wantedOS", "=", "sys", ".", "OSChoice", "\n", "}", "\n", "list", ":=", "manifestList", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "blob", ",", "&", "list", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "for", "_", ",", "d", ":=", "range", "list", ".", "Manifests", "{", "if", "d", ".", "Platform", ".", "Architecture", "==", "wantedArch", "&&", "d", ".", "Platform", ".", "OS", "==", "wantedOS", "{", "return", "d", ".", "Digest", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"no image found in manifest list for architecture %s, OS %s\"", ",", "wantedArch", ",", "wantedOS", ")", "\n", "}" ]
// chooseDigestFromManifestList parses blob as a schema2 manifest list, // and returns the digest of the image appropriate for the current environment.
[ "chooseDigestFromManifestList", "parses", "blob", "as", "a", "schema2", "manifest", "list", "and", "returns", "the", "digest", "of", "the", "image", "appropriate", "for", "the", "current", "environment", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/image/docker_list.go#L38-L58
test
containers/image
image/docker_list.go
ChooseManifestInstanceFromManifestList
func ChooseManifestInstanceFromManifestList(ctx context.Context, sys *types.SystemContext, src types.UnparsedImage) (digest.Digest, error) { // For now this only handles manifest.DockerV2ListMediaType; we can generalize it later, // probably along with manifest list editing. blob, mt, err := src.Manifest(ctx) if err != nil { return "", err } if mt != manifest.DockerV2ListMediaType { return "", fmt.Errorf("Internal error: Trying to select an image from a non-manifest-list manifest type %s", mt) } return chooseDigestFromManifestList(sys, blob) }
go
func ChooseManifestInstanceFromManifestList(ctx context.Context, sys *types.SystemContext, src types.UnparsedImage) (digest.Digest, error) { // For now this only handles manifest.DockerV2ListMediaType; we can generalize it later, // probably along with manifest list editing. blob, mt, err := src.Manifest(ctx) if err != nil { return "", err } if mt != manifest.DockerV2ListMediaType { return "", fmt.Errorf("Internal error: Trying to select an image from a non-manifest-list manifest type %s", mt) } return chooseDigestFromManifestList(sys, blob) }
[ "func", "ChooseManifestInstanceFromManifestList", "(", "ctx", "context", ".", "Context", ",", "sys", "*", "types", ".", "SystemContext", ",", "src", "types", ".", "UnparsedImage", ")", "(", "digest", ".", "Digest", ",", "error", ")", "{", "blob", ",", "mt", ",", "err", ":=", "src", ".", "Manifest", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "mt", "!=", "manifest", ".", "DockerV2ListMediaType", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Internal error: Trying to select an image from a non-manifest-list manifest type %s\"", ",", "mt", ")", "\n", "}", "\n", "return", "chooseDigestFromManifestList", "(", "sys", ",", "blob", ")", "\n", "}" ]
// ChooseManifestInstanceFromManifestList returns a digest of a manifest appropriate // for the current system from the manifest available from src.
[ "ChooseManifestInstanceFromManifestList", "returns", "a", "digest", "of", "a", "manifest", "appropriate", "for", "the", "current", "system", "from", "the", "manifest", "available", "from", "src", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/image/docker_list.go#L83-L94
test
containers/image
image/docker_schema1.go
manifestSchema1FromComponents
func manifestSchema1FromComponents(ref reference.Named, fsLayers []manifest.Schema1FSLayers, history []manifest.Schema1History, architecture string) (genericManifest, error) { m, err := manifest.Schema1FromComponents(ref, fsLayers, history, architecture) if err != nil { return nil, err } return &manifestSchema1{m: m}, nil }
go
func manifestSchema1FromComponents(ref reference.Named, fsLayers []manifest.Schema1FSLayers, history []manifest.Schema1History, architecture string) (genericManifest, error) { m, err := manifest.Schema1FromComponents(ref, fsLayers, history, architecture) if err != nil { return nil, err } return &manifestSchema1{m: m}, nil }
[ "func", "manifestSchema1FromComponents", "(", "ref", "reference", ".", "Named", ",", "fsLayers", "[", "]", "manifest", ".", "Schema1FSLayers", ",", "history", "[", "]", "manifest", ".", "Schema1History", ",", "architecture", "string", ")", "(", "genericManifest", ",", "error", ")", "{", "m", ",", "err", ":=", "manifest", ".", "Schema1FromComponents", "(", "ref", ",", "fsLayers", ",", "history", ",", "architecture", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "manifestSchema1", "{", "m", ":", "m", "}", ",", "nil", "\n", "}" ]
// manifestSchema1FromComponents builds a new manifestSchema1 from the supplied data.
[ "manifestSchema1FromComponents", "builds", "a", "new", "manifestSchema1", "from", "the", "supplied", "data", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/image/docker_schema1.go#L27-L33
test
containers/image
docker/docker_image_src.go
manifestDigest
func (s *dockerImageSource) manifestDigest(ctx context.Context, instanceDigest *digest.Digest) (digest.Digest, error) { if instanceDigest != nil { return *instanceDigest, nil } if digested, ok := s.ref.ref.(reference.Digested); ok { d := digested.Digest() if d.Algorithm() == digest.Canonical { return d, nil } } if err := s.ensureManifestIsLoaded(ctx); err != nil { return "", err } return manifest.Digest(s.cachedManifest) }
go
func (s *dockerImageSource) manifestDigest(ctx context.Context, instanceDigest *digest.Digest) (digest.Digest, error) { if instanceDigest != nil { return *instanceDigest, nil } if digested, ok := s.ref.ref.(reference.Digested); ok { d := digested.Digest() if d.Algorithm() == digest.Canonical { return d, nil } } if err := s.ensureManifestIsLoaded(ctx); err != nil { return "", err } return manifest.Digest(s.cachedManifest) }
[ "func", "(", "s", "*", "dockerImageSource", ")", "manifestDigest", "(", "ctx", "context", ".", "Context", ",", "instanceDigest", "*", "digest", ".", "Digest", ")", "(", "digest", ".", "Digest", ",", "error", ")", "{", "if", "instanceDigest", "!=", "nil", "{", "return", "*", "instanceDigest", ",", "nil", "\n", "}", "\n", "if", "digested", ",", "ok", ":=", "s", ".", "ref", ".", "ref", ".", "(", "reference", ".", "Digested", ")", ";", "ok", "{", "d", ":=", "digested", ".", "Digest", "(", ")", "\n", "if", "d", ".", "Algorithm", "(", ")", "==", "digest", ".", "Canonical", "{", "return", "d", ",", "nil", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "s", ".", "ensureManifestIsLoaded", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "manifest", ".", "Digest", "(", "s", ".", "cachedManifest", ")", "\n", "}" ]
// manifestDigest returns a digest of the manifest, from instanceDigest if non-nil; or from the supplied reference, // or finally, from a fetched manifest.
[ "manifestDigest", "returns", "a", "digest", "of", "the", "manifest", "from", "instanceDigest", "if", "non", "-", "nil", ";", "or", "from", "the", "supplied", "reference", "or", "finally", "from", "a", "fetched", "manifest", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/docker_image_src.go#L284-L298
test
containers/image
docker/docker_image_src.go
deleteImage
func deleteImage(ctx context.Context, sys *types.SystemContext, ref dockerReference) error { // docker/distribution does not document what action should be used for deleting images. // // Current docker/distribution requires "pull" for reading the manifest and "delete" for deleting it. // quay.io requires "push" (an explicit "pull" is unnecessary), does not grant any token (fails parsing the request) if "delete" is included. // OpenShift ignores the action string (both the password and the token is an OpenShift API token identifying a user). // // We have to hard-code a single string, luckily both docker/distribution and quay.io support "*" to mean "everything". c, err := newDockerClientFromRef(sys, ref, true, "*") if err != nil { return err } // When retrieving the digest from a registry >= 2.3 use the following header: // "Accept": "application/vnd.docker.distribution.manifest.v2+json" headers := make(map[string][]string) headers["Accept"] = []string{manifest.DockerV2Schema2MediaType} refTail, err := ref.tagOrDigest() if err != nil { return err } getPath := fmt.Sprintf(manifestPath, reference.Path(ref.ref), refTail) get, err := c.makeRequest(ctx, "GET", getPath, headers, nil, v2Auth, nil) if err != nil { return err } defer get.Body.Close() manifestBody, err := ioutil.ReadAll(get.Body) if err != nil { return err } switch get.StatusCode { case http.StatusOK: case http.StatusNotFound: return errors.Errorf("Unable to delete %v. Image may not exist or is not stored with a v2 Schema in a v2 registry", ref.ref) default: return errors.Errorf("Failed to delete %v: %s (%v)", ref.ref, manifestBody, get.Status) } digest := get.Header.Get("Docker-Content-Digest") deletePath := fmt.Sprintf(manifestPath, reference.Path(ref.ref), digest) // When retrieving the digest from a registry >= 2.3 use the following header: // "Accept": "application/vnd.docker.distribution.manifest.v2+json" delete, err := c.makeRequest(ctx, "DELETE", deletePath, headers, nil, v2Auth, nil) if err != nil { return err } defer delete.Body.Close() body, err := ioutil.ReadAll(delete.Body) if err != nil { return err } if delete.StatusCode != http.StatusAccepted { return errors.Errorf("Failed to delete %v: %s (%v)", deletePath, string(body), delete.Status) } if c.signatureBase != nil { manifestDigest, err := manifest.Digest(manifestBody) if err != nil { return err } for i := 0; ; i++ { url := signatureStorageURL(c.signatureBase, manifestDigest, i) if url == nil { return errors.Errorf("Internal error: signatureStorageURL with non-nil base returned nil") } missing, err := c.deleteOneSignature(url) if err != nil { return err } if missing { break } } } return nil }
go
func deleteImage(ctx context.Context, sys *types.SystemContext, ref dockerReference) error { // docker/distribution does not document what action should be used for deleting images. // // Current docker/distribution requires "pull" for reading the manifest and "delete" for deleting it. // quay.io requires "push" (an explicit "pull" is unnecessary), does not grant any token (fails parsing the request) if "delete" is included. // OpenShift ignores the action string (both the password and the token is an OpenShift API token identifying a user). // // We have to hard-code a single string, luckily both docker/distribution and quay.io support "*" to mean "everything". c, err := newDockerClientFromRef(sys, ref, true, "*") if err != nil { return err } // When retrieving the digest from a registry >= 2.3 use the following header: // "Accept": "application/vnd.docker.distribution.manifest.v2+json" headers := make(map[string][]string) headers["Accept"] = []string{manifest.DockerV2Schema2MediaType} refTail, err := ref.tagOrDigest() if err != nil { return err } getPath := fmt.Sprintf(manifestPath, reference.Path(ref.ref), refTail) get, err := c.makeRequest(ctx, "GET", getPath, headers, nil, v2Auth, nil) if err != nil { return err } defer get.Body.Close() manifestBody, err := ioutil.ReadAll(get.Body) if err != nil { return err } switch get.StatusCode { case http.StatusOK: case http.StatusNotFound: return errors.Errorf("Unable to delete %v. Image may not exist or is not stored with a v2 Schema in a v2 registry", ref.ref) default: return errors.Errorf("Failed to delete %v: %s (%v)", ref.ref, manifestBody, get.Status) } digest := get.Header.Get("Docker-Content-Digest") deletePath := fmt.Sprintf(manifestPath, reference.Path(ref.ref), digest) // When retrieving the digest from a registry >= 2.3 use the following header: // "Accept": "application/vnd.docker.distribution.manifest.v2+json" delete, err := c.makeRequest(ctx, "DELETE", deletePath, headers, nil, v2Auth, nil) if err != nil { return err } defer delete.Body.Close() body, err := ioutil.ReadAll(delete.Body) if err != nil { return err } if delete.StatusCode != http.StatusAccepted { return errors.Errorf("Failed to delete %v: %s (%v)", deletePath, string(body), delete.Status) } if c.signatureBase != nil { manifestDigest, err := manifest.Digest(manifestBody) if err != nil { return err } for i := 0; ; i++ { url := signatureStorageURL(c.signatureBase, manifestDigest, i) if url == nil { return errors.Errorf("Internal error: signatureStorageURL with non-nil base returned nil") } missing, err := c.deleteOneSignature(url) if err != nil { return err } if missing { break } } } return nil }
[ "func", "deleteImage", "(", "ctx", "context", ".", "Context", ",", "sys", "*", "types", ".", "SystemContext", ",", "ref", "dockerReference", ")", "error", "{", "c", ",", "err", ":=", "newDockerClientFromRef", "(", "sys", ",", "ref", ",", "true", ",", "\"*\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "headers", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "headers", "[", "\"Accept\"", "]", "=", "[", "]", "string", "{", "manifest", ".", "DockerV2Schema2MediaType", "}", "\n", "refTail", ",", "err", ":=", "ref", ".", "tagOrDigest", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "getPath", ":=", "fmt", ".", "Sprintf", "(", "manifestPath", ",", "reference", ".", "Path", "(", "ref", ".", "ref", ")", ",", "refTail", ")", "\n", "get", ",", "err", ":=", "c", ".", "makeRequest", "(", "ctx", ",", "\"GET\"", ",", "getPath", ",", "headers", ",", "nil", ",", "v2Auth", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "get", ".", "Body", ".", "Close", "(", ")", "\n", "manifestBody", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "get", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "switch", "get", ".", "StatusCode", "{", "case", "http", ".", "StatusOK", ":", "case", "http", ".", "StatusNotFound", ":", "return", "errors", ".", "Errorf", "(", "\"Unable to delete %v. Image may not exist or is not stored with a v2 Schema in a v2 registry\"", ",", "ref", ".", "ref", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"Failed to delete %v: %s (%v)\"", ",", "ref", ".", "ref", ",", "manifestBody", ",", "get", ".", "Status", ")", "\n", "}", "\n", "digest", ":=", "get", ".", "Header", ".", "Get", "(", "\"Docker-Content-Digest\"", ")", "\n", "deletePath", ":=", "fmt", ".", "Sprintf", "(", "manifestPath", ",", "reference", ".", "Path", "(", "ref", ".", "ref", ")", ",", "digest", ")", "\n", "delete", ",", "err", ":=", "c", ".", "makeRequest", "(", "ctx", ",", "\"DELETE\"", ",", "deletePath", ",", "headers", ",", "nil", ",", "v2Auth", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "delete", ".", "Body", ".", "Close", "(", ")", "\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "delete", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "delete", ".", "StatusCode", "!=", "http", ".", "StatusAccepted", "{", "return", "errors", ".", "Errorf", "(", "\"Failed to delete %v: %s (%v)\"", ",", "deletePath", ",", "string", "(", "body", ")", ",", "delete", ".", "Status", ")", "\n", "}", "\n", "if", "c", ".", "signatureBase", "!=", "nil", "{", "manifestDigest", ",", "err", ":=", "manifest", ".", "Digest", "(", "manifestBody", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "i", ":=", "0", ";", ";", "i", "++", "{", "url", ":=", "signatureStorageURL", "(", "c", ".", "signatureBase", ",", "manifestDigest", ",", "i", ")", "\n", "if", "url", "==", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"Internal error: signatureStorageURL with non-nil base returned nil\"", ")", "\n", "}", "\n", "missing", ",", "err", ":=", "c", ".", "deleteOneSignature", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "missing", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// deleteImage deletes the named image from the registry, if supported.
[ "deleteImage", "deletes", "the", "named", "image", "from", "the", "registry", "if", "supported", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/docker/docker_image_src.go#L393-L474
test
containers/image
manifest/docker_schema1.go
Schema1FromComponents
func Schema1FromComponents(ref reference.Named, fsLayers []Schema1FSLayers, history []Schema1History, architecture string) (*Schema1, error) { var name, tag string if ref != nil { // Well, what to do if it _is_ nil? Most consumers actually don't use these fields nowadays, so we might as well try not supplying them. name = reference.Path(ref) if tagged, ok := ref.(reference.NamedTagged); ok { tag = tagged.Tag() } } s1 := Schema1{ Name: name, Tag: tag, Architecture: architecture, FSLayers: fsLayers, History: history, SchemaVersion: 1, } if err := s1.initialize(); err != nil { return nil, err } return &s1, nil }
go
func Schema1FromComponents(ref reference.Named, fsLayers []Schema1FSLayers, history []Schema1History, architecture string) (*Schema1, error) { var name, tag string if ref != nil { // Well, what to do if it _is_ nil? Most consumers actually don't use these fields nowadays, so we might as well try not supplying them. name = reference.Path(ref) if tagged, ok := ref.(reference.NamedTagged); ok { tag = tagged.Tag() } } s1 := Schema1{ Name: name, Tag: tag, Architecture: architecture, FSLayers: fsLayers, History: history, SchemaVersion: 1, } if err := s1.initialize(); err != nil { return nil, err } return &s1, nil }
[ "func", "Schema1FromComponents", "(", "ref", "reference", ".", "Named", ",", "fsLayers", "[", "]", "Schema1FSLayers", ",", "history", "[", "]", "Schema1History", ",", "architecture", "string", ")", "(", "*", "Schema1", ",", "error", ")", "{", "var", "name", ",", "tag", "string", "\n", "if", "ref", "!=", "nil", "{", "name", "=", "reference", ".", "Path", "(", "ref", ")", "\n", "if", "tagged", ",", "ok", ":=", "ref", ".", "(", "reference", ".", "NamedTagged", ")", ";", "ok", "{", "tag", "=", "tagged", ".", "Tag", "(", ")", "\n", "}", "\n", "}", "\n", "s1", ":=", "Schema1", "{", "Name", ":", "name", ",", "Tag", ":", "tag", ",", "Architecture", ":", "architecture", ",", "FSLayers", ":", "fsLayers", ",", "History", ":", "history", ",", "SchemaVersion", ":", "1", ",", "}", "\n", "if", "err", ":=", "s1", ".", "initialize", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "s1", ",", "nil", "\n", "}" ]
// Schema1FromComponents creates an Schema1 manifest instance from the supplied data.
[ "Schema1FromComponents", "creates", "an", "Schema1", "manifest", "instance", "from", "the", "supplied", "data", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/docker_schema1.go#L73-L93
test
containers/image
manifest/docker_schema1.go
initialize
func (m *Schema1) initialize() error { if len(m.FSLayers) != len(m.History) { return errors.New("length of history not equal to number of layers") } if len(m.FSLayers) == 0 { return errors.New("no FSLayers in manifest") } m.ExtractedV1Compatibility = make([]Schema1V1Compatibility, len(m.History)) for i, h := range m.History { if err := json.Unmarshal([]byte(h.V1Compatibility), &m.ExtractedV1Compatibility[i]); err != nil { return errors.Wrapf(err, "Error parsing v2s1 history entry %d", i) } } return nil }
go
func (m *Schema1) initialize() error { if len(m.FSLayers) != len(m.History) { return errors.New("length of history not equal to number of layers") } if len(m.FSLayers) == 0 { return errors.New("no FSLayers in manifest") } m.ExtractedV1Compatibility = make([]Schema1V1Compatibility, len(m.History)) for i, h := range m.History { if err := json.Unmarshal([]byte(h.V1Compatibility), &m.ExtractedV1Compatibility[i]); err != nil { return errors.Wrapf(err, "Error parsing v2s1 history entry %d", i) } } return nil }
[ "func", "(", "m", "*", "Schema1", ")", "initialize", "(", ")", "error", "{", "if", "len", "(", "m", ".", "FSLayers", ")", "!=", "len", "(", "m", ".", "History", ")", "{", "return", "errors", ".", "New", "(", "\"length of history not equal to number of layers\"", ")", "\n", "}", "\n", "if", "len", "(", "m", ".", "FSLayers", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"no FSLayers in manifest\"", ")", "\n", "}", "\n", "m", ".", "ExtractedV1Compatibility", "=", "make", "(", "[", "]", "Schema1V1Compatibility", ",", "len", "(", "m", ".", "History", ")", ")", "\n", "for", "i", ",", "h", ":=", "range", "m", ".", "History", "{", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "h", ".", "V1Compatibility", ")", ",", "&", "m", ".", "ExtractedV1Compatibility", "[", "i", "]", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"Error parsing v2s1 history entry %d\"", ",", "i", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// initialize initializes ExtractedV1Compatibility and verifies invariants, so that the rest of this code can assume a minimally healthy manifest.
[ "initialize", "initializes", "ExtractedV1Compatibility", "and", "verifies", "invariants", "so", "that", "the", "rest", "of", "this", "code", "can", "assume", "a", "minimally", "healthy", "manifest", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/docker_schema1.go#L102-L116
test
containers/image
manifest/docker_schema1.go
ToSchema2Config
func (m *Schema1) ToSchema2Config(diffIDs []digest.Digest) ([]byte, error) { // Convert the schema 1 compat info into a schema 2 config, constructing some of the fields // that aren't directly comparable using info from the manifest. if len(m.History) == 0 { return nil, errors.New("image has no layers") } s1 := Schema2V1Image{} config := []byte(m.History[0].V1Compatibility) err := json.Unmarshal(config, &s1) if err != nil { return nil, errors.Wrapf(err, "error decoding configuration") } // Images created with versions prior to 1.8.3 require us to re-encode the encoded object, // adding some fields that aren't "omitempty". if s1.DockerVersion != "" && versions.LessThan(s1.DockerVersion, "1.8.3") { config, err = json.Marshal(&s1) if err != nil { return nil, errors.Wrapf(err, "error re-encoding compat image config %#v", s1) } } // Build the history. convertedHistory := []Schema2History{} for _, compat := range m.ExtractedV1Compatibility { hitem := Schema2History{ Created: compat.Created, CreatedBy: strings.Join(compat.ContainerConfig.Cmd, " "), Author: compat.Author, Comment: compat.Comment, EmptyLayer: compat.ThrowAway, } convertedHistory = append([]Schema2History{hitem}, convertedHistory...) } // Build the rootfs information. We need the decompressed sums that we've been // calculating to fill in the DiffIDs. It's expected (but not enforced by us) // that the number of diffIDs corresponds to the number of non-EmptyLayer // entries in the history. rootFS := &Schema2RootFS{ Type: "layers", DiffIDs: diffIDs, } // And now for some raw manipulation. raw := make(map[string]*json.RawMessage) err = json.Unmarshal(config, &raw) if err != nil { return nil, errors.Wrapf(err, "error re-decoding compat image config %#v", s1) } // Drop some fields. delete(raw, "id") delete(raw, "parent") delete(raw, "parent_id") delete(raw, "layer_id") delete(raw, "throwaway") delete(raw, "Size") // Add the history and rootfs information. rootfs, err := json.Marshal(rootFS) if err != nil { return nil, errors.Errorf("error encoding rootfs information %#v: %v", rootFS, err) } rawRootfs := json.RawMessage(rootfs) raw["rootfs"] = &rawRootfs history, err := json.Marshal(convertedHistory) if err != nil { return nil, errors.Errorf("error encoding history information %#v: %v", convertedHistory, err) } rawHistory := json.RawMessage(history) raw["history"] = &rawHistory // Encode the result. config, err = json.Marshal(raw) if err != nil { return nil, errors.Errorf("error re-encoding compat image config %#v: %v", s1, err) } return config, nil }
go
func (m *Schema1) ToSchema2Config(diffIDs []digest.Digest) ([]byte, error) { // Convert the schema 1 compat info into a schema 2 config, constructing some of the fields // that aren't directly comparable using info from the manifest. if len(m.History) == 0 { return nil, errors.New("image has no layers") } s1 := Schema2V1Image{} config := []byte(m.History[0].V1Compatibility) err := json.Unmarshal(config, &s1) if err != nil { return nil, errors.Wrapf(err, "error decoding configuration") } // Images created with versions prior to 1.8.3 require us to re-encode the encoded object, // adding some fields that aren't "omitempty". if s1.DockerVersion != "" && versions.LessThan(s1.DockerVersion, "1.8.3") { config, err = json.Marshal(&s1) if err != nil { return nil, errors.Wrapf(err, "error re-encoding compat image config %#v", s1) } } // Build the history. convertedHistory := []Schema2History{} for _, compat := range m.ExtractedV1Compatibility { hitem := Schema2History{ Created: compat.Created, CreatedBy: strings.Join(compat.ContainerConfig.Cmd, " "), Author: compat.Author, Comment: compat.Comment, EmptyLayer: compat.ThrowAway, } convertedHistory = append([]Schema2History{hitem}, convertedHistory...) } // Build the rootfs information. We need the decompressed sums that we've been // calculating to fill in the DiffIDs. It's expected (but not enforced by us) // that the number of diffIDs corresponds to the number of non-EmptyLayer // entries in the history. rootFS := &Schema2RootFS{ Type: "layers", DiffIDs: diffIDs, } // And now for some raw manipulation. raw := make(map[string]*json.RawMessage) err = json.Unmarshal(config, &raw) if err != nil { return nil, errors.Wrapf(err, "error re-decoding compat image config %#v", s1) } // Drop some fields. delete(raw, "id") delete(raw, "parent") delete(raw, "parent_id") delete(raw, "layer_id") delete(raw, "throwaway") delete(raw, "Size") // Add the history and rootfs information. rootfs, err := json.Marshal(rootFS) if err != nil { return nil, errors.Errorf("error encoding rootfs information %#v: %v", rootFS, err) } rawRootfs := json.RawMessage(rootfs) raw["rootfs"] = &rawRootfs history, err := json.Marshal(convertedHistory) if err != nil { return nil, errors.Errorf("error encoding history information %#v: %v", convertedHistory, err) } rawHistory := json.RawMessage(history) raw["history"] = &rawHistory // Encode the result. config, err = json.Marshal(raw) if err != nil { return nil, errors.Errorf("error re-encoding compat image config %#v: %v", s1, err) } return config, nil }
[ "func", "(", "m", "*", "Schema1", ")", "ToSchema2Config", "(", "diffIDs", "[", "]", "digest", ".", "Digest", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "len", "(", "m", ".", "History", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"image has no layers\"", ")", "\n", "}", "\n", "s1", ":=", "Schema2V1Image", "{", "}", "\n", "config", ":=", "[", "]", "byte", "(", "m", ".", "History", "[", "0", "]", ".", "V1Compatibility", ")", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "config", ",", "&", "s1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error decoding configuration\"", ")", "\n", "}", "\n", "if", "s1", ".", "DockerVersion", "!=", "\"\"", "&&", "versions", ".", "LessThan", "(", "s1", ".", "DockerVersion", ",", "\"1.8.3\"", ")", "{", "config", ",", "err", "=", "json", ".", "Marshal", "(", "&", "s1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error re-encoding compat image config %#v\"", ",", "s1", ")", "\n", "}", "\n", "}", "\n", "convertedHistory", ":=", "[", "]", "Schema2History", "{", "}", "\n", "for", "_", ",", "compat", ":=", "range", "m", ".", "ExtractedV1Compatibility", "{", "hitem", ":=", "Schema2History", "{", "Created", ":", "compat", ".", "Created", ",", "CreatedBy", ":", "strings", ".", "Join", "(", "compat", ".", "ContainerConfig", ".", "Cmd", ",", "\" \"", ")", ",", "Author", ":", "compat", ".", "Author", ",", "Comment", ":", "compat", ".", "Comment", ",", "EmptyLayer", ":", "compat", ".", "ThrowAway", ",", "}", "\n", "convertedHistory", "=", "append", "(", "[", "]", "Schema2History", "{", "hitem", "}", ",", "convertedHistory", "...", ")", "\n", "}", "\n", "rootFS", ":=", "&", "Schema2RootFS", "{", "Type", ":", "\"layers\"", ",", "DiffIDs", ":", "diffIDs", ",", "}", "\n", "raw", ":=", "make", "(", "map", "[", "string", "]", "*", "json", ".", "RawMessage", ")", "\n", "err", "=", "json", ".", "Unmarshal", "(", "config", ",", "&", "raw", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"error re-decoding compat image config %#v\"", ",", "s1", ")", "\n", "}", "\n", "delete", "(", "raw", ",", "\"id\"", ")", "\n", "delete", "(", "raw", ",", "\"parent\"", ")", "\n", "delete", "(", "raw", ",", "\"parent_id\"", ")", "\n", "delete", "(", "raw", ",", "\"layer_id\"", ")", "\n", "delete", "(", "raw", ",", "\"throwaway\"", ")", "\n", "delete", "(", "raw", ",", "\"Size\"", ")", "\n", "rootfs", ",", "err", ":=", "json", ".", "Marshal", "(", "rootFS", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"error encoding rootfs information %#v: %v\"", ",", "rootFS", ",", "err", ")", "\n", "}", "\n", "rawRootfs", ":=", "json", ".", "RawMessage", "(", "rootfs", ")", "\n", "raw", "[", "\"rootfs\"", "]", "=", "&", "rawRootfs", "\n", "history", ",", "err", ":=", "json", ".", "Marshal", "(", "convertedHistory", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"error encoding history information %#v: %v\"", ",", "convertedHistory", ",", "err", ")", "\n", "}", "\n", "rawHistory", ":=", "json", ".", "RawMessage", "(", "history", ")", "\n", "raw", "[", "\"history\"", "]", "=", "&", "rawHistory", "\n", "config", ",", "err", "=", "json", ".", "Marshal", "(", "raw", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"error re-encoding compat image config %#v: %v\"", ",", "s1", ",", "err", ")", "\n", "}", "\n", "return", "config", ",", "nil", "\n", "}" ]
// ToSchema2Config builds a schema2-style configuration blob using the supplied diffIDs.
[ "ToSchema2Config", "builds", "a", "schema2", "-", "style", "configuration", "blob", "using", "the", "supplied", "diffIDs", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/docker_schema1.go#L234-L306
test
containers/image
manifest/manifest.go
Digest
func Digest(manifest []byte) (digest.Digest, error) { if GuessMIMEType(manifest) == DockerV2Schema1SignedMediaType { sig, err := libtrust.ParsePrettySignature(manifest, "signatures") if err != nil { return "", err } manifest, err = sig.Payload() if err != nil { // Coverage: This should never happen, libtrust's Payload() can fail only if joseBase64UrlDecode() fails, on a string // that libtrust itself has josebase64UrlEncode()d return "", err } } return digest.FromBytes(manifest), nil }
go
func Digest(manifest []byte) (digest.Digest, error) { if GuessMIMEType(manifest) == DockerV2Schema1SignedMediaType { sig, err := libtrust.ParsePrettySignature(manifest, "signatures") if err != nil { return "", err } manifest, err = sig.Payload() if err != nil { // Coverage: This should never happen, libtrust's Payload() can fail only if joseBase64UrlDecode() fails, on a string // that libtrust itself has josebase64UrlEncode()d return "", err } } return digest.FromBytes(manifest), nil }
[ "func", "Digest", "(", "manifest", "[", "]", "byte", ")", "(", "digest", ".", "Digest", ",", "error", ")", "{", "if", "GuessMIMEType", "(", "manifest", ")", "==", "DockerV2Schema1SignedMediaType", "{", "sig", ",", "err", ":=", "libtrust", ".", "ParsePrettySignature", "(", "manifest", ",", "\"signatures\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "manifest", ",", "err", "=", "sig", ".", "Payload", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "}", "\n", "return", "digest", ".", "FromBytes", "(", "manifest", ")", ",", "nil", "\n", "}" ]
// Digest returns the a digest of a docker manifest, with any necessary implied transformations like stripping v1s1 signatures.
[ "Digest", "returns", "the", "a", "digest", "of", "a", "docker", "manifest", "with", "any", "necessary", "implied", "transformations", "like", "stripping", "v1s1", "signatures", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/manifest.go#L139-L154
test
containers/image
manifest/manifest.go
MatchesDigest
func MatchesDigest(manifest []byte, expectedDigest digest.Digest) (bool, error) { // This should eventually support various digest types. actualDigest, err := Digest(manifest) if err != nil { return false, err } return expectedDigest == actualDigest, nil }
go
func MatchesDigest(manifest []byte, expectedDigest digest.Digest) (bool, error) { // This should eventually support various digest types. actualDigest, err := Digest(manifest) if err != nil { return false, err } return expectedDigest == actualDigest, nil }
[ "func", "MatchesDigest", "(", "manifest", "[", "]", "byte", ",", "expectedDigest", "digest", ".", "Digest", ")", "(", "bool", ",", "error", ")", "{", "actualDigest", ",", "err", ":=", "Digest", "(", "manifest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "expectedDigest", "==", "actualDigest", ",", "nil", "\n", "}" ]
// MatchesDigest returns true iff the manifest matches expectedDigest. // Error may be set if this returns false. // Note that this is not doing ConstantTimeCompare; by the time we get here, the cryptographic signature must already have been verified, // or we are not using a cryptographic channel and the attacker can modify the digest along with the manifest blob.
[ "MatchesDigest", "returns", "true", "iff", "the", "manifest", "matches", "expectedDigest", ".", "Error", "may", "be", "set", "if", "this", "returns", "false", ".", "Note", "that", "this", "is", "not", "doing", "ConstantTimeCompare", ";", "by", "the", "time", "we", "get", "here", "the", "cryptographic", "signature", "must", "already", "have", "been", "verified", "or", "we", "are", "not", "using", "a", "cryptographic", "channel", "and", "the", "attacker", "can", "modify", "the", "digest", "along", "with", "the", "manifest", "blob", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/manifest.go#L160-L167
test
containers/image
manifest/manifest.go
NormalizedMIMEType
func NormalizedMIMEType(input string) string { switch input { // "application/json" is a valid v2s1 value per https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md . // This works for now, when nothing else seems to return "application/json"; if that were not true, the mapping/detection might // need to happen within the ImageSource. case "application/json": return DockerV2Schema1SignedMediaType case DockerV2Schema1MediaType, DockerV2Schema1SignedMediaType, imgspecv1.MediaTypeImageManifest, DockerV2Schema2MediaType, DockerV2ListMediaType: return input default: // If it's not a recognized manifest media type, or we have failed determining the type, we'll try one last time // to deserialize using v2s1 as per https://github.com/docker/distribution/blob/master/manifests.go#L108 // and https://github.com/docker/distribution/blob/master/manifest/schema1/manifest.go#L50 // // Crane registries can also return "text/plain", or pretty much anything else depending on a file extension “recognized” in the tag. // This makes no real sense, but it happens // because requests for manifests are // redirected to a content distribution // network which is configured that way. See https://bugzilla.redhat.com/show_bug.cgi?id=1389442 return DockerV2Schema1SignedMediaType } }
go
func NormalizedMIMEType(input string) string { switch input { // "application/json" is a valid v2s1 value per https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md . // This works for now, when nothing else seems to return "application/json"; if that were not true, the mapping/detection might // need to happen within the ImageSource. case "application/json": return DockerV2Schema1SignedMediaType case DockerV2Schema1MediaType, DockerV2Schema1SignedMediaType, imgspecv1.MediaTypeImageManifest, DockerV2Schema2MediaType, DockerV2ListMediaType: return input default: // If it's not a recognized manifest media type, or we have failed determining the type, we'll try one last time // to deserialize using v2s1 as per https://github.com/docker/distribution/blob/master/manifests.go#L108 // and https://github.com/docker/distribution/blob/master/manifest/schema1/manifest.go#L50 // // Crane registries can also return "text/plain", or pretty much anything else depending on a file extension “recognized” in the tag. // This makes no real sense, but it happens // because requests for manifests are // redirected to a content distribution // network which is configured that way. See https://bugzilla.redhat.com/show_bug.cgi?id=1389442 return DockerV2Schema1SignedMediaType } }
[ "func", "NormalizedMIMEType", "(", "input", "string", ")", "string", "{", "switch", "input", "{", "case", "\"application/json\"", ":", "return", "DockerV2Schema1SignedMediaType", "\n", "case", "DockerV2Schema1MediaType", ",", "DockerV2Schema1SignedMediaType", ",", "imgspecv1", ".", "MediaTypeImageManifest", ",", "DockerV2Schema2MediaType", ",", "DockerV2ListMediaType", ":", "return", "input", "\n", "default", ":", "return", "DockerV2Schema1SignedMediaType", "\n", "}", "\n", "}" ]
// NormalizedMIMEType returns the effective MIME type of a manifest MIME type returned by a server, // centralizing various workarounds.
[ "NormalizedMIMEType", "returns", "the", "effective", "MIME", "type", "of", "a", "manifest", "MIME", "type", "returned", "by", "a", "server", "centralizing", "various", "workarounds", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/manifest.go#L194-L218
test
containers/image
manifest/manifest.go
FromBlob
func FromBlob(manblob []byte, mt string) (Manifest, error) { switch NormalizedMIMEType(mt) { case DockerV2Schema1MediaType, DockerV2Schema1SignedMediaType: return Schema1FromManifest(manblob) case imgspecv1.MediaTypeImageManifest: return OCI1FromManifest(manblob) case DockerV2Schema2MediaType: return Schema2FromManifest(manblob) case DockerV2ListMediaType: return nil, fmt.Errorf("Treating manifest lists as individual manifests is not implemented") default: // Note that this may not be reachable, NormalizedMIMEType has a default for unknown values. return nil, fmt.Errorf("Unimplemented manifest MIME type %s", mt) } }
go
func FromBlob(manblob []byte, mt string) (Manifest, error) { switch NormalizedMIMEType(mt) { case DockerV2Schema1MediaType, DockerV2Schema1SignedMediaType: return Schema1FromManifest(manblob) case imgspecv1.MediaTypeImageManifest: return OCI1FromManifest(manblob) case DockerV2Schema2MediaType: return Schema2FromManifest(manblob) case DockerV2ListMediaType: return nil, fmt.Errorf("Treating manifest lists as individual manifests is not implemented") default: // Note that this may not be reachable, NormalizedMIMEType has a default for unknown values. return nil, fmt.Errorf("Unimplemented manifest MIME type %s", mt) } }
[ "func", "FromBlob", "(", "manblob", "[", "]", "byte", ",", "mt", "string", ")", "(", "Manifest", ",", "error", ")", "{", "switch", "NormalizedMIMEType", "(", "mt", ")", "{", "case", "DockerV2Schema1MediaType", ",", "DockerV2Schema1SignedMediaType", ":", "return", "Schema1FromManifest", "(", "manblob", ")", "\n", "case", "imgspecv1", ".", "MediaTypeImageManifest", ":", "return", "OCI1FromManifest", "(", "manblob", ")", "\n", "case", "DockerV2Schema2MediaType", ":", "return", "Schema2FromManifest", "(", "manblob", ")", "\n", "case", "DockerV2ListMediaType", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Treating manifest lists as individual manifests is not implemented\"", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Unimplemented manifest MIME type %s\"", ",", "mt", ")", "\n", "}", "\n", "}" ]
// FromBlob returns a Manifest instance for the specified manifest blob and the corresponding MIME type
[ "FromBlob", "returns", "a", "Manifest", "instance", "for", "the", "specified", "manifest", "blob", "and", "the", "corresponding", "MIME", "type" ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/manifest/manifest.go#L221-L234
test
containers/image
directory/directory_transport.go
NewReference
func NewReference(path string) (types.ImageReference, error) { resolved, err := explicitfilepath.ResolvePathToFullyExplicit(path) if err != nil { return nil, err } return dirReference{path: path, resolvedPath: resolved}, nil }
go
func NewReference(path string) (types.ImageReference, error) { resolved, err := explicitfilepath.ResolvePathToFullyExplicit(path) if err != nil { return nil, err } return dirReference{path: path, resolvedPath: resolved}, nil }
[ "func", "NewReference", "(", "path", "string", ")", "(", "types", ".", "ImageReference", ",", "error", ")", "{", "resolved", ",", "err", ":=", "explicitfilepath", ".", "ResolvePathToFullyExplicit", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "dirReference", "{", "path", ":", "path", ",", "resolvedPath", ":", "resolved", "}", ",", "nil", "\n", "}" ]
// There is no directory.ParseReference because it is rather pointless. // Callers who need a transport-independent interface will go through // dirTransport.ParseReference; callers who intentionally deal with directories // can use directory.NewReference. // NewReference returns a directory reference for a specified path. // // We do not expose an API supplying the resolvedPath; we could, but recomputing it // is generally cheap enough that we prefer being confident about the properties of resolvedPath.
[ "There", "is", "no", "directory", ".", "ParseReference", "because", "it", "is", "rather", "pointless", ".", "Callers", "who", "need", "a", "transport", "-", "independent", "interface", "will", "go", "through", "dirTransport", ".", "ParseReference", ";", "callers", "who", "intentionally", "deal", "with", "directories", "can", "use", "directory", ".", "NewReference", ".", "NewReference", "returns", "a", "directory", "reference", "for", "a", "specified", "path", ".", "We", "do", "not", "expose", "an", "API", "supplying", "the", "resolvedPath", ";", "we", "could", "but", "recomputing", "it", "is", "generally", "cheap", "enough", "that", "we", "prefer", "being", "confident", "about", "the", "properties", "of", "resolvedPath", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_transport.go#L77-L83
test
containers/image
directory/directory_transport.go
layerPath
func (ref dirReference) layerPath(digest digest.Digest) string { // FIXME: Should we keep the digest identification? return filepath.Join(ref.path, digest.Hex()) }
go
func (ref dirReference) layerPath(digest digest.Digest) string { // FIXME: Should we keep the digest identification? return filepath.Join(ref.path, digest.Hex()) }
[ "func", "(", "ref", "dirReference", ")", "layerPath", "(", "digest", "digest", ".", "Digest", ")", "string", "{", "return", "filepath", ".", "Join", "(", "ref", ".", "path", ",", "digest", ".", "Hex", "(", ")", ")", "\n", "}" ]
// layerPath returns a path for a layer tarball within a directory using our conventions.
[ "layerPath", "returns", "a", "path", "for", "a", "layer", "tarball", "within", "a", "directory", "using", "our", "conventions", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_transport.go#L174-L177
test
containers/image
directory/directory_transport.go
signaturePath
func (ref dirReference) signaturePath(index int) string { return filepath.Join(ref.path, fmt.Sprintf("signature-%d", index+1)) }
go
func (ref dirReference) signaturePath(index int) string { return filepath.Join(ref.path, fmt.Sprintf("signature-%d", index+1)) }
[ "func", "(", "ref", "dirReference", ")", "signaturePath", "(", "index", "int", ")", "string", "{", "return", "filepath", ".", "Join", "(", "ref", ".", "path", ",", "fmt", ".", "Sprintf", "(", "\"signature-%d\"", ",", "index", "+", "1", ")", ")", "\n", "}" ]
// signaturePath returns a path for a signature within a directory using our conventions.
[ "signaturePath", "returns", "a", "path", "for", "a", "signature", "within", "a", "directory", "using", "our", "conventions", "." ]
da9ab3561ad2031aeb5e036b7cf2755d4e246fec
https://github.com/containers/image/blob/da9ab3561ad2031aeb5e036b7cf2755d4e246fec/directory/directory_transport.go#L180-L182
test
Jeffail/tunny
tunny.go
New
func New(n int, ctor func() Worker) *Pool { p := &Pool{ ctor: ctor, reqChan: make(chan workRequest), } p.SetSize(n) return p }
go
func New(n int, ctor func() Worker) *Pool { p := &Pool{ ctor: ctor, reqChan: make(chan workRequest), } p.SetSize(n) return p }
[ "func", "New", "(", "n", "int", ",", "ctor", "func", "(", ")", "Worker", ")", "*", "Pool", "{", "p", ":=", "&", "Pool", "{", "ctor", ":", "ctor", ",", "reqChan", ":", "make", "(", "chan", "workRequest", ")", ",", "}", "\n", "p", ".", "SetSize", "(", "n", ")", "\n", "return", "p", "\n", "}" ]
// New creates a new Pool of workers that starts with n workers. You must // provide a constructor function that creates new Worker types and when you // change the size of the pool the constructor will be called to create each new // Worker.
[ "New", "creates", "a", "new", "Pool", "of", "workers", "that", "starts", "with", "n", "workers", ".", "You", "must", "provide", "a", "constructor", "function", "that", "creates", "new", "Worker", "types", "and", "when", "you", "change", "the", "size", "of", "the", "pool", "the", "constructor", "will", "be", "called", "to", "create", "each", "new", "Worker", "." ]
4921fff29480bad359ad2fb3271fb461c8ffe1fc
https://github.com/Jeffail/tunny/blob/4921fff29480bad359ad2fb3271fb461c8ffe1fc/tunny.go#L119-L127
test
Jeffail/tunny
tunny.go
NewFunc
func NewFunc(n int, f func(interface{}) interface{}) *Pool { return New(n, func() Worker { return &closureWorker{ processor: f, } }) }
go
func NewFunc(n int, f func(interface{}) interface{}) *Pool { return New(n, func() Worker { return &closureWorker{ processor: f, } }) }
[ "func", "NewFunc", "(", "n", "int", ",", "f", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "*", "Pool", "{", "return", "New", "(", "n", ",", "func", "(", ")", "Worker", "{", "return", "&", "closureWorker", "{", "processor", ":", "f", ",", "}", "\n", "}", ")", "\n", "}" ]
// NewFunc creates a new Pool of workers where each worker will process using // the provided func.
[ "NewFunc", "creates", "a", "new", "Pool", "of", "workers", "where", "each", "worker", "will", "process", "using", "the", "provided", "func", "." ]
4921fff29480bad359ad2fb3271fb461c8ffe1fc
https://github.com/Jeffail/tunny/blob/4921fff29480bad359ad2fb3271fb461c8ffe1fc/tunny.go#L131-L137
test
Jeffail/tunny
tunny.go
ProcessTimed
func (p *Pool) ProcessTimed( payload interface{}, timeout time.Duration, ) (interface{}, error) { atomic.AddInt64(&p.queuedJobs, 1) defer atomic.AddInt64(&p.queuedJobs, -1) tout := time.NewTimer(timeout) var request workRequest var open bool select { case request, open = <-p.reqChan: if !open { return nil, ErrPoolNotRunning } case <-tout.C: return nil, ErrJobTimedOut } select { case request.jobChan <- payload: case <-tout.C: request.interruptFunc() return nil, ErrJobTimedOut } select { case payload, open = <-request.retChan: if !open { return nil, ErrWorkerClosed } case <-tout.C: request.interruptFunc() return nil, ErrJobTimedOut } tout.Stop() return payload, nil }
go
func (p *Pool) ProcessTimed( payload interface{}, timeout time.Duration, ) (interface{}, error) { atomic.AddInt64(&p.queuedJobs, 1) defer atomic.AddInt64(&p.queuedJobs, -1) tout := time.NewTimer(timeout) var request workRequest var open bool select { case request, open = <-p.reqChan: if !open { return nil, ErrPoolNotRunning } case <-tout.C: return nil, ErrJobTimedOut } select { case request.jobChan <- payload: case <-tout.C: request.interruptFunc() return nil, ErrJobTimedOut } select { case payload, open = <-request.retChan: if !open { return nil, ErrWorkerClosed } case <-tout.C: request.interruptFunc() return nil, ErrJobTimedOut } tout.Stop() return payload, nil }
[ "func", "(", "p", "*", "Pool", ")", "ProcessTimed", "(", "payload", "interface", "{", "}", ",", "timeout", "time", ".", "Duration", ",", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "atomic", ".", "AddInt64", "(", "&", "p", ".", "queuedJobs", ",", "1", ")", "\n", "defer", "atomic", ".", "AddInt64", "(", "&", "p", ".", "queuedJobs", ",", "-", "1", ")", "\n", "tout", ":=", "time", ".", "NewTimer", "(", "timeout", ")", "\n", "var", "request", "workRequest", "\n", "var", "open", "bool", "\n", "select", "{", "case", "request", ",", "open", "=", "<-", "p", ".", "reqChan", ":", "if", "!", "open", "{", "return", "nil", ",", "ErrPoolNotRunning", "\n", "}", "\n", "case", "<-", "tout", ".", "C", ":", "return", "nil", ",", "ErrJobTimedOut", "\n", "}", "\n", "select", "{", "case", "request", ".", "jobChan", "<-", "payload", ":", "case", "<-", "tout", ".", "C", ":", "request", ".", "interruptFunc", "(", ")", "\n", "return", "nil", ",", "ErrJobTimedOut", "\n", "}", "\n", "select", "{", "case", "payload", ",", "open", "=", "<-", "request", ".", "retChan", ":", "if", "!", "open", "{", "return", "nil", ",", "ErrWorkerClosed", "\n", "}", "\n", "case", "<-", "tout", ".", "C", ":", "request", ".", "interruptFunc", "(", ")", "\n", "return", "nil", ",", "ErrJobTimedOut", "\n", "}", "\n", "tout", ".", "Stop", "(", ")", "\n", "return", "payload", ",", "nil", "\n", "}" ]
// ProcessTimed will use the Pool to process a payload and synchronously return // the result. If the timeout occurs before the job has finished the worker will // be interrupted and ErrJobTimedOut will be returned. ProcessTimed can be // called safely by any goroutines.
[ "ProcessTimed", "will", "use", "the", "Pool", "to", "process", "a", "payload", "and", "synchronously", "return", "the", "result", ".", "If", "the", "timeout", "occurs", "before", "the", "job", "has", "finished", "the", "worker", "will", "be", "interrupted", "and", "ErrJobTimedOut", "will", "be", "returned", ".", "ProcessTimed", "can", "be", "called", "safely", "by", "any", "goroutines", "." ]
4921fff29480bad359ad2fb3271fb461c8ffe1fc
https://github.com/Jeffail/tunny/blob/4921fff29480bad359ad2fb3271fb461c8ffe1fc/tunny.go#L175-L215
test
Jeffail/tunny
tunny.go
SetSize
func (p *Pool) SetSize(n int) { p.workerMut.Lock() defer p.workerMut.Unlock() lWorkers := len(p.workers) if lWorkers == n { return } // Add extra workers if N > len(workers) for i := lWorkers; i < n; i++ { p.workers = append(p.workers, newWorkerWrapper(p.reqChan, p.ctor())) } // Asynchronously stop all workers > N for i := n; i < lWorkers; i++ { p.workers[i].stop() } // Synchronously wait for all workers > N to stop for i := n; i < lWorkers; i++ { p.workers[i].join() } // Remove stopped workers from slice p.workers = p.workers[:n] }
go
func (p *Pool) SetSize(n int) { p.workerMut.Lock() defer p.workerMut.Unlock() lWorkers := len(p.workers) if lWorkers == n { return } // Add extra workers if N > len(workers) for i := lWorkers; i < n; i++ { p.workers = append(p.workers, newWorkerWrapper(p.reqChan, p.ctor())) } // Asynchronously stop all workers > N for i := n; i < lWorkers; i++ { p.workers[i].stop() } // Synchronously wait for all workers > N to stop for i := n; i < lWorkers; i++ { p.workers[i].join() } // Remove stopped workers from slice p.workers = p.workers[:n] }
[ "func", "(", "p", "*", "Pool", ")", "SetSize", "(", "n", "int", ")", "{", "p", ".", "workerMut", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "workerMut", ".", "Unlock", "(", ")", "\n", "lWorkers", ":=", "len", "(", "p", ".", "workers", ")", "\n", "if", "lWorkers", "==", "n", "{", "return", "\n", "}", "\n", "for", "i", ":=", "lWorkers", ";", "i", "<", "n", ";", "i", "++", "{", "p", ".", "workers", "=", "append", "(", "p", ".", "workers", ",", "newWorkerWrapper", "(", "p", ".", "reqChan", ",", "p", ".", "ctor", "(", ")", ")", ")", "\n", "}", "\n", "for", "i", ":=", "n", ";", "i", "<", "lWorkers", ";", "i", "++", "{", "p", ".", "workers", "[", "i", "]", ".", "stop", "(", ")", "\n", "}", "\n", "for", "i", ":=", "n", ";", "i", "<", "lWorkers", ";", "i", "++", "{", "p", ".", "workers", "[", "i", "]", ".", "join", "(", ")", "\n", "}", "\n", "p", ".", "workers", "=", "p", ".", "workers", "[", ":", "n", "]", "\n", "}" ]
// SetSize changes the total number of workers in the Pool. This can be called // by any goroutine at any time unless the Pool has been stopped, in which case // a panic will occur.
[ "SetSize", "changes", "the", "total", "number", "of", "workers", "in", "the", "Pool", ".", "This", "can", "be", "called", "by", "any", "goroutine", "at", "any", "time", "unless", "the", "Pool", "has", "been", "stopped", "in", "which", "case", "a", "panic", "will", "occur", "." ]
4921fff29480bad359ad2fb3271fb461c8ffe1fc
https://github.com/Jeffail/tunny/blob/4921fff29480bad359ad2fb3271fb461c8ffe1fc/tunny.go#L225-L251
test
Jeffail/tunny
tunny.go
GetSize
func (p *Pool) GetSize() int { p.workerMut.Lock() defer p.workerMut.Unlock() return len(p.workers) }
go
func (p *Pool) GetSize() int { p.workerMut.Lock() defer p.workerMut.Unlock() return len(p.workers) }
[ "func", "(", "p", "*", "Pool", ")", "GetSize", "(", ")", "int", "{", "p", ".", "workerMut", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "workerMut", ".", "Unlock", "(", ")", "\n", "return", "len", "(", "p", ".", "workers", ")", "\n", "}" ]
// GetSize returns the current size of the pool.
[ "GetSize", "returns", "the", "current", "size", "of", "the", "pool", "." ]
4921fff29480bad359ad2fb3271fb461c8ffe1fc
https://github.com/Jeffail/tunny/blob/4921fff29480bad359ad2fb3271fb461c8ffe1fc/tunny.go#L254-L259
test
go-opencv/go-opencv
opencv/cxtype.go
TL
func (r *Rect) TL() Point { return Point{int(r.x), int(r.y)} }
go
func (r *Rect) TL() Point { return Point{int(r.x), int(r.y)} }
[ "func", "(", "r", "*", "Rect", ")", "TL", "(", ")", "Point", "{", "return", "Point", "{", "int", "(", "r", ".", "x", ")", ",", "int", "(", "r", ".", "y", ")", "}", "\n", "}" ]
// Returns the Top-Left Point of the rectangle
[ "Returns", "the", "Top", "-", "Left", "Point", "of", "the", "rectangle" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxtype.go#L526-L528
test
go-opencv/go-opencv
opencv/cxtype.go
BR
func (r *Rect) BR() Point { return Point{int(r.x) + int(r.width), int(r.y) + int(r.height)} }
go
func (r *Rect) BR() Point { return Point{int(r.x) + int(r.width), int(r.y) + int(r.height)} }
[ "func", "(", "r", "*", "Rect", ")", "BR", "(", ")", "Point", "{", "return", "Point", "{", "int", "(", "r", ".", "x", ")", "+", "int", "(", "r", ".", "width", ")", ",", "int", "(", "r", ".", "y", ")", "+", "int", "(", "r", ".", "height", ")", "}", "\n", "}" ]
// Returns the Bottom-Right Point of the rectangle
[ "Returns", "the", "Bottom", "-", "Right", "Point", "of", "the", "rectangle" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxtype.go#L531-L533
test
go-opencv/go-opencv
opencv/cxtype.go
CVBox
func (box *Box2D) CVBox() C.CvBox2D { var cvBox C.CvBox2D cvBox.angle = C.float(box.angle) cvBox.center.x = C.float(box.center.X) cvBox.center.y = C.float(box.center.Y) cvBox.size.width = C.float(box.size.Width) cvBox.size.height = C.float(box.size.Height) return cvBox }
go
func (box *Box2D) CVBox() C.CvBox2D { var cvBox C.CvBox2D cvBox.angle = C.float(box.angle) cvBox.center.x = C.float(box.center.X) cvBox.center.y = C.float(box.center.Y) cvBox.size.width = C.float(box.size.Width) cvBox.size.height = C.float(box.size.Height) return cvBox }
[ "func", "(", "box", "*", "Box2D", ")", "CVBox", "(", ")", "C", ".", "CvBox2D", "{", "var", "cvBox", "C", ".", "CvBox2D", "\n", "cvBox", ".", "angle", "=", "C", ".", "float", "(", "box", ".", "angle", ")", "\n", "cvBox", ".", "center", ".", "x", "=", "C", ".", "float", "(", "box", ".", "center", ".", "X", ")", "\n", "cvBox", ".", "center", ".", "y", "=", "C", ".", "float", "(", "box", ".", "center", ".", "Y", ")", "\n", "cvBox", ".", "size", ".", "width", "=", "C", ".", "float", "(", "box", ".", "size", ".", "Width", ")", "\n", "cvBox", ".", "size", ".", "height", "=", "C", ".", "float", "(", "box", ".", "size", ".", "Height", ")", "\n", "return", "cvBox", "\n", "}" ]
// Returns a CvBox2D
[ "Returns", "a", "CvBox2D" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxtype.go#L833-L841
test
go-opencv/go-opencv
opencv/cxtype.go
Points
func (box *Box2D) Points() []Point2D32f { var pts [4]C.CvPoint2D32f C.cvBoxPoints( box.CVBox(), (*C.CvPoint2D32f)(unsafe.Pointer(&pts[0])), ) outPts := make([]Point2D32f, 4) for i, p := range pts { outPts[i].X = float32(p.x) outPts[i].Y = float32(p.y) } return outPts }
go
func (box *Box2D) Points() []Point2D32f { var pts [4]C.CvPoint2D32f C.cvBoxPoints( box.CVBox(), (*C.CvPoint2D32f)(unsafe.Pointer(&pts[0])), ) outPts := make([]Point2D32f, 4) for i, p := range pts { outPts[i].X = float32(p.x) outPts[i].Y = float32(p.y) } return outPts }
[ "func", "(", "box", "*", "Box2D", ")", "Points", "(", ")", "[", "]", "Point2D32f", "{", "var", "pts", "[", "4", "]", "C", ".", "CvPoint2D32f", "\n", "C", ".", "cvBoxPoints", "(", "box", ".", "CVBox", "(", ")", ",", "(", "*", "C", ".", "CvPoint2D32f", ")", "(", "unsafe", ".", "Pointer", "(", "&", "pts", "[", "0", "]", ")", ")", ",", ")", "\n", "outPts", ":=", "make", "(", "[", "]", "Point2D32f", ",", "4", ")", "\n", "for", "i", ",", "p", ":=", "range", "pts", "{", "outPts", "[", "i", "]", ".", "X", "=", "float32", "(", "p", ".", "x", ")", "\n", "outPts", "[", "i", "]", ".", "Y", "=", "float32", "(", "p", ".", "y", ")", "\n", "}", "\n", "return", "outPts", "\n", "}" ]
// Finds box vertices
[ "Finds", "box", "vertices" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxtype.go#L844-L856
test
go-opencv/go-opencv
opencv/highgui.go
FOURCC
func FOURCC(c1, c2, c3, c4 int8) uint32 { rv := C.GoOpenCV_FOURCC_(C.int(c1), C.int(c2), C.int(c3), C.int(c4)) return uint32(rv) }
go
func FOURCC(c1, c2, c3, c4 int8) uint32 { rv := C.GoOpenCV_FOURCC_(C.int(c1), C.int(c2), C.int(c3), C.int(c4)) return uint32(rv) }
[ "func", "FOURCC", "(", "c1", ",", "c2", ",", "c3", ",", "c4", "int8", ")", "uint32", "{", "rv", ":=", "C", ".", "GoOpenCV_FOURCC_", "(", "C", ".", "int", "(", "c1", ")", ",", "C", ".", "int", "(", "c2", ")", ",", "C", ".", "int", "(", "c3", ")", ",", "C", ".", "int", "(", "c4", ")", ")", "\n", "return", "uint32", "(", "rv", ")", "\n", "}" ]
// Prototype for CV_FOURCC so that swig can generate wrapper without mixing up the define
[ "Prototype", "for", "CV_FOURCC", "so", "that", "swig", "can", "generate", "wrapper", "without", "mixing", "up", "the", "define" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/highgui.go#L574-L577
test
go-opencv/go-opencv
opencv/cxcore.go
Merge
func Merge(imgBlue, imgGreen, imgRed, imgAlpha, dst *IplImage) { C.cvMerge( unsafe.Pointer(imgBlue), unsafe.Pointer(imgGreen), unsafe.Pointer(imgRed), unsafe.Pointer(imgAlpha), unsafe.Pointer(dst), ) }
go
func Merge(imgBlue, imgGreen, imgRed, imgAlpha, dst *IplImage) { C.cvMerge( unsafe.Pointer(imgBlue), unsafe.Pointer(imgGreen), unsafe.Pointer(imgRed), unsafe.Pointer(imgAlpha), unsafe.Pointer(dst), ) }
[ "func", "Merge", "(", "imgBlue", ",", "imgGreen", ",", "imgRed", ",", "imgAlpha", ",", "dst", "*", "IplImage", ")", "{", "C", ".", "cvMerge", "(", "unsafe", ".", "Pointer", "(", "imgBlue", ")", ",", "unsafe", ".", "Pointer", "(", "imgGreen", ")", ",", "unsafe", ".", "Pointer", "(", "imgRed", ")", ",", "unsafe", ".", "Pointer", "(", "imgAlpha", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", ")", "\n", "}" ]
// Merge creates one multichannel array out of several single-channel ones.
[ "Merge", "creates", "one", "multichannel", "array", "out", "of", "several", "single", "-", "channel", "ones", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L58-L66
test
go-opencv/go-opencv
opencv/cxcore.go
Split
func Split(src, imgBlue, imgGreen, imgRed, imgAlpha *IplImage) { C.cvSplit( unsafe.Pointer(src), unsafe.Pointer(imgBlue), unsafe.Pointer(imgGreen), unsafe.Pointer(imgRed), unsafe.Pointer(imgAlpha), ) }
go
func Split(src, imgBlue, imgGreen, imgRed, imgAlpha *IplImage) { C.cvSplit( unsafe.Pointer(src), unsafe.Pointer(imgBlue), unsafe.Pointer(imgGreen), unsafe.Pointer(imgRed), unsafe.Pointer(imgAlpha), ) }
[ "func", "Split", "(", "src", ",", "imgBlue", ",", "imgGreen", ",", "imgRed", ",", "imgAlpha", "*", "IplImage", ")", "{", "C", ".", "cvSplit", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "unsafe", ".", "Pointer", "(", "imgBlue", ")", ",", "unsafe", ".", "Pointer", "(", "imgGreen", ")", ",", "unsafe", ".", "Pointer", "(", "imgRed", ")", ",", "unsafe", ".", "Pointer", "(", "imgAlpha", ")", ",", ")", "\n", "}" ]
// Split divides a multi-channel array into several single-channel arrays.
[ "Split", "divides", "a", "multi", "-", "channel", "array", "into", "several", "single", "-", "channel", "arrays", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L69-L77
test
go-opencv/go-opencv
opencv/cxcore.go
AddWeighted
func AddWeighted(src1 *IplImage, alpha float64, src2 *IplImage, beta float64, gamma float64, dst *IplImage) { C.cvAddWeighted( unsafe.Pointer(src1), C.double(alpha), unsafe.Pointer(src2), C.double(beta), C.double(gamma), unsafe.Pointer(dst), ) }
go
func AddWeighted(src1 *IplImage, alpha float64, src2 *IplImage, beta float64, gamma float64, dst *IplImage) { C.cvAddWeighted( unsafe.Pointer(src1), C.double(alpha), unsafe.Pointer(src2), C.double(beta), C.double(gamma), unsafe.Pointer(dst), ) }
[ "func", "AddWeighted", "(", "src1", "*", "IplImage", ",", "alpha", "float64", ",", "src2", "*", "IplImage", ",", "beta", "float64", ",", "gamma", "float64", ",", "dst", "*", "IplImage", ")", "{", "C", ".", "cvAddWeighted", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "C", ".", "double", "(", "alpha", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "C", ".", "double", "(", "beta", ")", ",", "C", ".", "double", "(", "gamma", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", ")", "\n", "}" ]
// AddWeighted calculates the weighted sum of two images.
[ "AddWeighted", "calculates", "the", "weighted", "sum", "of", "two", "images", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L80-L89
test
go-opencv/go-opencv
opencv/cxcore.go
And
func And(src1, src2, dst *IplImage) { AndWithMask(src1, src2, dst, nil) }
go
func And(src1, src2, dst *IplImage) { AndWithMask(src1, src2, dst, nil) }
[ "func", "And", "(", "src1", ",", "src2", ",", "dst", "*", "IplImage", ")", "{", "AndWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element bit-wise conjunction of two arrays.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "conjunction", "of", "two", "arrays", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L556-L558
test
go-opencv/go-opencv
opencv/cxcore.go
AndWithMask
func AndWithMask(src1, src2, dst, mask *IplImage) { C.cvAnd( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func AndWithMask(src1, src2, dst, mask *IplImage) { C.cvAnd( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "AndWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvAnd", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element bit-wise conjunction of two arrays with a mask.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "conjunction", "of", "two", "arrays", "with", "a", "mask", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L561-L568
test
go-opencv/go-opencv
opencv/cxcore.go
AndScalar
func AndScalar(src *IplImage, value Scalar, dst *IplImage) { AndScalarWithMask(src, value, dst, nil) }
go
func AndScalar(src *IplImage, value Scalar, dst *IplImage) { AndScalarWithMask(src, value, dst, nil) }
[ "func", "AndScalar", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", "*", "IplImage", ")", "{", "AndScalarWithMask", "(", "src", ",", "value", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element bit-wise conjunction of an array and a scalar.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "conjunction", "of", "an", "array", "and", "a", "scalar", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L571-L573
test
go-opencv/go-opencv
opencv/cxcore.go
AndScalarWithMask
func AndScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvAndS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func AndScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvAndS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "AndScalarWithMask", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvAndS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element bit-wise conjunction of an array and a scalar with a mask.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "conjunction", "of", "an", "array", "and", "a", "scalar", "with", "a", "mask", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L576-L583
test
go-opencv/go-opencv
opencv/cxcore.go
Or
func Or(src1, src2, dst *IplImage) { OrWithMask(src1, src2, dst, nil) }
go
func Or(src1, src2, dst *IplImage) { OrWithMask(src1, src2, dst, nil) }
[ "func", "Or", "(", "src1", ",", "src2", ",", "dst", "*", "IplImage", ")", "{", "OrWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element bit-wise disjunction of two arrays.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "disjunction", "of", "two", "arrays", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L586-L588
test
go-opencv/go-opencv
opencv/cxcore.go
OrWithMask
func OrWithMask(src1, src2, dst, mask *IplImage) { C.cvOr( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func OrWithMask(src1, src2, dst, mask *IplImage) { C.cvOr( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "OrWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvOr", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element bit-wise disjunction of two arrays with a mask.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "disjunction", "of", "two", "arrays", "with", "a", "mask", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L591-L598
test
go-opencv/go-opencv
opencv/cxcore.go
OrScalar
func OrScalar(src *IplImage, value Scalar, dst *IplImage) { OrScalarWithMask(src, value, dst, nil) }
go
func OrScalar(src *IplImage, value Scalar, dst *IplImage) { OrScalarWithMask(src, value, dst, nil) }
[ "func", "OrScalar", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", "*", "IplImage", ")", "{", "OrScalarWithMask", "(", "src", ",", "value", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element bit-wise disjunction of an array and a scalar.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "disjunction", "of", "an", "array", "and", "a", "scalar", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L601-L603
test
go-opencv/go-opencv
opencv/cxcore.go
OrScalarWithMask
func OrScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvOrS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func OrScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvOrS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "OrScalarWithMask", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvOrS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element bit-wise disjunction of an array and a scalar with a mask.
[ "Calculates", "the", "per", "-", "element", "bit", "-", "wise", "disjunction", "of", "an", "array", "and", "a", "scalar", "with", "a", "mask", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L606-L613
test
go-opencv/go-opencv
opencv/cxcore.go
AddWithMask
func AddWithMask(src1, src2, dst, mask *IplImage) { C.cvAdd( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func AddWithMask(src1, src2, dst, mask *IplImage) { C.cvAdd( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "AddWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvAdd", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element sum of two arrays with a mask. // dst = src1 + src2
[ "Calculates", "the", "per", "-", "element", "sum", "of", "two", "arrays", "with", "a", "mask", ".", "dst", "=", "src1", "+", "src2" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L657-L664
test
go-opencv/go-opencv
opencv/cxcore.go
AddScalar
func AddScalar(src *IplImage, value Scalar, dst *IplImage) { AddScalarWithMask(src, value, dst, nil) }
go
func AddScalar(src *IplImage, value Scalar, dst *IplImage) { AddScalarWithMask(src, value, dst, nil) }
[ "func", "AddScalar", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", "*", "IplImage", ")", "{", "AddScalarWithMask", "(", "src", ",", "value", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element sum of an array and a scalar. // dst = src + value
[ "Calculates", "the", "per", "-", "element", "sum", "of", "an", "array", "and", "a", "scalar", ".", "dst", "=", "src", "+", "value" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L668-L670
test
go-opencv/go-opencv
opencv/cxcore.go
AddScalarWithMask
func AddScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvAddS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func AddScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvAddS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "AddScalarWithMask", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvAddS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element sum of an array and a scalar with a mask. // dst = src + value
[ "Calculates", "the", "per", "-", "element", "sum", "of", "an", "array", "and", "a", "scalar", "with", "a", "mask", ".", "dst", "=", "src", "+", "value" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L674-L681
test
go-opencv/go-opencv
opencv/cxcore.go
Subtract
func Subtract(src1, src2, dst *IplImage) { SubtractWithMask(src1, src2, dst, nil) }
go
func Subtract(src1, src2, dst *IplImage) { SubtractWithMask(src1, src2, dst, nil) }
[ "func", "Subtract", "(", "src1", ",", "src2", ",", "dst", "*", "IplImage", ")", "{", "SubtractWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element difference between two arrays. // dst = src1 - src2
[ "Calculates", "the", "per", "-", "element", "difference", "between", "two", "arrays", ".", "dst", "=", "src1", "-", "src2" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L685-L687
test
go-opencv/go-opencv
opencv/cxcore.go
SubtractWithMask
func SubtractWithMask(src1, src2, dst, mask *IplImage) { C.cvSub( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func SubtractWithMask(src1, src2, dst, mask *IplImage) { C.cvSub( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "SubtractWithMask", "(", "src1", ",", "src2", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvSub", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element difference between two arrays with a mask. // dst = src1 - src2
[ "Calculates", "the", "per", "-", "element", "difference", "between", "two", "arrays", "with", "a", "mask", ".", "dst", "=", "src1", "-", "src2" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L691-L698
test
go-opencv/go-opencv
opencv/cxcore.go
SubScalar
func SubScalar(src *IplImage, value Scalar, dst *IplImage) { SubScalarWithMask(src, value, dst, nil) }
go
func SubScalar(src *IplImage, value Scalar, dst *IplImage) { SubScalarWithMask(src, value, dst, nil) }
[ "func", "SubScalar", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", "*", "IplImage", ")", "{", "SubScalarWithMask", "(", "src", ",", "value", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element difference between an array and a scalar. // dst = src - value
[ "Calculates", "the", "per", "-", "element", "difference", "between", "an", "array", "and", "a", "scalar", ".", "dst", "=", "src", "-", "value" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L702-L704
test
go-opencv/go-opencv
opencv/cxcore.go
SubScalarWithMask
func SubScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvSubS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func SubScalarWithMask(src *IplImage, value Scalar, dst, mask *IplImage) { C.cvSubS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "SubScalarWithMask", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvSubS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element difference between an array and a scalar with a mask. // dst = src - value
[ "Calculates", "the", "per", "-", "element", "difference", "between", "an", "array", "and", "a", "scalar", "with", "a", "mask", ".", "dst", "=", "src", "-", "value" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L708-L715
test
go-opencv/go-opencv
opencv/cxcore.go
SubScalarRev
func SubScalarRev(value Scalar, src, dst *IplImage) { SubScalarWithMaskRev(value, src, dst, nil) }
go
func SubScalarRev(value Scalar, src, dst *IplImage) { SubScalarWithMaskRev(value, src, dst, nil) }
[ "func", "SubScalarRev", "(", "value", "Scalar", ",", "src", ",", "dst", "*", "IplImage", ")", "{", "SubScalarWithMaskRev", "(", "value", ",", "src", ",", "dst", ",", "nil", ")", "\n", "}" ]
// Calculates the per-element difference between a scalar and an array. // dst = value - src
[ "Calculates", "the", "per", "-", "element", "difference", "between", "a", "scalar", "and", "an", "array", ".", "dst", "=", "value", "-", "src" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L719-L721
test
go-opencv/go-opencv
opencv/cxcore.go
SubScalarWithMaskRev
func SubScalarWithMaskRev(value Scalar, src, dst, mask *IplImage) { C.cvSubRS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
go
func SubScalarWithMaskRev(value Scalar, src, dst, mask *IplImage) { C.cvSubRS( unsafe.Pointer(src), (C.CvScalar)(value), unsafe.Pointer(dst), unsafe.Pointer(mask), ) }
[ "func", "SubScalarWithMaskRev", "(", "value", "Scalar", ",", "src", ",", "dst", ",", "mask", "*", "IplImage", ")", "{", "C", ".", "cvSubRS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "}" ]
// Calculates the per-element difference between a scalar and an array with a mask. // dst = value - src
[ "Calculates", "the", "per", "-", "element", "difference", "between", "a", "scalar", "and", "an", "array", "with", "a", "mask", ".", "dst", "=", "value", "-", "src" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L725-L732
test
go-opencv/go-opencv
opencv/cxcore.go
AbsDiff
func AbsDiff(src1, src2, dst *IplImage) { C.cvAbsDiff( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), ) }
go
func AbsDiff(src1, src2, dst *IplImage) { C.cvAbsDiff( unsafe.Pointer(src1), unsafe.Pointer(src2), unsafe.Pointer(dst), ) }
[ "func", "AbsDiff", "(", "src1", ",", "src2", ",", "dst", "*", "IplImage", ")", "{", "C", ".", "cvAbsDiff", "(", "unsafe", ".", "Pointer", "(", "src1", ")", ",", "unsafe", ".", "Pointer", "(", "src2", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", ")", "\n", "}" ]
// Calculates the per-element absolute difference between two arrays.
[ "Calculates", "the", "per", "-", "element", "absolute", "difference", "between", "two", "arrays", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L735-L741
test
go-opencv/go-opencv
opencv/cxcore.go
AbsDiffScalar
func AbsDiffScalar(src *IplImage, value Scalar, dst *IplImage) { C.cvAbsDiffS( unsafe.Pointer(src), unsafe.Pointer(dst), (C.CvScalar)(value), ) }
go
func AbsDiffScalar(src *IplImage, value Scalar, dst *IplImage) { C.cvAbsDiffS( unsafe.Pointer(src), unsafe.Pointer(dst), (C.CvScalar)(value), ) }
[ "func", "AbsDiffScalar", "(", "src", "*", "IplImage", ",", "value", "Scalar", ",", "dst", "*", "IplImage", ")", "{", "C", ".", "cvAbsDiffS", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "unsafe", ".", "Pointer", "(", "dst", ")", ",", "(", "C", ".", "CvScalar", ")", "(", "value", ")", ",", ")", "\n", "}" ]
// Calculates the per-element absolute difference between an array and a scalar.
[ "Calculates", "the", "per", "-", "element", "absolute", "difference", "between", "an", "array", "and", "a", "scalar", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L744-L750
test
go-opencv/go-opencv
opencv/cxcore.go
MeanStdDevWithMask
func MeanStdDevWithMask(src, mask *IplImage) (Scalar, Scalar) { var mean, stdDev Scalar C.cvAvgSdv( unsafe.Pointer(src), (*C.CvScalar)(&mean), (*C.CvScalar)(&stdDev), unsafe.Pointer(mask), ) return mean, stdDev }
go
func MeanStdDevWithMask(src, mask *IplImage) (Scalar, Scalar) { var mean, stdDev Scalar C.cvAvgSdv( unsafe.Pointer(src), (*C.CvScalar)(&mean), (*C.CvScalar)(&stdDev), unsafe.Pointer(mask), ) return mean, stdDev }
[ "func", "MeanStdDevWithMask", "(", "src", ",", "mask", "*", "IplImage", ")", "(", "Scalar", ",", "Scalar", ")", "{", "var", "mean", ",", "stdDev", "Scalar", "\n", "C", ".", "cvAvgSdv", "(", "unsafe", ".", "Pointer", "(", "src", ")", ",", "(", "*", "C", ".", "CvScalar", ")", "(", "&", "mean", ")", ",", "(", "*", "C", ".", "CvScalar", ")", "(", "&", "stdDev", ")", ",", "unsafe", ".", "Pointer", "(", "mask", ")", ",", ")", "\n", "return", "mean", ",", "stdDev", "\n", "}" ]
// MeanStdDevWithMask calculates mean and standard deviation of pixel values with mask
[ "MeanStdDevWithMask", "calculates", "mean", "and", "standard", "deviation", "of", "pixel", "values", "with", "mask" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L775-L785
test
go-opencv/go-opencv
opencv/cxcore.go
CreateSeq
func CreateSeq(seq_flags, elem_size int) *Seq { return (*Seq)(C.cvCreateSeq( C.int(seq_flags), C.size_t(unsafe.Sizeof(Seq{})), C.size_t(elem_size), C.cvCreateMemStorage(C.int(0)), )) }
go
func CreateSeq(seq_flags, elem_size int) *Seq { return (*Seq)(C.cvCreateSeq( C.int(seq_flags), C.size_t(unsafe.Sizeof(Seq{})), C.size_t(elem_size), C.cvCreateMemStorage(C.int(0)), )) }
[ "func", "CreateSeq", "(", "seq_flags", ",", "elem_size", "int", ")", "*", "Seq", "{", "return", "(", "*", "Seq", ")", "(", "C", ".", "cvCreateSeq", "(", "C", ".", "int", "(", "seq_flags", ")", ",", "C", ".", "size_t", "(", "unsafe", ".", "Sizeof", "(", "Seq", "{", "}", ")", ")", ",", "C", ".", "size_t", "(", "elem_size", ")", ",", "C", ".", "cvCreateMemStorage", "(", "C", ".", "int", "(", "0", ")", ")", ",", ")", ")", "\n", "}" ]
// Creates a new sequence.
[ "Creates", "a", "new", "sequence", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L803-L810
test
go-opencv/go-opencv
opencv/cxcore.go
Push
func (seq *Seq) Push(element unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer(C.cvSeqPush((*C.struct_CvSeq)(seq), element)) }
go
func (seq *Seq) Push(element unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer(C.cvSeqPush((*C.struct_CvSeq)(seq), element)) }
[ "func", "(", "seq", "*", "Seq", ")", "Push", "(", "element", "unsafe", ".", "Pointer", ")", "unsafe", ".", "Pointer", "{", "return", "unsafe", ".", "Pointer", "(", "C", ".", "cvSeqPush", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "element", ")", ")", "\n", "}" ]
// Adds an element to the sequence end. // Returns a pointer to the element added.
[ "Adds", "an", "element", "to", "the", "sequence", "end", ".", "Returns", "a", "pointer", "to", "the", "element", "added", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L814-L816
test
go-opencv/go-opencv
opencv/cxcore.go
Pop
func (seq *Seq) Pop(element unsafe.Pointer) { C.cvSeqPop((*C.struct_CvSeq)(seq), element) }
go
func (seq *Seq) Pop(element unsafe.Pointer) { C.cvSeqPop((*C.struct_CvSeq)(seq), element) }
[ "func", "(", "seq", "*", "Seq", ")", "Pop", "(", "element", "unsafe", ".", "Pointer", ")", "{", "C", ".", "cvSeqPop", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "element", ")", "\n", "}" ]
// Removes element from the sequence end. // Copies the element into the paramter element.
[ "Removes", "element", "from", "the", "sequence", "end", ".", "Copies", "the", "element", "into", "the", "paramter", "element", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L820-L822
test
go-opencv/go-opencv
opencv/cxcore.go
PushFront
func (seq *Seq) PushFront(element unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer((C.cvSeqPushFront((*C.struct_CvSeq)(seq), element))) }
go
func (seq *Seq) PushFront(element unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer((C.cvSeqPushFront((*C.struct_CvSeq)(seq), element))) }
[ "func", "(", "seq", "*", "Seq", ")", "PushFront", "(", "element", "unsafe", ".", "Pointer", ")", "unsafe", ".", "Pointer", "{", "return", "unsafe", ".", "Pointer", "(", "(", "C", ".", "cvSeqPushFront", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "element", ")", ")", ")", "\n", "}" ]
// Adds an element to the sequence beginning. // Returns a pointer to the element added.
[ "Adds", "an", "element", "to", "the", "sequence", "beginning", ".", "Returns", "a", "pointer", "to", "the", "element", "added", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L826-L828
test
go-opencv/go-opencv
opencv/cxcore.go
PopFront
func (seq *Seq) PopFront(element unsafe.Pointer) { C.cvSeqPopFront((*C.struct_CvSeq)(seq), element) }
go
func (seq *Seq) PopFront(element unsafe.Pointer) { C.cvSeqPopFront((*C.struct_CvSeq)(seq), element) }
[ "func", "(", "seq", "*", "Seq", ")", "PopFront", "(", "element", "unsafe", ".", "Pointer", ")", "{", "C", ".", "cvSeqPopFront", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "element", ")", "\n", "}" ]
// Removes element from the sequence beginning. // Copies the element into the paramter element.
[ "Removes", "element", "from", "the", "sequence", "beginning", ".", "Copies", "the", "element", "into", "the", "paramter", "element", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L832-L834
test
go-opencv/go-opencv
opencv/cxcore.go
GetElemAt
func (seq *Seq) GetElemAt(index int) unsafe.Pointer { return (unsafe.Pointer)(C.cvGetSeqElem( (*C.struct_CvSeq)(seq), C.int(index), )) }
go
func (seq *Seq) GetElemAt(index int) unsafe.Pointer { return (unsafe.Pointer)(C.cvGetSeqElem( (*C.struct_CvSeq)(seq), C.int(index), )) }
[ "func", "(", "seq", "*", "Seq", ")", "GetElemAt", "(", "index", "int", ")", "unsafe", ".", "Pointer", "{", "return", "(", "unsafe", ".", "Pointer", ")", "(", "C", ".", "cvGetSeqElem", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "C", ".", "int", "(", "index", ")", ",", ")", ")", "\n", "}" ]
// Gets a pointer to the element at the index
[ "Gets", "a", "pointer", "to", "the", "element", "at", "the", "index" ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L867-L872
test
go-opencv/go-opencv
opencv/cxcore.go
RemoveAt
func (seq *Seq) RemoveAt(index int) { C.cvSeqRemove((*C.struct_CvSeq)(seq), C.int(index)) }
go
func (seq *Seq) RemoveAt(index int) { C.cvSeqRemove((*C.struct_CvSeq)(seq), C.int(index)) }
[ "func", "(", "seq", "*", "Seq", ")", "RemoveAt", "(", "index", "int", ")", "{", "C", ".", "cvSeqRemove", "(", "(", "*", "C", ".", "struct_CvSeq", ")", "(", "seq", ")", ",", "C", ".", "int", "(", "index", ")", ")", "\n", "}" ]
// Removes an element from the middle of a sequence.
[ "Removes", "an", "element", "from", "the", "middle", "of", "a", "sequence", "." ]
a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db
https://github.com/go-opencv/go-opencv/blob/a4fe8ec027ccc9eb8b7d0797db7c76e61083f1db/opencv/cxcore.go#L875-L877
test
avast/retry-go
options.go
Delay
func Delay(delay time.Duration) Option { return func(c *Config) { c.delay = delay } }
go
func Delay(delay time.Duration) Option { return func(c *Config) { c.delay = delay } }
[ "func", "Delay", "(", "delay", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "Config", ")", "{", "c", ".", "delay", "=", "delay", "\n", "}", "\n", "}" ]
// Delay set delay between retry // default is 100ms
[ "Delay", "set", "delay", "between", "retry", "default", "is", "100ms" ]
88ef2130df9642aa2849152b2985af9ba3676ee9
https://github.com/avast/retry-go/blob/88ef2130df9642aa2849152b2985af9ba3676ee9/options.go#L46-L50
test
avast/retry-go
options.go
BackOffDelay
func BackOffDelay(n uint, config *Config) time.Duration { return config.delay * (1 << (n - 1)) }
go
func BackOffDelay(n uint, config *Config) time.Duration { return config.delay * (1 << (n - 1)) }
[ "func", "BackOffDelay", "(", "n", "uint", ",", "config", "*", "Config", ")", "time", ".", "Duration", "{", "return", "config", ".", "delay", "*", "(", "1", "<<", "(", "n", "-", "1", ")", ")", "\n", "}" ]
// BackOffDelay is a DelayType which increases delay between consecutive retries
[ "BackOffDelay", "is", "a", "DelayType", "which", "increases", "delay", "between", "consecutive", "retries" ]
88ef2130df9642aa2849152b2985af9ba3676ee9
https://github.com/avast/retry-go/blob/88ef2130df9642aa2849152b2985af9ba3676ee9/options.go#L61-L63
test
avast/retry-go
retry.go
Error
func (e Error) Error() string { logWithNumber := make([]string, lenWithoutNil(e)) for i, l := range e { if l != nil { logWithNumber[i] = fmt.Sprintf("#%d: %s", i+1, l.Error()) } } return fmt.Sprintf("All attempts fail:\n%s", strings.Join(logWithNumber, "\n")) }
go
func (e Error) Error() string { logWithNumber := make([]string, lenWithoutNil(e)) for i, l := range e { if l != nil { logWithNumber[i] = fmt.Sprintf("#%d: %s", i+1, l.Error()) } } return fmt.Sprintf("All attempts fail:\n%s", strings.Join(logWithNumber, "\n")) }
[ "func", "(", "e", "Error", ")", "Error", "(", ")", "string", "{", "logWithNumber", ":=", "make", "(", "[", "]", "string", ",", "lenWithoutNil", "(", "e", ")", ")", "\n", "for", "i", ",", "l", ":=", "range", "e", "{", "if", "l", "!=", "nil", "{", "logWithNumber", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"#%d: %s\"", ",", "i", "+", "1", ",", "l", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"All attempts fail:\\n%s\"", ",", "\\n", ")", "\n", "}" ]
// Error method return string representation of Error // It is an implementation of error interface
[ "Error", "method", "return", "string", "representation", "of", "Error", "It", "is", "an", "implementation", "of", "error", "interface" ]
88ef2130df9642aa2849152b2985af9ba3676ee9
https://github.com/avast/retry-go/blob/88ef2130df9642aa2849152b2985af9ba3676ee9/retry.go#L132-L141
test
ipfs/go-ipfs-api
requestbuilder.go
Arguments
func (r *RequestBuilder) Arguments(args ...string) *RequestBuilder { r.args = append(r.args, args...) return r }
go
func (r *RequestBuilder) Arguments(args ...string) *RequestBuilder { r.args = append(r.args, args...) return r }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Arguments", "(", "args", "...", "string", ")", "*", "RequestBuilder", "{", "r", ".", "args", "=", "append", "(", "r", ".", "args", ",", "args", "...", ")", "\n", "return", "r", "\n", "}" ]
// Arguments adds the arguments to the args.
[ "Arguments", "adds", "the", "arguments", "to", "the", "args", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L24-L27
test
ipfs/go-ipfs-api
requestbuilder.go
BodyString
func (r *RequestBuilder) BodyString(body string) *RequestBuilder { return r.Body(strings.NewReader(body)) }
go
func (r *RequestBuilder) BodyString(body string) *RequestBuilder { return r.Body(strings.NewReader(body)) }
[ "func", "(", "r", "*", "RequestBuilder", ")", "BodyString", "(", "body", "string", ")", "*", "RequestBuilder", "{", "return", "r", ".", "Body", "(", "strings", ".", "NewReader", "(", "body", ")", ")", "\n", "}" ]
// BodyString sets the request body to the given string.
[ "BodyString", "sets", "the", "request", "body", "to", "the", "given", "string", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L30-L32
test
ipfs/go-ipfs-api
requestbuilder.go
BodyBytes
func (r *RequestBuilder) BodyBytes(body []byte) *RequestBuilder { return r.Body(bytes.NewReader(body)) }
go
func (r *RequestBuilder) BodyBytes(body []byte) *RequestBuilder { return r.Body(bytes.NewReader(body)) }
[ "func", "(", "r", "*", "RequestBuilder", ")", "BodyBytes", "(", "body", "[", "]", "byte", ")", "*", "RequestBuilder", "{", "return", "r", ".", "Body", "(", "bytes", ".", "NewReader", "(", "body", ")", ")", "\n", "}" ]
// BodyBytes sets the request body to the given buffer.
[ "BodyBytes", "sets", "the", "request", "body", "to", "the", "given", "buffer", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L35-L37
test
ipfs/go-ipfs-api
requestbuilder.go
Body
func (r *RequestBuilder) Body(body io.Reader) *RequestBuilder { r.body = body return r }
go
func (r *RequestBuilder) Body(body io.Reader) *RequestBuilder { r.body = body return r }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Body", "(", "body", "io", ".", "Reader", ")", "*", "RequestBuilder", "{", "r", ".", "body", "=", "body", "\n", "return", "r", "\n", "}" ]
// Body sets the request body to the given reader.
[ "Body", "sets", "the", "request", "body", "to", "the", "given", "reader", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L40-L43
test
ipfs/go-ipfs-api
requestbuilder.go
Option
func (r *RequestBuilder) Option(key string, value interface{}) *RequestBuilder { var s string switch v := value.(type) { case bool: s = strconv.FormatBool(v) case string: s = v case []byte: s = string(v) default: // slow case. s = fmt.Sprint(value) } if r.opts == nil { r.opts = make(map[string]string, 1) } r.opts[key] = s return r }
go
func (r *RequestBuilder) Option(key string, value interface{}) *RequestBuilder { var s string switch v := value.(type) { case bool: s = strconv.FormatBool(v) case string: s = v case []byte: s = string(v) default: // slow case. s = fmt.Sprint(value) } if r.opts == nil { r.opts = make(map[string]string, 1) } r.opts[key] = s return r }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Option", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "*", "RequestBuilder", "{", "var", "s", "string", "\n", "switch", "v", ":=", "value", ".", "(", "type", ")", "{", "case", "bool", ":", "s", "=", "strconv", ".", "FormatBool", "(", "v", ")", "\n", "case", "string", ":", "s", "=", "v", "\n", "case", "[", "]", "byte", ":", "s", "=", "string", "(", "v", ")", "\n", "default", ":", "s", "=", "fmt", ".", "Sprint", "(", "value", ")", "\n", "}", "\n", "if", "r", ".", "opts", "==", "nil", "{", "r", ".", "opts", "=", "make", "(", "map", "[", "string", "]", "string", ",", "1", ")", "\n", "}", "\n", "r", ".", "opts", "[", "key", "]", "=", "s", "\n", "return", "r", "\n", "}" ]
// Option sets the given option.
[ "Option", "sets", "the", "given", "option", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L46-L64
test
ipfs/go-ipfs-api
requestbuilder.go
Header
func (r *RequestBuilder) Header(name, value string) *RequestBuilder { if r.headers == nil { r.headers = make(map[string]string, 1) } r.headers[name] = value return r }
go
func (r *RequestBuilder) Header(name, value string) *RequestBuilder { if r.headers == nil { r.headers = make(map[string]string, 1) } r.headers[name] = value return r }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Header", "(", "name", ",", "value", "string", ")", "*", "RequestBuilder", "{", "if", "r", ".", "headers", "==", "nil", "{", "r", ".", "headers", "=", "make", "(", "map", "[", "string", "]", "string", ",", "1", ")", "\n", "}", "\n", "r", ".", "headers", "[", "name", "]", "=", "value", "\n", "return", "r", "\n", "}" ]
// Header sets the given header.
[ "Header", "sets", "the", "given", "header", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L67-L73
test
ipfs/go-ipfs-api
requestbuilder.go
Send
func (r *RequestBuilder) Send(ctx context.Context) (*Response, error) { req := NewRequest(ctx, r.shell.url, r.command, r.args...) req.Opts = r.opts req.Headers = r.headers req.Body = r.body return req.Send(&r.shell.httpcli) }
go
func (r *RequestBuilder) Send(ctx context.Context) (*Response, error) { req := NewRequest(ctx, r.shell.url, r.command, r.args...) req.Opts = r.opts req.Headers = r.headers req.Body = r.body return req.Send(&r.shell.httpcli) }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Send", "(", "ctx", "context", ".", "Context", ")", "(", "*", "Response", ",", "error", ")", "{", "req", ":=", "NewRequest", "(", "ctx", ",", "r", ".", "shell", ".", "url", ",", "r", ".", "command", ",", "r", ".", "args", "...", ")", "\n", "req", ".", "Opts", "=", "r", ".", "opts", "\n", "req", ".", "Headers", "=", "r", ".", "headers", "\n", "req", ".", "Body", "=", "r", ".", "body", "\n", "return", "req", ".", "Send", "(", "&", "r", ".", "shell", ".", "httpcli", ")", "\n", "}" ]
// Send sends the request and return the response.
[ "Send", "sends", "the", "request", "and", "return", "the", "response", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L76-L82
test
ipfs/go-ipfs-api
requestbuilder.go
Exec
func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error { httpRes, err := r.Send(ctx) if err != nil { return err } if res == nil { lateErr := httpRes.Close() if httpRes.Error != nil { return httpRes.Error } return lateErr } return httpRes.Decode(res) }
go
func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error { httpRes, err := r.Send(ctx) if err != nil { return err } if res == nil { lateErr := httpRes.Close() if httpRes.Error != nil { return httpRes.Error } return lateErr } return httpRes.Decode(res) }
[ "func", "(", "r", "*", "RequestBuilder", ")", "Exec", "(", "ctx", "context", ".", "Context", ",", "res", "interface", "{", "}", ")", "error", "{", "httpRes", ",", "err", ":=", "r", ".", "Send", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "res", "==", "nil", "{", "lateErr", ":=", "httpRes", ".", "Close", "(", ")", "\n", "if", "httpRes", ".", "Error", "!=", "nil", "{", "return", "httpRes", ".", "Error", "\n", "}", "\n", "return", "lateErr", "\n", "}", "\n", "return", "httpRes", ".", "Decode", "(", "res", ")", "\n", "}" ]
// Exec sends the request a request and decodes the response.
[ "Exec", "sends", "the", "request", "a", "request", "and", "decodes", "the", "response", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/requestbuilder.go#L85-L100
test
ipfs/go-ipfs-api
pubsub.go
Next
func (s *PubSubSubscription) Next() (*Message, error) { if s.resp.Error != nil { return nil, s.resp.Error } d := json.NewDecoder(s.resp.Output) var r struct { From []byte `json:"from,omitempty"` Data []byte `json:"data,omitempty"` Seqno []byte `json:"seqno,omitempty"` TopicIDs []string `json:"topicIDs,omitempty"` } err := d.Decode(&r) if err != nil { return nil, err } from, err := peer.IDFromBytes(r.From) if err != nil { return nil, err } return &Message{ From: from, Data: r.Data, Seqno: r.Seqno, TopicIDs: r.TopicIDs, }, nil }
go
func (s *PubSubSubscription) Next() (*Message, error) { if s.resp.Error != nil { return nil, s.resp.Error } d := json.NewDecoder(s.resp.Output) var r struct { From []byte `json:"from,omitempty"` Data []byte `json:"data,omitempty"` Seqno []byte `json:"seqno,omitempty"` TopicIDs []string `json:"topicIDs,omitempty"` } err := d.Decode(&r) if err != nil { return nil, err } from, err := peer.IDFromBytes(r.From) if err != nil { return nil, err } return &Message{ From: from, Data: r.Data, Seqno: r.Seqno, TopicIDs: r.TopicIDs, }, nil }
[ "func", "(", "s", "*", "PubSubSubscription", ")", "Next", "(", ")", "(", "*", "Message", ",", "error", ")", "{", "if", "s", ".", "resp", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "s", ".", "resp", ".", "Error", "\n", "}", "\n", "d", ":=", "json", ".", "NewDecoder", "(", "s", ".", "resp", ".", "Output", ")", "\n", "var", "r", "struct", "{", "From", "[", "]", "byte", "`json:\"from,omitempty\"`", "\n", "Data", "[", "]", "byte", "`json:\"data,omitempty\"`", "\n", "Seqno", "[", "]", "byte", "`json:\"seqno,omitempty\"`", "\n", "TopicIDs", "[", "]", "string", "`json:\"topicIDs,omitempty\"`", "\n", "}", "\n", "err", ":=", "d", ".", "Decode", "(", "&", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "from", ",", "err", ":=", "peer", ".", "IDFromBytes", "(", "r", ".", "From", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Message", "{", "From", ":", "from", ",", "Data", ":", "r", ".", "Data", ",", "Seqno", ":", "r", ".", "Seqno", ",", "TopicIDs", ":", "r", ".", "TopicIDs", ",", "}", ",", "nil", "\n", "}" ]
// Next waits for the next record and returns that.
[ "Next", "waits", "for", "the", "next", "record", "and", "returns", "that", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/pubsub.go#L31-L60
test
ipfs/go-ipfs-api
pubsub.go
Cancel
func (s *PubSubSubscription) Cancel() error { if s.resp.Output == nil { return nil } return s.resp.Output.Close() }
go
func (s *PubSubSubscription) Cancel() error { if s.resp.Output == nil { return nil } return s.resp.Output.Close() }
[ "func", "(", "s", "*", "PubSubSubscription", ")", "Cancel", "(", ")", "error", "{", "if", "s", ".", "resp", ".", "Output", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "resp", ".", "Output", ".", "Close", "(", ")", "\n", "}" ]
// Cancel cancels the given subscription.
[ "Cancel", "cancels", "the", "given", "subscription", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/pubsub.go#L63-L69
test
ipfs/go-ipfs-api
unixfs.go
FileList
func (s *Shell) FileList(path string) (*UnixLsObject, error) { var out lsOutput if err := s.Request("file/ls", path).Exec(context.Background(), &out); err != nil { return nil, err } for _, object := range out.Objects { return object, nil } return nil, fmt.Errorf("no object in results") }
go
func (s *Shell) FileList(path string) (*UnixLsObject, error) { var out lsOutput if err := s.Request("file/ls", path).Exec(context.Background(), &out); err != nil { return nil, err } for _, object := range out.Objects { return object, nil } return nil, fmt.Errorf("no object in results") }
[ "func", "(", "s", "*", "Shell", ")", "FileList", "(", "path", "string", ")", "(", "*", "UnixLsObject", ",", "error", ")", "{", "var", "out", "lsOutput", "\n", "if", "err", ":=", "s", ".", "Request", "(", "\"file/ls\"", ",", "path", ")", ".", "Exec", "(", "context", ".", "Background", "(", ")", ",", "&", "out", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "object", ":=", "range", "out", ".", "Objects", "{", "return", "object", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no object in results\"", ")", "\n", "}" ]
// FileList entries at the given path using the UnixFS commands
[ "FileList", "entries", "at", "the", "given", "path", "using", "the", "UnixFS", "commands" ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/unixfs.go#L27-L38
test
ipfs/go-ipfs-api
shell.go
Cat
func (s *Shell) Cat(path string) (io.ReadCloser, error) { resp, err := s.Request("cat", path).Send(context.Background()) if err != nil { return nil, err } if resp.Error != nil { return nil, resp.Error } return resp.Output, nil }
go
func (s *Shell) Cat(path string) (io.ReadCloser, error) { resp, err := s.Request("cat", path).Send(context.Background()) if err != nil { return nil, err } if resp.Error != nil { return nil, resp.Error } return resp.Output, nil }
[ "func", "(", "s", "*", "Shell", ")", "Cat", "(", "path", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "resp", ",", "err", ":=", "s", ".", "Request", "(", "\"cat\"", ",", "path", ")", ".", "Send", "(", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "resp", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "resp", ".", "Error", "\n", "}", "\n", "return", "resp", ".", "Output", ",", "nil", "\n", "}" ]
// Cat the content at the given path. Callers need to drain and close the returned reader after usage.
[ "Cat", "the", "content", "at", "the", "given", "path", ".", "Callers", "need", "to", "drain", "and", "close", "the", "returned", "reader", "after", "usage", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L129-L139
test
ipfs/go-ipfs-api
shell.go
List
func (s *Shell) List(path string) ([]*LsLink, error) { var out struct{ Objects []LsObject } err := s.Request("ls", path).Exec(context.Background(), &out) if err != nil { return nil, err } if len(out.Objects) != 1 { return nil, errors.New("bad response from server") } return out.Objects[0].Links, nil }
go
func (s *Shell) List(path string) ([]*LsLink, error) { var out struct{ Objects []LsObject } err := s.Request("ls", path).Exec(context.Background(), &out) if err != nil { return nil, err } if len(out.Objects) != 1 { return nil, errors.New("bad response from server") } return out.Objects[0].Links, nil }
[ "func", "(", "s", "*", "Shell", ")", "List", "(", "path", "string", ")", "(", "[", "]", "*", "LsLink", ",", "error", ")", "{", "var", "out", "struct", "{", "Objects", "[", "]", "LsObject", "}", "\n", "err", ":=", "s", ".", "Request", "(", "\"ls\"", ",", "path", ")", ".", "Exec", "(", "context", ".", "Background", "(", ")", ",", "&", "out", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "out", ".", "Objects", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"bad response from server\"", ")", "\n", "}", "\n", "return", "out", ".", "Objects", "[", "0", "]", ".", "Links", ",", "nil", "\n", "}" ]
// List entries at the given path
[ "List", "entries", "at", "the", "given", "path" ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L150-L160
test
ipfs/go-ipfs-api
shell.go
Pin
func (s *Shell) Pin(path string) error { return s.Request("pin/add", path). Option("recursive", true). Exec(context.Background(), nil) }
go
func (s *Shell) Pin(path string) error { return s.Request("pin/add", path). Option("recursive", true). Exec(context.Background(), nil) }
[ "func", "(", "s", "*", "Shell", ")", "Pin", "(", "path", "string", ")", "error", "{", "return", "s", ".", "Request", "(", "\"pin/add\"", ",", "path", ")", ".", "Option", "(", "\"recursive\"", ",", "true", ")", ".", "Exec", "(", "context", ".", "Background", "(", ")", ",", "nil", ")", "\n", "}" ]
// Pin the given path
[ "Pin", "the", "given", "path" ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L175-L179
test
ipfs/go-ipfs-api
shell.go
Pins
func (s *Shell) Pins() (map[string]PinInfo, error) { var raw struct{ Keys map[string]PinInfo } return raw.Keys, s.Request("pin/ls").Exec(context.Background(), &raw) }
go
func (s *Shell) Pins() (map[string]PinInfo, error) { var raw struct{ Keys map[string]PinInfo } return raw.Keys, s.Request("pin/ls").Exec(context.Background(), &raw) }
[ "func", "(", "s", "*", "Shell", ")", "Pins", "(", ")", "(", "map", "[", "string", "]", "PinInfo", ",", "error", ")", "{", "var", "raw", "struct", "{", "Keys", "map", "[", "string", "]", "PinInfo", "}", "\n", "return", "raw", ".", "Keys", ",", "s", ".", "Request", "(", "\"pin/ls\"", ")", ".", "Exec", "(", "context", ".", "Background", "(", ")", ",", "&", "raw", ")", "\n", "}" ]
// Pins returns a map of the pin hashes to their info (currently just the // pin type, one of DirectPin, RecursivePin, or IndirectPin. A map is returned // instead of a slice because it is easier to do existence lookup by map key // than unordered array searching. The map is likely to be more useful to a // client than a flat list.
[ "Pins", "returns", "a", "map", "of", "the", "pin", "hashes", "to", "their", "info", "(", "currently", "just", "the", "pin", "type", "one", "of", "DirectPin", "RecursivePin", "or", "IndirectPin", ".", "A", "map", "is", "returned", "instead", "of", "a", "slice", "because", "it", "is", "easier", "to", "do", "existence", "lookup", "by", "map", "key", "than", "unordered", "array", "searching", ".", "The", "map", "is", "likely", "to", "be", "more", "useful", "to", "a", "client", "than", "a", "flat", "list", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L203-L206
test
ipfs/go-ipfs-api
shell.go
Version
func (s *Shell) Version() (string, string, error) { ver := struct { Version string Commit string }{} if err := s.Request("version").Exec(context.Background(), &ver); err != nil { return "", "", err } return ver.Version, ver.Commit, nil }
go
func (s *Shell) Version() (string, string, error) { ver := struct { Version string Commit string }{} if err := s.Request("version").Exec(context.Background(), &ver); err != nil { return "", "", err } return ver.Version, ver.Commit, nil }
[ "func", "(", "s", "*", "Shell", ")", "Version", "(", ")", "(", "string", ",", "string", ",", "error", ")", "{", "ver", ":=", "struct", "{", "Version", "string", "\n", "Commit", "string", "\n", "}", "{", "}", "\n", "if", "err", ":=", "s", ".", "Request", "(", "\"version\"", ")", ".", "Exec", "(", "context", ".", "Background", "(", ")", ",", "&", "ver", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "\"\"", ",", "err", "\n", "}", "\n", "return", "ver", ".", "Version", ",", "ver", ".", "Commit", ",", "nil", "\n", "}" ]
// returns ipfs version and commit sha
[ "returns", "ipfs", "version", "and", "commit", "sha" ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L339-L349
test
ipfs/go-ipfs-api
shell.go
SwarmPeers
func (s *Shell) SwarmPeers(ctx context.Context) (*SwarmConnInfos, error) { v := &SwarmConnInfos{} err := s.Request("swarm/peers").Exec(ctx, &v) return v, err }
go
func (s *Shell) SwarmPeers(ctx context.Context) (*SwarmConnInfos, error) { v := &SwarmConnInfos{} err := s.Request("swarm/peers").Exec(ctx, &v) return v, err }
[ "func", "(", "s", "*", "Shell", ")", "SwarmPeers", "(", "ctx", "context", ".", "Context", ")", "(", "*", "SwarmConnInfos", ",", "error", ")", "{", "v", ":=", "&", "SwarmConnInfos", "{", "}", "\n", "err", ":=", "s", ".", "Request", "(", "\"swarm/peers\"", ")", ".", "Exec", "(", "ctx", ",", "&", "v", ")", "\n", "return", "v", ",", "err", "\n", "}" ]
// SwarmPeers gets all the swarm peers
[ "SwarmPeers", "gets", "all", "the", "swarm", "peers" ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L500-L504
test
ipfs/go-ipfs-api
shell.go
SwarmConnect
func (s *Shell) SwarmConnect(ctx context.Context, addr ...string) error { var conn *swarmConnection err := s.Request("swarm/connect"). Arguments(addr...). Exec(ctx, &conn) return err }
go
func (s *Shell) SwarmConnect(ctx context.Context, addr ...string) error { var conn *swarmConnection err := s.Request("swarm/connect"). Arguments(addr...). Exec(ctx, &conn) return err }
[ "func", "(", "s", "*", "Shell", ")", "SwarmConnect", "(", "ctx", "context", ".", "Context", ",", "addr", "...", "string", ")", "error", "{", "var", "conn", "*", "swarmConnection", "\n", "err", ":=", "s", ".", "Request", "(", "\"swarm/connect\"", ")", ".", "Arguments", "(", "addr", "...", ")", ".", "Exec", "(", "ctx", ",", "&", "conn", ")", "\n", "return", "err", "\n", "}" ]
// SwarmConnect opens a swarm connection to a specific address.
[ "SwarmConnect", "opens", "a", "swarm", "connection", "to", "a", "specific", "address", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/shell.go#L511-L517
test
ipfs/go-ipfs-api
options/dag.go
DagPutOptions
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) { options := &DagPutSettings{ InputEnc: "json", Kind: "cbor", Pin: "false", Hash: "sha2-256", } for _, opt := range opts { err := opt(options) if err != nil { return nil, err } } return options, nil }
go
func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) { options := &DagPutSettings{ InputEnc: "json", Kind: "cbor", Pin: "false", Hash: "sha2-256", } for _, opt := range opts { err := opt(options) if err != nil { return nil, err } } return options, nil }
[ "func", "DagPutOptions", "(", "opts", "...", "DagPutOption", ")", "(", "*", "DagPutSettings", ",", "error", ")", "{", "options", ":=", "&", "DagPutSettings", "{", "InputEnc", ":", "\"json\"", ",", "Kind", ":", "\"cbor\"", ",", "Pin", ":", "\"false\"", ",", "Hash", ":", "\"sha2-256\"", ",", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "err", ":=", "opt", "(", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "options", ",", "nil", "\n", "}" ]
// DagPutOptions applies the given options to a DagPutSettings instance.
[ "DagPutOptions", "applies", "the", "given", "options", "to", "a", "DagPutSettings", "instance", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/options/dag.go#L15-L30
test
ipfs/go-ipfs-api
options/dag.go
Pin
func (dagOpts) Pin(pin string) DagPutOption { return func(opts *DagPutSettings) error { opts.Pin = pin return nil } }
go
func (dagOpts) Pin(pin string) DagPutOption { return func(opts *DagPutSettings) error { opts.Pin = pin return nil } }
[ "func", "(", "dagOpts", ")", "Pin", "(", "pin", "string", ")", "DagPutOption", "{", "return", "func", "(", "opts", "*", "DagPutSettings", ")", "error", "{", "opts", ".", "Pin", "=", "pin", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Pin is an option for Dag.Put which specifies whether to pin the added // dags. Default is "false".
[ "Pin", "is", "an", "option", "for", "Dag", ".", "Put", "which", "specifies", "whether", "to", "pin", "the", "added", "dags", ".", "Default", "is", "false", "." ]
a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32
https://github.com/ipfs/go-ipfs-api/blob/a1b28da48b3763f67654ec4cfcba5fcbfb3dfb32/options/dag.go#L38-L43
test