repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
openshift/source-to-image
pkg/util/user/rangelist.go
ParseRangeList
func ParseRangeList(str string) (*RangeList, error) { rl := RangeList{} if len(str) == 0 { return &rl, nil } parts := strings.Split(str, ",") for _, p := range parts { r, err := ParseRange(p) if err != nil { return nil, err } rl = append(rl, r) } return &rl, nil }
go
func ParseRangeList(str string) (*RangeList, error) { rl := RangeList{} if len(str) == 0 { return &rl, nil } parts := strings.Split(str, ",") for _, p := range parts { r, err := ParseRange(p) if err != nil { return nil, err } rl = append(rl, r) } return &rl, nil }
[ "func", "ParseRangeList", "(", "str", "string", ")", "(", "*", "RangeList", ",", "error", ")", "{", "rl", ":=", "RangeList", "{", "}", "\n", "if", "len", "(", "str", ")", "==", "0", "{", "return", "&", "rl", ",", "nil", "\n", "}", "\n", "parts", ":=", "strings", ".", "Split", "(", "str", ",", "\"", "\"", ")", "\n", "for", "_", ",", "p", ":=", "range", "parts", "{", "r", ",", "err", ":=", "ParseRange", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rl", "=", "append", "(", "rl", ",", "r", ")", "\n", "}", "\n", "return", "&", "rl", ",", "nil", "\n", "}" ]
// ParseRangeList parses a string that contains a comma-separated list of ranges
[ "ParseRangeList", "parses", "a", "string", "that", "contains", "a", "comma", "-", "separated", "list", "of", "ranges" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L12-L26
train
openshift/source-to-image
pkg/util/user/rangelist.go
Empty
func (l *RangeList) Empty() bool { if len(*l) == 0 { return true } for _, r := range *l { if !r.Empty() { return false } } return true }
go
func (l *RangeList) Empty() bool { if len(*l) == 0 { return true } for _, r := range *l { if !r.Empty() { return false } } return true }
[ "func", "(", "l", "*", "RangeList", ")", "Empty", "(", ")", "bool", "{", "if", "len", "(", "*", "l", ")", "==", "0", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "*", "l", "{", "if", "!", "r", ".", "Empty", "(", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Empty returns true if the RangeList is empty
[ "Empty", "returns", "true", "if", "the", "RangeList", "is", "empty" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L29-L39
train
openshift/source-to-image
pkg/util/user/rangelist.go
Contains
func (l *RangeList) Contains(uid int) bool { for _, r := range *l { if r.Contains(uid) { return true } } return false }
go
func (l *RangeList) Contains(uid int) bool { for _, r := range *l { if r.Contains(uid) { return true } } return false }
[ "func", "(", "l", "*", "RangeList", ")", "Contains", "(", "uid", "int", ")", "bool", "{", "for", "_", ",", "r", ":=", "range", "*", "l", "{", "if", "r", ".", "Contains", "(", "uid", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Contains returns true if the uid is contained by any range in the RangeList
[ "Contains", "returns", "true", "if", "the", "uid", "is", "contained", "by", "any", "range", "in", "the", "RangeList" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L42-L49
train
openshift/source-to-image
pkg/util/user/rangelist.go
Set
func (l *RangeList) Set(value string) error { newRangeList, err := ParseRangeList(value) if err != nil { return err } *l = *newRangeList return nil }
go
func (l *RangeList) Set(value string) error { newRangeList, err := ParseRangeList(value) if err != nil { return err } *l = *newRangeList return nil }
[ "func", "(", "l", "*", "RangeList", ")", "Set", "(", "value", "string", ")", "error", "{", "newRangeList", ",", "err", ":=", "ParseRangeList", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "l", "=", "*", "newRangeList", "\n", "return", "nil", "\n", "}" ]
// Set sets the value of a RangeList object
[ "Set", "sets", "the", "value", "of", "a", "RangeList", "object" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L57-L64
train
openshift/source-to-image
pkg/util/user/rangelist.go
String
func (l *RangeList) String() string { rangeStrings := []string{} for _, r := range *l { rangeStrings = append(rangeStrings, r.String()) } return strings.Join(rangeStrings, ",") }
go
func (l *RangeList) String() string { rangeStrings := []string{} for _, r := range *l { rangeStrings = append(rangeStrings, r.String()) } return strings.Join(rangeStrings, ",") }
[ "func", "(", "l", "*", "RangeList", ")", "String", "(", ")", "string", "{", "rangeStrings", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "*", "l", "{", "rangeStrings", "=", "append", "(", "rangeStrings", ",", "r", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "rangeStrings", ",", "\"", "\"", ")", "\n", "}" ]
// String returns a parseable string representation of a RangeList
[ "String", "returns", "a", "parseable", "string", "representation", "of", "a", "RangeList" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L67-L73
train
openshift/source-to-image
pkg/util/user/rangelist.go
IsUserAllowed
func IsUserAllowed(user string, allowed *RangeList) bool { if allowed == nil || allowed.Empty() { return true } uid, err := strconv.Atoi(user) if err != nil { return false } return allowed.Contains(uid) }
go
func IsUserAllowed(user string, allowed *RangeList) bool { if allowed == nil || allowed.Empty() { return true } uid, err := strconv.Atoi(user) if err != nil { return false } return allowed.Contains(uid) }
[ "func", "IsUserAllowed", "(", "user", "string", ",", "allowed", "*", "RangeList", ")", "bool", "{", "if", "allowed", "==", "nil", "||", "allowed", ".", "Empty", "(", ")", "{", "return", "true", "\n", "}", "\n", "uid", ",", "err", ":=", "strconv", ".", "Atoi", "(", "user", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "allowed", ".", "Contains", "(", "uid", ")", "\n", "}" ]
// IsUserAllowed checks that the given user is numeric and is // contained by the given RangeList. Returns true if // allowed is nil or empty.
[ "IsUserAllowed", "checks", "that", "the", "given", "user", "is", "numeric", "and", "is", "contained", "by", "the", "given", "RangeList", ".", "Returns", "true", "if", "allowed", "is", "nil", "or", "empty", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/rangelist.go#L78-L87
train
openshift/source-to-image
pkg/build/cleanup.go
NewDefaultCleaner
func NewDefaultCleaner(fs fs.FileSystem, docker docker.Docker) Cleaner { return &DefaultCleaner{ fs: fs, docker: docker, } }
go
func NewDefaultCleaner(fs fs.FileSystem, docker docker.Docker) Cleaner { return &DefaultCleaner{ fs: fs, docker: docker, } }
[ "func", "NewDefaultCleaner", "(", "fs", "fs", ".", "FileSystem", ",", "docker", "docker", ".", "Docker", ")", "Cleaner", "{", "return", "&", "DefaultCleaner", "{", "fs", ":", "fs", ",", "docker", ":", "docker", ",", "}", "\n", "}" ]
// NewDefaultCleaner creates a new instance of the default Cleaner implementation
[ "NewDefaultCleaner", "creates", "a", "new", "instance", "of", "the", "default", "Cleaner", "implementation" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/build/cleanup.go#L21-L26
train
openshift/source-to-image
pkg/build/cleanup.go
Cleanup
func (c *DefaultCleaner) Cleanup(config *api.Config) { if config.PreserveWorkingDir { glog.V(2).Infof("Temporary directory %q will be saved, not deleted", config.WorkingDir) } else { glog.V(2).Infof("Removing temporary directory %s", config.WorkingDir) if err := c.fs.RemoveDirectory(config.WorkingDir); err != nil { glog.Warningf("Error removing temporary directory %q: %v", config.WorkingDir, err) } } if config.LayeredBuild { // config.LayeredBuild is true only when layered build was finished successfully. // Also in this case config.BuilderImage contains name of the new just built image, // not the original one that was specified by the user. glog.V(2).Infof("Removing temporary image %s", config.BuilderImage) if err := c.docker.RemoveImage(config.BuilderImage); err != nil { glog.Warningf("Error removing temporary image %s: %v", config.BuilderImage, err) } } }
go
func (c *DefaultCleaner) Cleanup(config *api.Config) { if config.PreserveWorkingDir { glog.V(2).Infof("Temporary directory %q will be saved, not deleted", config.WorkingDir) } else { glog.V(2).Infof("Removing temporary directory %s", config.WorkingDir) if err := c.fs.RemoveDirectory(config.WorkingDir); err != nil { glog.Warningf("Error removing temporary directory %q: %v", config.WorkingDir, err) } } if config.LayeredBuild { // config.LayeredBuild is true only when layered build was finished successfully. // Also in this case config.BuilderImage contains name of the new just built image, // not the original one that was specified by the user. glog.V(2).Infof("Removing temporary image %s", config.BuilderImage) if err := c.docker.RemoveImage(config.BuilderImage); err != nil { glog.Warningf("Error removing temporary image %s: %v", config.BuilderImage, err) } } }
[ "func", "(", "c", "*", "DefaultCleaner", ")", "Cleanup", "(", "config", "*", "api", ".", "Config", ")", "{", "if", "config", ".", "PreserveWorkingDir", "{", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "config", ".", "WorkingDir", ")", "\n", "}", "else", "{", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "config", ".", "WorkingDir", ")", "\n", "if", "err", ":=", "c", ".", "fs", ".", "RemoveDirectory", "(", "config", ".", "WorkingDir", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Warningf", "(", "\"", "\"", ",", "config", ".", "WorkingDir", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "config", ".", "LayeredBuild", "{", "// config.LayeredBuild is true only when layered build was finished successfully.", "// Also in this case config.BuilderImage contains name of the new just built image,", "// not the original one that was specified by the user.", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "config", ".", "BuilderImage", ")", "\n", "if", "err", ":=", "c", ".", "docker", ".", "RemoveImage", "(", "config", ".", "BuilderImage", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Warningf", "(", "\"", "\"", ",", "config", ".", "BuilderImage", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Cleanup removes the temporary directories where the sources were stored for build.
[ "Cleanup", "removes", "the", "temporary", "directories", "where", "the", "sources", "were", "stored", "for", "build", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/build/cleanup.go#L29-L47
train
openshift/source-to-image
pkg/scm/git/git.go
New
func New(fs fs.FileSystem, runner cmd.CommandRunner) Git { return &stiGit{ FileSystem: fs, CommandRunner: runner, } }
go
func New(fs fs.FileSystem, runner cmd.CommandRunner) Git { return &stiGit{ FileSystem: fs, CommandRunner: runner, } }
[ "func", "New", "(", "fs", "fs", ".", "FileSystem", ",", "runner", "cmd", ".", "CommandRunner", ")", "Git", "{", "return", "&", "stiGit", "{", "FileSystem", ":", "fs", ",", "CommandRunner", ":", "runner", ",", "}", "\n", "}" ]
// New returns a new instance of the default implementation of the Git interface
[ "New", "returns", "a", "new", "instance", "of", "the", "default", "implementation", "of", "the", "Git", "interface" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L35-L40
train
openshift/source-to-image
pkg/scm/git/git.go
LocalNonBareGitRepositoryIsEmpty
func LocalNonBareGitRepositoryIsEmpty(fs fs.FileSystem, dir string) (bool, error) { gitPath := filepath.Join(dir, ".git") fi, err := fs.Stat(gitPath) if err != nil { return false, err } if !fi.IsDir() { gitPath, err = followGitSubmodule(fs, gitPath) if err != nil { return false, err } } // Search for any file in .git/{objects,refs}. We don't just search the // base .git directory because of the hook samples that are normally // generated with `git init` found := false for _, dir := range []string{"objects", "refs"} { err := fs.Walk(filepath.Join(gitPath, dir), func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() { found = true } if found { return filepath.SkipDir } return nil }) if err != nil { return false, err } if found { return false, nil } } return true, nil }
go
func LocalNonBareGitRepositoryIsEmpty(fs fs.FileSystem, dir string) (bool, error) { gitPath := filepath.Join(dir, ".git") fi, err := fs.Stat(gitPath) if err != nil { return false, err } if !fi.IsDir() { gitPath, err = followGitSubmodule(fs, gitPath) if err != nil { return false, err } } // Search for any file in .git/{objects,refs}. We don't just search the // base .git directory because of the hook samples that are normally // generated with `git init` found := false for _, dir := range []string{"objects", "refs"} { err := fs.Walk(filepath.Join(gitPath, dir), func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() { found = true } if found { return filepath.SkipDir } return nil }) if err != nil { return false, err } if found { return false, nil } } return true, nil }
[ "func", "LocalNonBareGitRepositoryIsEmpty", "(", "fs", "fs", ".", "FileSystem", ",", "dir", "string", ")", "(", "bool", ",", "error", ")", "{", "gitPath", ":=", "filepath", ".", "Join", "(", "dir", ",", "\"", "\"", ")", "\n\n", "fi", ",", "err", ":=", "fs", ".", "Stat", "(", "gitPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "!", "fi", ".", "IsDir", "(", ")", "{", "gitPath", ",", "err", "=", "followGitSubmodule", "(", "fs", ",", "gitPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "}", "\n\n", "// Search for any file in .git/{objects,refs}. We don't just search the", "// base .git directory because of the hook samples that are normally", "// generated with `git init`", "found", ":=", "false", "\n", "for", "_", ",", "dir", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "{", "err", ":=", "fs", ".", "Walk", "(", "filepath", ".", "Join", "(", "gitPath", ",", "dir", ")", ",", "func", "(", "path", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "info", ".", "IsDir", "(", ")", "{", "found", "=", "true", "\n", "}", "\n\n", "if", "found", "{", "return", "filepath", ".", "SkipDir", "\n", "}", "\n\n", "return", "nil", "\n", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "found", "{", "return", "false", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// LocalNonBareGitRepositoryIsEmpty returns true if the non-bare git repository // at dir has no refs or objects. It also handles the case of dir being a // checked out git submodule.
[ "LocalNonBareGitRepositoryIsEmpty", "returns", "true", "if", "the", "non", "-", "bare", "git", "repository", "at", "dir", "has", "no", "refs", "or", "objects", ".", "It", "also", "handles", "the", "case", "of", "dir", "being", "a", "checked", "out", "git", "submodule", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L110-L156
train
openshift/source-to-image
pkg/scm/git/git.go
Clone
func (h *stiGit) Clone(src *URL, target string, c CloneConfig) error { var err error source := *src if cygpath.UsingCygwinGit { if source.IsLocal() { source.URL.Path, err = cygpath.ToSlashCygwin(source.LocalPath()) if err != nil { return err } } target, err = cygpath.ToSlashCygwin(target) if err != nil { return err } } cloneArgs := append([]string{"clone"}, cloneConfigToArgs(c)...) cloneArgs = append(cloneArgs, []string{source.StringNoFragment(), target}...) stderr := &bytes.Buffer{} opts := cmd.CommandOpts{Stderr: stderr} err = h.RunWithOptions(opts, "git", cloneArgs...) if err != nil { glog.Errorf("Clone failed: source %s, target %s, with output %q", source, target, stderr.String()) return err } return nil }
go
func (h *stiGit) Clone(src *URL, target string, c CloneConfig) error { var err error source := *src if cygpath.UsingCygwinGit { if source.IsLocal() { source.URL.Path, err = cygpath.ToSlashCygwin(source.LocalPath()) if err != nil { return err } } target, err = cygpath.ToSlashCygwin(target) if err != nil { return err } } cloneArgs := append([]string{"clone"}, cloneConfigToArgs(c)...) cloneArgs = append(cloneArgs, []string{source.StringNoFragment(), target}...) stderr := &bytes.Buffer{} opts := cmd.CommandOpts{Stderr: stderr} err = h.RunWithOptions(opts, "git", cloneArgs...) if err != nil { glog.Errorf("Clone failed: source %s, target %s, with output %q", source, target, stderr.String()) return err } return nil }
[ "func", "(", "h", "*", "stiGit", ")", "Clone", "(", "src", "*", "URL", ",", "target", "string", ",", "c", "CloneConfig", ")", "error", "{", "var", "err", "error", "\n\n", "source", ":=", "*", "src", "\n\n", "if", "cygpath", ".", "UsingCygwinGit", "{", "if", "source", ".", "IsLocal", "(", ")", "{", "source", ".", "URL", ".", "Path", ",", "err", "=", "cygpath", ".", "ToSlashCygwin", "(", "source", ".", "LocalPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "target", ",", "err", "=", "cygpath", ".", "ToSlashCygwin", "(", "target", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "cloneArgs", ":=", "append", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "cloneConfigToArgs", "(", "c", ")", "...", ")", "\n", "cloneArgs", "=", "append", "(", "cloneArgs", ",", "[", "]", "string", "{", "source", ".", "StringNoFragment", "(", ")", ",", "target", "}", "...", ")", "\n", "stderr", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "opts", ":=", "cmd", ".", "CommandOpts", "{", "Stderr", ":", "stderr", "}", "\n", "err", "=", "h", ".", "RunWithOptions", "(", "opts", ",", "\"", "\"", ",", "cloneArgs", "...", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "source", ",", "target", ",", "stderr", ".", "String", "(", ")", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Clone clones a git repository to a specific target directory.
[ "Clone", "clones", "a", "git", "repository", "to", "a", "specific", "target", "directory", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L165-L194
train
openshift/source-to-image
pkg/scm/git/git.go
Checkout
func (h *stiGit) Checkout(repo, ref string) error { opts := cmd.CommandOpts{ Stdout: os.Stdout, Stderr: os.Stderr, Dir: repo, } if log.V(1) { return h.RunWithOptions(opts, "git", "checkout", ref) } return h.RunWithOptions(opts, "git", "checkout", "--quiet", ref) }
go
func (h *stiGit) Checkout(repo, ref string) error { opts := cmd.CommandOpts{ Stdout: os.Stdout, Stderr: os.Stderr, Dir: repo, } if log.V(1) { return h.RunWithOptions(opts, "git", "checkout", ref) } return h.RunWithOptions(opts, "git", "checkout", "--quiet", ref) }
[ "func", "(", "h", "*", "stiGit", ")", "Checkout", "(", "repo", ",", "ref", "string", ")", "error", "{", "opts", ":=", "cmd", ".", "CommandOpts", "{", "Stdout", ":", "os", ".", "Stdout", ",", "Stderr", ":", "os", ".", "Stderr", ",", "Dir", ":", "repo", ",", "}", "\n", "if", "log", ".", "V", "(", "1", ")", "{", "return", "h", ".", "RunWithOptions", "(", "opts", ",", "\"", "\"", ",", "\"", "\"", ",", "ref", ")", "\n", "}", "\n", "return", "h", ".", "RunWithOptions", "(", "opts", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "ref", ")", "\n", "}" ]
// Checkout checks out a specific branch reference of a given git repository
[ "Checkout", "checks", "out", "a", "specific", "branch", "reference", "of", "a", "given", "git", "repository" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L197-L207
train
openshift/source-to-image
pkg/scm/git/git.go
SubmoduleUpdate
func (h *stiGit) SubmoduleUpdate(repo string, init, recursive bool) error { updateArgs := []string{"submodule", "update"} if init { updateArgs = append(updateArgs, "--init") } if recursive { updateArgs = append(updateArgs, "--recursive") } opts := cmd.CommandOpts{ Stdout: os.Stdout, Stderr: os.Stderr, Dir: repo, } return h.RunWithOptions(opts, "git", updateArgs...) }
go
func (h *stiGit) SubmoduleUpdate(repo string, init, recursive bool) error { updateArgs := []string{"submodule", "update"} if init { updateArgs = append(updateArgs, "--init") } if recursive { updateArgs = append(updateArgs, "--recursive") } opts := cmd.CommandOpts{ Stdout: os.Stdout, Stderr: os.Stderr, Dir: repo, } return h.RunWithOptions(opts, "git", updateArgs...) }
[ "func", "(", "h", "*", "stiGit", ")", "SubmoduleUpdate", "(", "repo", "string", ",", "init", ",", "recursive", "bool", ")", "error", "{", "updateArgs", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "if", "init", "{", "updateArgs", "=", "append", "(", "updateArgs", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "recursive", "{", "updateArgs", "=", "append", "(", "updateArgs", ",", "\"", "\"", ")", "\n", "}", "\n\n", "opts", ":=", "cmd", ".", "CommandOpts", "{", "Stdout", ":", "os", ".", "Stdout", ",", "Stderr", ":", "os", ".", "Stderr", ",", "Dir", ":", "repo", ",", "}", "\n", "return", "h", ".", "RunWithOptions", "(", "opts", ",", "\"", "\"", ",", "updateArgs", "...", ")", "\n", "}" ]
// SubmoduleUpdate checks out submodules to their correct version. // Optionally also inits submodules, optionally operates recursively.
[ "SubmoduleUpdate", "checks", "out", "submodules", "to", "their", "correct", "version", ".", "Optionally", "also", "inits", "submodules", "optionally", "operates", "recursively", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L221-L236
train
openshift/source-to-image
pkg/scm/git/git.go
LsTree
func (h *stiGit) LsTree(repo, ref string, recursive bool) ([]os.FileInfo, error) { args := []string{"ls-tree", ref} if recursive { args = append(args, "-r") } opts := cmd.CommandOpts{ Dir: repo, } r, err := h.StartWithStdoutPipe(opts, "git", args...) if err != nil { return nil, err } submodules := []string{} rv := []os.FileInfo{} scanner := bufio.NewScanner(r) for scanner.Scan() { text := scanner.Text() m := lsTreeRegexp.FindStringSubmatch(text) if m == nil { return nil, fmt.Errorf("unparsable response %q from git ls-files", text) } mode, _ := strconv.ParseInt(m[1], 8, 0) path := m[2] if recursive && mode == 0160000 { // S_IFGITLINK submodules = append(submodules, filepath.Join(repo, path)) continue } rv = append(rv, &fs.FileInfo{FileMode: os.FileMode(mode), FileName: path}) } err = scanner.Err() if err != nil { h.Wait() return nil, err } err = h.Wait() if err != nil { return nil, err } for _, submodule := range submodules { rrv, err := h.LsTree(submodule, "HEAD", recursive) if err != nil { return nil, err } rv = append(rv, rrv...) } return rv, nil }
go
func (h *stiGit) LsTree(repo, ref string, recursive bool) ([]os.FileInfo, error) { args := []string{"ls-tree", ref} if recursive { args = append(args, "-r") } opts := cmd.CommandOpts{ Dir: repo, } r, err := h.StartWithStdoutPipe(opts, "git", args...) if err != nil { return nil, err } submodules := []string{} rv := []os.FileInfo{} scanner := bufio.NewScanner(r) for scanner.Scan() { text := scanner.Text() m := lsTreeRegexp.FindStringSubmatch(text) if m == nil { return nil, fmt.Errorf("unparsable response %q from git ls-files", text) } mode, _ := strconv.ParseInt(m[1], 8, 0) path := m[2] if recursive && mode == 0160000 { // S_IFGITLINK submodules = append(submodules, filepath.Join(repo, path)) continue } rv = append(rv, &fs.FileInfo{FileMode: os.FileMode(mode), FileName: path}) } err = scanner.Err() if err != nil { h.Wait() return nil, err } err = h.Wait() if err != nil { return nil, err } for _, submodule := range submodules { rrv, err := h.LsTree(submodule, "HEAD", recursive) if err != nil { return nil, err } rv = append(rv, rrv...) } return rv, nil }
[ "func", "(", "h", "*", "stiGit", ")", "LsTree", "(", "repo", ",", "ref", "string", ",", "recursive", "bool", ")", "(", "[", "]", "os", ".", "FileInfo", ",", "error", ")", "{", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "ref", "}", "\n", "if", "recursive", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "}", "\n\n", "opts", ":=", "cmd", ".", "CommandOpts", "{", "Dir", ":", "repo", ",", "}", "\n\n", "r", ",", "err", ":=", "h", ".", "StartWithStdoutPipe", "(", "opts", ",", "\"", "\"", ",", "args", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "submodules", ":=", "[", "]", "string", "{", "}", "\n", "rv", ":=", "[", "]", "os", ".", "FileInfo", "{", "}", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "text", ":=", "scanner", ".", "Text", "(", ")", "\n", "m", ":=", "lsTreeRegexp", ".", "FindStringSubmatch", "(", "text", ")", "\n", "if", "m", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "text", ")", "\n", "}", "\n", "mode", ",", "_", ":=", "strconv", ".", "ParseInt", "(", "m", "[", "1", "]", ",", "8", ",", "0", ")", "\n", "path", ":=", "m", "[", "2", "]", "\n", "if", "recursive", "&&", "mode", "==", "0160000", "{", "// S_IFGITLINK", "submodules", "=", "append", "(", "submodules", ",", "filepath", ".", "Join", "(", "repo", ",", "path", ")", ")", "\n", "continue", "\n", "}", "\n", "rv", "=", "append", "(", "rv", ",", "&", "fs", ".", "FileInfo", "{", "FileMode", ":", "os", ".", "FileMode", "(", "mode", ")", ",", "FileName", ":", "path", "}", ")", "\n", "}", "\n", "err", "=", "scanner", ".", "Err", "(", ")", "\n", "if", "err", "!=", "nil", "{", "h", ".", "Wait", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "h", ".", "Wait", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "submodule", ":=", "range", "submodules", "{", "rrv", ",", "err", ":=", "h", ".", "LsTree", "(", "submodule", ",", "\"", "\"", ",", "recursive", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rv", "=", "append", "(", "rv", ",", "rrv", "...", ")", "\n", "}", "\n\n", "return", "rv", ",", "nil", "\n", "}" ]
// LsTree returns a slice of os.FileInfo objects populated with the paths and // file modes of files known to Git. This is used on Windows systems where the // executable mode metadata is lost on git checkout.
[ "LsTree", "returns", "a", "slice", "of", "os", ".", "FileInfo", "objects", "populated", "with", "the", "paths", "and", "file", "modes", "of", "files", "known", "to", "Git", ".", "This", "is", "used", "on", "Windows", "systems", "where", "the", "executable", "mode", "metadata", "is", "lost", "on", "git", "checkout", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L241-L293
train
openshift/source-to-image
pkg/scm/git/git.go
GetInfo
func (h *stiGit) GetInfo(repo string) *SourceInfo { git := func(arg ...string) string { command := exec.Command("git", arg...) command.Dir = repo out, err := command.CombinedOutput() if err != nil { glog.V(1).Infof("Error executing 'git %#v': %s (%v)", arg, out, err) return "" } return strings.TrimSpace(string(out)) } return &SourceInfo{ Location: git("config", "--get", "remote.origin.url"), Ref: git("rev-parse", "--abbrev-ref", "HEAD"), CommitID: git("rev-parse", "--verify", "HEAD"), AuthorName: git("--no-pager", "show", "-s", "--format=%an", "HEAD"), AuthorEmail: git("--no-pager", "show", "-s", "--format=%ae", "HEAD"), CommitterName: git("--no-pager", "show", "-s", "--format=%cn", "HEAD"), CommitterEmail: git("--no-pager", "show", "-s", "--format=%ce", "HEAD"), Date: git("--no-pager", "show", "-s", "--format=%ad", "HEAD"), Message: git("--no-pager", "show", "-s", "--format=%<(80,trunc)%s", "HEAD"), } }
go
func (h *stiGit) GetInfo(repo string) *SourceInfo { git := func(arg ...string) string { command := exec.Command("git", arg...) command.Dir = repo out, err := command.CombinedOutput() if err != nil { glog.V(1).Infof("Error executing 'git %#v': %s (%v)", arg, out, err) return "" } return strings.TrimSpace(string(out)) } return &SourceInfo{ Location: git("config", "--get", "remote.origin.url"), Ref: git("rev-parse", "--abbrev-ref", "HEAD"), CommitID: git("rev-parse", "--verify", "HEAD"), AuthorName: git("--no-pager", "show", "-s", "--format=%an", "HEAD"), AuthorEmail: git("--no-pager", "show", "-s", "--format=%ae", "HEAD"), CommitterName: git("--no-pager", "show", "-s", "--format=%cn", "HEAD"), CommitterEmail: git("--no-pager", "show", "-s", "--format=%ce", "HEAD"), Date: git("--no-pager", "show", "-s", "--format=%ad", "HEAD"), Message: git("--no-pager", "show", "-s", "--format=%<(80,trunc)%s", "HEAD"), } }
[ "func", "(", "h", "*", "stiGit", ")", "GetInfo", "(", "repo", "string", ")", "*", "SourceInfo", "{", "git", ":=", "func", "(", "arg", "...", "string", ")", "string", "{", "command", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "arg", "...", ")", "\n", "command", ".", "Dir", "=", "repo", "\n", "out", ",", "err", ":=", "command", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "arg", ",", "out", ",", "err", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "strings", ".", "TrimSpace", "(", "string", "(", "out", ")", ")", "\n", "}", "\n", "return", "&", "SourceInfo", "{", "Location", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "Ref", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "CommitID", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "AuthorName", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "AuthorEmail", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "CommitterName", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "CommitterEmail", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "Date", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "Message", ":", "git", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "}", "\n", "}" ]
// GetInfo retrieves the information about the source code and commit
[ "GetInfo", "retrieves", "the", "information", "about", "the", "source", "code", "and", "commit" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/git.go#L296-L318
train
openshift/source-to-image
pkg/util/glog/glog.go
V
func (f *FileLogger) V(level int32) VerboseLogger { // Is the loglevel set verbose enough to accept the forthcoming log statement if log.V(log.Level(level)) { return f } // Otherwise discard return None }
go
func (f *FileLogger) V(level int32) VerboseLogger { // Is the loglevel set verbose enough to accept the forthcoming log statement if log.V(log.Level(level)) { return f } // Otherwise discard return None }
[ "func", "(", "f", "*", "FileLogger", ")", "V", "(", "level", "int32", ")", "VerboseLogger", "{", "// Is the loglevel set verbose enough to accept the forthcoming log statement", "if", "log", ".", "V", "(", "log", ".", "Level", "(", "level", ")", ")", "{", "return", "f", "\n", "}", "\n", "// Otherwise discard", "return", "None", "\n", "}" ]
// V will returns a logger which will discard output if the specified level is greater than the current logging level.
[ "V", "will", "returns", "a", "logger", "which", "will", "discard", "output", "if", "the", "specified", "level", "is", "greater", "than", "the", "current", "logging", "level", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L110-L117
train
openshift/source-to-image
pkg/util/glog/glog.go
Infof
func (f *FileLogger) Infof(format string, args ...interface{}) { f.outputf(infoLog, format, args...) }
go
func (f *FileLogger) Infof(format string, args ...interface{}) { f.outputf(infoLog, format, args...) }
[ "func", "(", "f", "*", "FileLogger", ")", "Infof", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "outputf", "(", "infoLog", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// Infof records an info log entry.
[ "Infof", "records", "an", "info", "log", "entry", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L174-L176
train
openshift/source-to-image
pkg/util/glog/glog.go
Warningf
func (f *FileLogger) Warningf(format string, args ...interface{}) { f.outputf(warningLog, format, args...) }
go
func (f *FileLogger) Warningf(format string, args ...interface{}) { f.outputf(warningLog, format, args...) }
[ "func", "(", "f", "*", "FileLogger", ")", "Warningf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "outputf", "(", "warningLog", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// Warningf records an warning log entry.
[ "Warningf", "records", "an", "warning", "log", "entry", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L184-L186
train
openshift/source-to-image
pkg/util/glog/glog.go
Errorf
func (f *FileLogger) Errorf(format string, args ...interface{}) { f.outputf(errorLog, format, args...) }
go
func (f *FileLogger) Errorf(format string, args ...interface{}) { f.outputf(errorLog, format, args...) }
[ "func", "(", "f", "*", "FileLogger", ")", "Errorf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "f", ".", "outputf", "(", "errorLog", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// Errorf records an error log entry.
[ "Errorf", "records", "an", "error", "log", "entry", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L194-L196
train
openshift/source-to-image
pkg/util/glog/glog.go
Fatalf
func (f *FileLogger) Fatalf(format string, args ...interface{}) { defer os.Exit(1) f.outputf(fatalLog, format, args...) }
go
func (f *FileLogger) Fatalf(format string, args ...interface{}) { defer os.Exit(1) f.outputf(fatalLog, format, args...) }
[ "func", "(", "f", "*", "FileLogger", ")", "Fatalf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "defer", "os", ".", "Exit", "(", "1", ")", "\n", "f", ".", "outputf", "(", "fatalLog", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// Fatalf records a fatal log entry and terminates the program.
[ "Fatalf", "records", "a", "fatal", "log", "entry", "and", "terminates", "the", "program", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L204-L207
train
openshift/source-to-image
pkg/util/glog/glog.go
Fatal
func (f *FileLogger) Fatal(args ...interface{}) { defer os.Exit(1) f.output(fatalLog, args...) }
go
func (f *FileLogger) Fatal(args ...interface{}) { defer os.Exit(1) f.output(fatalLog, args...) }
[ "func", "(", "f", "*", "FileLogger", ")", "Fatal", "(", "args", "...", "interface", "{", "}", ")", "{", "defer", "os", ".", "Exit", "(", "1", ")", "\n", "f", ".", "output", "(", "fatalLog", ",", "args", "...", ")", "\n", "}" ]
// Fatal records a fatal log entry and terminates the program.
[ "Fatal", "records", "a", "fatal", "log", "entry", "and", "terminates", "the", "program", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/glog/glog.go#L210-L213
train
openshift/source-to-image
pkg/api/helpers.go
RecordStageAndStepInfo
func RecordStageAndStepInfo(stages []StageInfo, stageName StageName, stepName StepName, startTime time.Time, endTime time.Time) []StageInfo { // Make sure that the stages slice is initialized if len(stages) == 0 { stages = make([]StageInfo, 0) } // If the stage already exists update the endTime and Duration, and append the new step. for stageKey, stageVal := range stages { if stageVal.Name == stageName { stages[stageKey].DurationMilliseconds = endTime.Sub(stages[stageKey].StartTime).Nanoseconds() / int64(time.Millisecond) if len(stages[stageKey].Steps) == 0 { stages[stageKey].Steps = make([]StepInfo, 0) } stages[stageKey].Steps = append(stages[stageKey].Steps, StepInfo{ Name: stepName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) return stages } } // If the stageName does not exist, add it to the slice along with the new step. steps := make([]StepInfo, 0) steps = append(steps, StepInfo{ Name: stepName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) stages = append(stages, StageInfo{ Name: stageName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), Steps: steps, }) return stages }
go
func RecordStageAndStepInfo(stages []StageInfo, stageName StageName, stepName StepName, startTime time.Time, endTime time.Time) []StageInfo { // Make sure that the stages slice is initialized if len(stages) == 0 { stages = make([]StageInfo, 0) } // If the stage already exists update the endTime and Duration, and append the new step. for stageKey, stageVal := range stages { if stageVal.Name == stageName { stages[stageKey].DurationMilliseconds = endTime.Sub(stages[stageKey].StartTime).Nanoseconds() / int64(time.Millisecond) if len(stages[stageKey].Steps) == 0 { stages[stageKey].Steps = make([]StepInfo, 0) } stages[stageKey].Steps = append(stages[stageKey].Steps, StepInfo{ Name: stepName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) return stages } } // If the stageName does not exist, add it to the slice along with the new step. steps := make([]StepInfo, 0) steps = append(steps, StepInfo{ Name: stepName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), }) stages = append(stages, StageInfo{ Name: stageName, StartTime: startTime, DurationMilliseconds: endTime.Sub(startTime).Nanoseconds() / int64(time.Millisecond), Steps: steps, }) return stages }
[ "func", "RecordStageAndStepInfo", "(", "stages", "[", "]", "StageInfo", ",", "stageName", "StageName", ",", "stepName", "StepName", ",", "startTime", "time", ".", "Time", ",", "endTime", "time", ".", "Time", ")", "[", "]", "StageInfo", "{", "// Make sure that the stages slice is initialized", "if", "len", "(", "stages", ")", "==", "0", "{", "stages", "=", "make", "(", "[", "]", "StageInfo", ",", "0", ")", "\n", "}", "\n\n", "// If the stage already exists update the endTime and Duration, and append the new step.", "for", "stageKey", ",", "stageVal", ":=", "range", "stages", "{", "if", "stageVal", ".", "Name", "==", "stageName", "{", "stages", "[", "stageKey", "]", ".", "DurationMilliseconds", "=", "endTime", ".", "Sub", "(", "stages", "[", "stageKey", "]", ".", "StartTime", ")", ".", "Nanoseconds", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", "\n", "if", "len", "(", "stages", "[", "stageKey", "]", ".", "Steps", ")", "==", "0", "{", "stages", "[", "stageKey", "]", ".", "Steps", "=", "make", "(", "[", "]", "StepInfo", ",", "0", ")", "\n", "}", "\n", "stages", "[", "stageKey", "]", ".", "Steps", "=", "append", "(", "stages", "[", "stageKey", "]", ".", "Steps", ",", "StepInfo", "{", "Name", ":", "stepName", ",", "StartTime", ":", "startTime", ",", "DurationMilliseconds", ":", "endTime", ".", "Sub", "(", "startTime", ")", ".", "Nanoseconds", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", ",", "}", ")", "\n", "return", "stages", "\n", "}", "\n", "}", "\n\n", "// If the stageName does not exist, add it to the slice along with the new step.", "steps", ":=", "make", "(", "[", "]", "StepInfo", ",", "0", ")", "\n", "steps", "=", "append", "(", "steps", ",", "StepInfo", "{", "Name", ":", "stepName", ",", "StartTime", ":", "startTime", ",", "DurationMilliseconds", ":", "endTime", ".", "Sub", "(", "startTime", ")", ".", "Nanoseconds", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", ",", "}", ")", "\n", "stages", "=", "append", "(", "stages", ",", "StageInfo", "{", "Name", ":", "stageName", ",", "StartTime", ":", "startTime", ",", "DurationMilliseconds", ":", "endTime", ".", "Sub", "(", "startTime", ")", ".", "Nanoseconds", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", ",", "Steps", ":", "steps", ",", "}", ")", "\n", "return", "stages", "\n", "}" ]
// RecordStageAndStepInfo records details about each build stage and step
[ "RecordStageAndStepInfo", "records", "details", "about", "each", "build", "stage", "and", "step" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/api/helpers.go#L6-L42
train
openshift/source-to-image
pkg/util/injection.go
FixInjectionsWithRelativePath
func FixInjectionsWithRelativePath(workdir string, injections api.VolumeList) api.VolumeList { if len(injections) == 0 { return injections } newList := api.VolumeList{} for _, injection := range injections { changed := false if filepath.Clean(filepath.FromSlash(injection.Destination)) == "." { injection.Destination = filepath.ToSlash(workdir) changed = true } if filepath.ToSlash(injection.Destination)[0] != '/' { injection.Destination = filepath.ToSlash(filepath.Join(workdir, injection.Destination)) changed = true } if changed { glog.V(5).Infof("Using %q as a destination for injecting %q", injection.Destination, injection.Source) } newList = append(newList, injection) } return newList }
go
func FixInjectionsWithRelativePath(workdir string, injections api.VolumeList) api.VolumeList { if len(injections) == 0 { return injections } newList := api.VolumeList{} for _, injection := range injections { changed := false if filepath.Clean(filepath.FromSlash(injection.Destination)) == "." { injection.Destination = filepath.ToSlash(workdir) changed = true } if filepath.ToSlash(injection.Destination)[0] != '/' { injection.Destination = filepath.ToSlash(filepath.Join(workdir, injection.Destination)) changed = true } if changed { glog.V(5).Infof("Using %q as a destination for injecting %q", injection.Destination, injection.Source) } newList = append(newList, injection) } return newList }
[ "func", "FixInjectionsWithRelativePath", "(", "workdir", "string", ",", "injections", "api", ".", "VolumeList", ")", "api", ".", "VolumeList", "{", "if", "len", "(", "injections", ")", "==", "0", "{", "return", "injections", "\n", "}", "\n", "newList", ":=", "api", ".", "VolumeList", "{", "}", "\n", "for", "_", ",", "injection", ":=", "range", "injections", "{", "changed", ":=", "false", "\n", "if", "filepath", ".", "Clean", "(", "filepath", ".", "FromSlash", "(", "injection", ".", "Destination", ")", ")", "==", "\"", "\"", "{", "injection", ".", "Destination", "=", "filepath", ".", "ToSlash", "(", "workdir", ")", "\n", "changed", "=", "true", "\n", "}", "\n", "if", "filepath", ".", "ToSlash", "(", "injection", ".", "Destination", ")", "[", "0", "]", "!=", "'/'", "{", "injection", ".", "Destination", "=", "filepath", ".", "ToSlash", "(", "filepath", ".", "Join", "(", "workdir", ",", "injection", ".", "Destination", ")", ")", "\n", "changed", "=", "true", "\n", "}", "\n", "if", "changed", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "injection", ".", "Destination", ",", "injection", ".", "Source", ")", "\n", "}", "\n", "newList", "=", "append", "(", "newList", ",", "injection", ")", "\n", "}", "\n", "return", "newList", "\n", "}" ]
// FixInjectionsWithRelativePath fixes the injections that does not specify the // destination directory or the directory is relative to use the provided // working directory.
[ "FixInjectionsWithRelativePath", "fixes", "the", "injections", "that", "does", "not", "specify", "the", "destination", "directory", "or", "the", "directory", "is", "relative", "to", "use", "the", "provided", "working", "directory", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L17-L38
train
openshift/source-to-image
pkg/util/injection.go
ListFilesToTruncate
func ListFilesToTruncate(fs fs.FileSystem, injections api.VolumeList) ([]string, error) { result := []string{} for _, s := range injections { if s.Keep { continue } files, err := ListFiles(fs, s) if err != nil { return nil, err } result = append(result, files...) } return result, nil }
go
func ListFilesToTruncate(fs fs.FileSystem, injections api.VolumeList) ([]string, error) { result := []string{} for _, s := range injections { if s.Keep { continue } files, err := ListFiles(fs, s) if err != nil { return nil, err } result = append(result, files...) } return result, nil }
[ "func", "ListFilesToTruncate", "(", "fs", "fs", ".", "FileSystem", ",", "injections", "api", ".", "VolumeList", ")", "(", "[", "]", "string", ",", "error", ")", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "s", ":=", "range", "injections", "{", "if", "s", ".", "Keep", "{", "continue", "\n", "}", "\n", "files", ",", "err", ":=", "ListFiles", "(", "fs", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "files", "...", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ListFilesToTruncate returns a flat list of all files that are injected into a // container which need to be truncated. All files from nested directories are returned in the list.
[ "ListFilesToTruncate", "returns", "a", "flat", "list", "of", "all", "files", "that", "are", "injected", "into", "a", "container", "which", "need", "to", "be", "truncated", ".", "All", "files", "from", "nested", "directories", "are", "returned", "in", "the", "list", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L42-L55
train
openshift/source-to-image
pkg/util/injection.go
ListFiles
func ListFiles(fs fs.FileSystem, spec api.VolumeSpec) ([]string, error) { result := []string{} if _, err := os.Stat(spec.Source); err != nil { return nil, err } err := fs.Walk(spec.Source, func(path string, f os.FileInfo, err error) error { if err != nil { return err } // Detected files will be truncated. k8s' AtomicWriter creates // directories and symlinks to directories in order to inject files. // An attempt to truncate either a dir or symlink to a dir will fail. // Thus, we need to dereference symlinks to see if they might point // to a directory. // Do not try to simplify this logic to simply return nil if a symlink // is detected. During the tar transfer to an assemble image, symlinked // files are turned concrete (i.e. they will be turned into regular files // containing the content of their target). These newly concrete files // need to be truncated as well. if f.Mode()&os.ModeSymlink != 0 { linkDest, err := filepath.EvalSymlinks(path) if err != nil { return fmt.Errorf("unable to evaluate symlink [%v]: %v", path, err) } // Evaluate the destination of the link. f, err = os.Lstat(linkDest) if err != nil { // This is not a fatal error. If AtomicWrite tried multiple times, a symlink might not point // to a valid destination. glog.Warningf("Unable to lstat symlink destination [%s]->[%s]. err: %v. Partial atomic write?", path, linkDest, err) return nil } } if f.IsDir() { return nil } newPath := filepath.ToSlash(filepath.Join(spec.Destination, strings.TrimPrefix(path, spec.Source))) result = append(result, newPath) return nil }) if err != nil { return nil, err } return result, nil }
go
func ListFiles(fs fs.FileSystem, spec api.VolumeSpec) ([]string, error) { result := []string{} if _, err := os.Stat(spec.Source); err != nil { return nil, err } err := fs.Walk(spec.Source, func(path string, f os.FileInfo, err error) error { if err != nil { return err } // Detected files will be truncated. k8s' AtomicWriter creates // directories and symlinks to directories in order to inject files. // An attempt to truncate either a dir or symlink to a dir will fail. // Thus, we need to dereference symlinks to see if they might point // to a directory. // Do not try to simplify this logic to simply return nil if a symlink // is detected. During the tar transfer to an assemble image, symlinked // files are turned concrete (i.e. they will be turned into regular files // containing the content of their target). These newly concrete files // need to be truncated as well. if f.Mode()&os.ModeSymlink != 0 { linkDest, err := filepath.EvalSymlinks(path) if err != nil { return fmt.Errorf("unable to evaluate symlink [%v]: %v", path, err) } // Evaluate the destination of the link. f, err = os.Lstat(linkDest) if err != nil { // This is not a fatal error. If AtomicWrite tried multiple times, a symlink might not point // to a valid destination. glog.Warningf("Unable to lstat symlink destination [%s]->[%s]. err: %v. Partial atomic write?", path, linkDest, err) return nil } } if f.IsDir() { return nil } newPath := filepath.ToSlash(filepath.Join(spec.Destination, strings.TrimPrefix(path, spec.Source))) result = append(result, newPath) return nil }) if err != nil { return nil, err } return result, nil }
[ "func", "ListFiles", "(", "fs", "fs", ".", "FileSystem", ",", "spec", "api", ".", "VolumeSpec", ")", "(", "[", "]", "string", ",", "error", ")", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "spec", ".", "Source", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", ":=", "fs", ".", "Walk", "(", "spec", ".", "Source", ",", "func", "(", "path", "string", ",", "f", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Detected files will be truncated. k8s' AtomicWriter creates", "// directories and symlinks to directories in order to inject files.", "// An attempt to truncate either a dir or symlink to a dir will fail.", "// Thus, we need to dereference symlinks to see if they might point", "// to a directory.", "// Do not try to simplify this logic to simply return nil if a symlink", "// is detected. During the tar transfer to an assemble image, symlinked", "// files are turned concrete (i.e. they will be turned into regular files", "// containing the content of their target). These newly concrete files", "// need to be truncated as well.", "if", "f", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "!=", "0", "{", "linkDest", ",", "err", ":=", "filepath", ".", "EvalSymlinks", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "err", ")", "\n", "}", "\n", "// Evaluate the destination of the link.", "f", ",", "err", "=", "os", ".", "Lstat", "(", "linkDest", ")", "\n", "if", "err", "!=", "nil", "{", "// This is not a fatal error. If AtomicWrite tried multiple times, a symlink might not point", "// to a valid destination.", "glog", ".", "Warningf", "(", "\"", "\"", ",", "path", ",", "linkDest", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n\n", "if", "f", ".", "IsDir", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "newPath", ":=", "filepath", ".", "ToSlash", "(", "filepath", ".", "Join", "(", "spec", ".", "Destination", ",", "strings", ".", "TrimPrefix", "(", "path", ",", "spec", ".", "Source", ")", ")", ")", "\n", "result", "=", "append", "(", "result", ",", "newPath", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ListFiles returns a flat list of all files injected into a container for the given `VolumeSpec`.
[ "ListFiles", "returns", "a", "flat", "list", "of", "all", "files", "injected", "into", "a", "container", "for", "the", "given", "VolumeSpec", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L58-L106
train
openshift/source-to-image
pkg/util/injection.go
CreateTruncateFilesScript
func CreateTruncateFilesScript(files []string, scriptName string) (string, error) { rmScript := "set -e\n" for _, s := range files { rmScript += fmt.Sprintf("truncate -s0 %q\n", s) } f, err := ioutil.TempFile("", "s2i-injection-remove") if err != nil { return "", err } if len(scriptName) > 0 { rmScript += fmt.Sprintf("truncate -s0 %q\n", scriptName) } rmScript += "set +e\n" err = ioutil.WriteFile(f.Name(), []byte(rmScript), 0700) return f.Name(), err }
go
func CreateTruncateFilesScript(files []string, scriptName string) (string, error) { rmScript := "set -e\n" for _, s := range files { rmScript += fmt.Sprintf("truncate -s0 %q\n", s) } f, err := ioutil.TempFile("", "s2i-injection-remove") if err != nil { return "", err } if len(scriptName) > 0 { rmScript += fmt.Sprintf("truncate -s0 %q\n", scriptName) } rmScript += "set +e\n" err = ioutil.WriteFile(f.Name(), []byte(rmScript), 0700) return f.Name(), err }
[ "func", "CreateTruncateFilesScript", "(", "files", "[", "]", "string", ",", "scriptName", "string", ")", "(", "string", ",", "error", ")", "{", "rmScript", ":=", "\"", "\\n", "\"", "\n", "for", "_", ",", "s", ":=", "range", "files", "{", "rmScript", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "s", ")", "\n", "}", "\n\n", "f", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "len", "(", "scriptName", ")", ">", "0", "{", "rmScript", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "scriptName", ")", "\n", "}", "\n", "rmScript", "+=", "\"", "\\n", "\"", "\n", "err", "=", "ioutil", ".", "WriteFile", "(", "f", ".", "Name", "(", ")", ",", "[", "]", "byte", "(", "rmScript", ")", ",", "0700", ")", "\n", "return", "f", ".", "Name", "(", ")", ",", "err", "\n", "}" ]
// CreateTruncateFilesScript creates a shell script that contains truncation // of all files we injected into the container. The path to the script is returned. // When the scriptName is provided, it is also truncated together with all // secrets.
[ "CreateTruncateFilesScript", "creates", "a", "shell", "script", "that", "contains", "truncation", "of", "all", "files", "we", "injected", "into", "the", "container", ".", "The", "path", "to", "the", "script", "is", "returned", ".", "When", "the", "scriptName", "is", "provided", "it", "is", "also", "truncated", "together", "with", "all", "secrets", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L112-L128
train
openshift/source-to-image
pkg/util/injection.go
CreateInjectionResultFile
func CreateInjectionResultFile(injectErr error) (string, error) { f, err := ioutil.TempFile("", "s2i-injection-result") if err != nil { return "", err } if injectErr != nil { err = ioutil.WriteFile(f.Name(), []byte(injectErr.Error()), 0700) } return f.Name(), err }
go
func CreateInjectionResultFile(injectErr error) (string, error) { f, err := ioutil.TempFile("", "s2i-injection-result") if err != nil { return "", err } if injectErr != nil { err = ioutil.WriteFile(f.Name(), []byte(injectErr.Error()), 0700) } return f.Name(), err }
[ "func", "CreateInjectionResultFile", "(", "injectErr", "error", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "injectErr", "!=", "nil", "{", "err", "=", "ioutil", ".", "WriteFile", "(", "f", ".", "Name", "(", ")", ",", "[", "]", "byte", "(", "injectErr", ".", "Error", "(", ")", ")", ",", "0700", ")", "\n", "}", "\n", "return", "f", ".", "Name", "(", ")", ",", "err", "\n", "}" ]
// CreateInjectionResultFile creates a result file with the message from the provided injection // error. The path to the result file is returned. If the provided error is nil, an empty file is // created.
[ "CreateInjectionResultFile", "creates", "a", "result", "file", "with", "the", "message", "from", "the", "provided", "injection", "error", ".", "The", "path", "to", "the", "result", "file", "is", "returned", ".", "If", "the", "provided", "error", "is", "nil", "an", "empty", "file", "is", "created", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L133-L142
train
openshift/source-to-image
pkg/util/injection.go
HandleInjectionError
func HandleInjectionError(p api.VolumeSpec, err error) error { if err == nil { return nil } if strings.Contains(err.Error(), "no such file or directory") { glog.Errorf("The destination directory for %q injection must exist in container (%q)", p.Source, p.Destination) return err } glog.Errorf("Error occurred during injecting %q to %q: %v", p.Source, p.Destination, err) return err }
go
func HandleInjectionError(p api.VolumeSpec, err error) error { if err == nil { return nil } if strings.Contains(err.Error(), "no such file or directory") { glog.Errorf("The destination directory for %q injection must exist in container (%q)", p.Source, p.Destination) return err } glog.Errorf("Error occurred during injecting %q to %q: %v", p.Source, p.Destination, err) return err }
[ "func", "HandleInjectionError", "(", "p", "api", ".", "VolumeSpec", ",", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "Source", ",", "p", ".", "Destination", ")", "\n", "return", "err", "\n", "}", "\n", "glog", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "Source", ",", "p", ".", "Destination", ",", "err", ")", "\n", "return", "err", "\n", "}" ]
// HandleInjectionError handles the error caused by injection and provide // reasonable suggestion to users.
[ "HandleInjectionError", "handles", "the", "error", "caused", "by", "injection", "and", "provide", "reasonable", "suggestion", "to", "users", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/injection.go#L146-L156
train
openshift/source-to-image
pkg/scm/scm.go
DownloaderForSource
func DownloaderForSource(fs fs.FileSystem, s *git.URL, forceCopy bool) (build.Downloader, error) { glog.V(4).Infof("DownloadForSource %s", s) if s == nil { return &empty.Noop{}, nil } if s.IsLocal() { if forceCopy { return &file.File{FileSystem: fs}, nil } isLocalNonBareGitRepo, err := git.IsLocalNonBareGitRepository(fs, s.LocalPath()) if err != nil { return nil, err } if !isLocalNonBareGitRepo { return &file.File{FileSystem: fs}, nil } isEmpty, err := git.LocalNonBareGitRepositoryIsEmpty(fs, s.LocalPath()) if err != nil { return nil, err } if isEmpty { return nil, errors.NewEmptyGitRepositoryError(s.LocalPath()) } if !git.HasGitBinary() { return &file.File{FileSystem: fs}, nil } } return &gitdownloader.Clone{Git: git.New(fs, cmd.NewCommandRunner()), FileSystem: fs}, nil }
go
func DownloaderForSource(fs fs.FileSystem, s *git.URL, forceCopy bool) (build.Downloader, error) { glog.V(4).Infof("DownloadForSource %s", s) if s == nil { return &empty.Noop{}, nil } if s.IsLocal() { if forceCopy { return &file.File{FileSystem: fs}, nil } isLocalNonBareGitRepo, err := git.IsLocalNonBareGitRepository(fs, s.LocalPath()) if err != nil { return nil, err } if !isLocalNonBareGitRepo { return &file.File{FileSystem: fs}, nil } isEmpty, err := git.LocalNonBareGitRepositoryIsEmpty(fs, s.LocalPath()) if err != nil { return nil, err } if isEmpty { return nil, errors.NewEmptyGitRepositoryError(s.LocalPath()) } if !git.HasGitBinary() { return &file.File{FileSystem: fs}, nil } } return &gitdownloader.Clone{Git: git.New(fs, cmd.NewCommandRunner()), FileSystem: fs}, nil }
[ "func", "DownloaderForSource", "(", "fs", "fs", ".", "FileSystem", ",", "s", "*", "git", ".", "URL", ",", "forceCopy", "bool", ")", "(", "build", ".", "Downloader", ",", "error", ")", "{", "glog", ".", "V", "(", "4", ")", ".", "Infof", "(", "\"", "\"", ",", "s", ")", "\n\n", "if", "s", "==", "nil", "{", "return", "&", "empty", ".", "Noop", "{", "}", ",", "nil", "\n", "}", "\n\n", "if", "s", ".", "IsLocal", "(", ")", "{", "if", "forceCopy", "{", "return", "&", "file", ".", "File", "{", "FileSystem", ":", "fs", "}", ",", "nil", "\n", "}", "\n\n", "isLocalNonBareGitRepo", ",", "err", ":=", "git", ".", "IsLocalNonBareGitRepository", "(", "fs", ",", "s", ".", "LocalPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "isLocalNonBareGitRepo", "{", "return", "&", "file", ".", "File", "{", "FileSystem", ":", "fs", "}", ",", "nil", "\n", "}", "\n\n", "isEmpty", ",", "err", ":=", "git", ".", "LocalNonBareGitRepositoryIsEmpty", "(", "fs", ",", "s", ".", "LocalPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "isEmpty", "{", "return", "nil", ",", "errors", ".", "NewEmptyGitRepositoryError", "(", "s", ".", "LocalPath", "(", ")", ")", "\n", "}", "\n\n", "if", "!", "git", ".", "HasGitBinary", "(", ")", "{", "return", "&", "file", ".", "File", "{", "FileSystem", ":", "fs", "}", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "&", "gitdownloader", ".", "Clone", "{", "Git", ":", "git", ".", "New", "(", "fs", ",", "cmd", ".", "NewCommandRunner", "(", ")", ")", ",", "FileSystem", ":", "fs", "}", ",", "nil", "\n", "}" ]
// DownloaderForSource determines what SCM plugin should be used for downloading // the sources from the repository.
[ "DownloaderForSource", "determines", "what", "SCM", "plugin", "should", "be", "used", "for", "downloading", "the", "sources", "from", "the", "repository", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/scm.go#L19-L53
train
openshift/source-to-image
pkg/util/status/build_status.go
NewFailureReason
func NewFailureReason(reason api.StepFailureReason, message api.StepFailureMessage) api.FailureReason { return api.FailureReason{ Reason: reason, Message: message, } }
go
func NewFailureReason(reason api.StepFailureReason, message api.StepFailureMessage) api.FailureReason { return api.FailureReason{ Reason: reason, Message: message, } }
[ "func", "NewFailureReason", "(", "reason", "api", ".", "StepFailureReason", ",", "message", "api", ".", "StepFailureMessage", ")", "api", ".", "FailureReason", "{", "return", "api", ".", "FailureReason", "{", "Reason", ":", "reason", ",", "Message", ":", "message", ",", "}", "\n", "}" ]
// NewFailureReason initializes a new failure reason that contains both the // reason and a message to be displayed.
[ "NewFailureReason", "initializes", "a", "new", "failure", "reason", "that", "contains", "both", "the", "reason", "and", "a", "message", "to", "be", "displayed", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/status/build_status.go#L126-L131
train
openshift/source-to-image
pkg/docker/util.go
GetImageRegistryAuth
func GetImageRegistryAuth(auths *AuthConfigurations, imageName string) api.AuthConfig { glog.V(5).Infof("Getting docker credentials for %s", imageName) if auths == nil { return api.AuthConfig{} } ref, err := parseNamedDockerImageReference(imageName) if err != nil { glog.V(0).Infof("error: Failed to parse docker reference %s", imageName) return api.AuthConfig{} } if ref.Registry != "" { if auth, ok := auths.Configs[ref.Registry]; ok { glog.V(5).Infof("Using %s[%s] credentials for pulling %s", auth.Email, ref.Registry, imageName) return auth } } if auth, ok := auths.Configs[defaultRegistry]; ok { glog.V(5).Infof("Using %s credentials for pulling %s", auth.Email, imageName) return auth } return api.AuthConfig{} }
go
func GetImageRegistryAuth(auths *AuthConfigurations, imageName string) api.AuthConfig { glog.V(5).Infof("Getting docker credentials for %s", imageName) if auths == nil { return api.AuthConfig{} } ref, err := parseNamedDockerImageReference(imageName) if err != nil { glog.V(0).Infof("error: Failed to parse docker reference %s", imageName) return api.AuthConfig{} } if ref.Registry != "" { if auth, ok := auths.Configs[ref.Registry]; ok { glog.V(5).Infof("Using %s[%s] credentials for pulling %s", auth.Email, ref.Registry, imageName) return auth } } if auth, ok := auths.Configs[defaultRegistry]; ok { glog.V(5).Infof("Using %s credentials for pulling %s", auth.Email, imageName) return auth } return api.AuthConfig{} }
[ "func", "GetImageRegistryAuth", "(", "auths", "*", "AuthConfigurations", ",", "imageName", "string", ")", "api", ".", "AuthConfig", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "imageName", ")", "\n", "if", "auths", "==", "nil", "{", "return", "api", ".", "AuthConfig", "{", "}", "\n", "}", "\n", "ref", ",", "err", ":=", "parseNamedDockerImageReference", "(", "imageName", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "0", ")", ".", "Infof", "(", "\"", "\"", ",", "imageName", ")", "\n", "return", "api", ".", "AuthConfig", "{", "}", "\n", "}", "\n", "if", "ref", ".", "Registry", "!=", "\"", "\"", "{", "if", "auth", ",", "ok", ":=", "auths", ".", "Configs", "[", "ref", ".", "Registry", "]", ";", "ok", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "auth", ".", "Email", ",", "ref", ".", "Registry", ",", "imageName", ")", "\n", "return", "auth", "\n", "}", "\n", "}", "\n", "if", "auth", ",", "ok", ":=", "auths", ".", "Configs", "[", "defaultRegistry", "]", ";", "ok", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "auth", ".", "Email", ",", "imageName", ")", "\n", "return", "auth", "\n", "}", "\n", "return", "api", ".", "AuthConfig", "{", "}", "\n", "}" ]
// GetImageRegistryAuth retrieves the appropriate docker client authentication // object for a given image name and a given set of client authentication // objects.
[ "GetImageRegistryAuth", "retrieves", "the", "appropriate", "docker", "client", "authentication", "object", "for", "a", "given", "image", "name", "and", "a", "given", "set", "of", "client", "authentication", "objects", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L57-L78
train
openshift/source-to-image
pkg/docker/util.go
parseNamedDockerImageReference
func parseNamedDockerImageReference(spec string) (namedDockerImageReference, error) { var ref namedDockerImageReference namedRef, err := reference.ParseNormalizedNamed(spec) if err != nil { return ref, err } name := namedRef.Name() i := strings.IndexRune(name, '/') if i == -1 || (!strings.ContainsAny(name[:i], ":.") && name[:i] != "localhost") { ref.Name = name } else { ref.Registry, ref.Name = name[:i], name[i+1:] } if named, ok := namedRef.(reference.NamedTagged); ok { ref.Tag = named.Tag() } if named, ok := namedRef.(reference.Canonical); ok { ref.ID = named.Digest().String() } // It's not enough just to use the reference.ParseNamed(). We have to fill // ref.Namespace from ref.Name if i := strings.IndexRune(ref.Name, '/'); i != -1 { ref.Namespace, ref.Name = ref.Name[:i], ref.Name[i+1:] } return ref, nil }
go
func parseNamedDockerImageReference(spec string) (namedDockerImageReference, error) { var ref namedDockerImageReference namedRef, err := reference.ParseNormalizedNamed(spec) if err != nil { return ref, err } name := namedRef.Name() i := strings.IndexRune(name, '/') if i == -1 || (!strings.ContainsAny(name[:i], ":.") && name[:i] != "localhost") { ref.Name = name } else { ref.Registry, ref.Name = name[:i], name[i+1:] } if named, ok := namedRef.(reference.NamedTagged); ok { ref.Tag = named.Tag() } if named, ok := namedRef.(reference.Canonical); ok { ref.ID = named.Digest().String() } // It's not enough just to use the reference.ParseNamed(). We have to fill // ref.Namespace from ref.Name if i := strings.IndexRune(ref.Name, '/'); i != -1 { ref.Namespace, ref.Name = ref.Name[:i], ref.Name[i+1:] } return ref, nil }
[ "func", "parseNamedDockerImageReference", "(", "spec", "string", ")", "(", "namedDockerImageReference", ",", "error", ")", "{", "var", "ref", "namedDockerImageReference", "\n\n", "namedRef", ",", "err", ":=", "reference", ".", "ParseNormalizedNamed", "(", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ref", ",", "err", "\n", "}", "\n\n", "name", ":=", "namedRef", ".", "Name", "(", ")", "\n", "i", ":=", "strings", ".", "IndexRune", "(", "name", ",", "'/'", ")", "\n", "if", "i", "==", "-", "1", "||", "(", "!", "strings", ".", "ContainsAny", "(", "name", "[", ":", "i", "]", ",", "\"", "\"", ")", "&&", "name", "[", ":", "i", "]", "!=", "\"", "\"", ")", "{", "ref", ".", "Name", "=", "name", "\n", "}", "else", "{", "ref", ".", "Registry", ",", "ref", ".", "Name", "=", "name", "[", ":", "i", "]", ",", "name", "[", "i", "+", "1", ":", "]", "\n", "}", "\n\n", "if", "named", ",", "ok", ":=", "namedRef", ".", "(", "reference", ".", "NamedTagged", ")", ";", "ok", "{", "ref", ".", "Tag", "=", "named", ".", "Tag", "(", ")", "\n", "}", "\n\n", "if", "named", ",", "ok", ":=", "namedRef", ".", "(", "reference", ".", "Canonical", ")", ";", "ok", "{", "ref", ".", "ID", "=", "named", ".", "Digest", "(", ")", ".", "String", "(", ")", "\n", "}", "\n\n", "// It's not enough just to use the reference.ParseNamed(). We have to fill", "// ref.Namespace from ref.Name", "if", "i", ":=", "strings", ".", "IndexRune", "(", "ref", ".", "Name", ",", "'/'", ")", ";", "i", "!=", "-", "1", "{", "ref", ".", "Namespace", ",", "ref", ".", "Name", "=", "ref", ".", "Name", "[", ":", "i", "]", ",", "ref", ".", "Name", "[", "i", "+", "1", ":", "]", "\n", "}", "\n\n", "return", "ref", ",", "nil", "\n", "}" ]
// parseNamedDockerImageReference parses a Docker pull spec string into a // NamedDockerImageReference.
[ "parseNamedDockerImageReference", "parses", "a", "Docker", "pull", "spec", "string", "into", "a", "NamedDockerImageReference", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L91-L122
train
openshift/source-to-image
pkg/docker/util.go
LoadImageRegistryAuth
func LoadImageRegistryAuth(dockerCfg io.Reader) *AuthConfigurations { auths, err := NewAuthConfigurations(dockerCfg) if err != nil { glog.V(0).Infof("error: Unable to load docker config: %v", err) return nil } return auths }
go
func LoadImageRegistryAuth(dockerCfg io.Reader) *AuthConfigurations { auths, err := NewAuthConfigurations(dockerCfg) if err != nil { glog.V(0).Infof("error: Unable to load docker config: %v", err) return nil } return auths }
[ "func", "LoadImageRegistryAuth", "(", "dockerCfg", "io", ".", "Reader", ")", "*", "AuthConfigurations", "{", "auths", ",", "err", ":=", "NewAuthConfigurations", "(", "dockerCfg", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "0", ")", ".", "Infof", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "auths", "\n", "}" ]
// LoadImageRegistryAuth loads and returns the set of client auth objects from // a docker config json file.
[ "LoadImageRegistryAuth", "loads", "and", "returns", "the", "set", "of", "client", "auth", "objects", "from", "a", "docker", "config", "json", "file", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L126-L133
train
openshift/source-to-image
pkg/docker/util.go
NewAuthConfigurations
func NewAuthConfigurations(r io.Reader) (*AuthConfigurations, error) { var auth *AuthConfigurations confs, err := parseDockerConfig(r) if err != nil { return nil, err } auth, err = authConfigs(confs) if err != nil { return nil, err } return auth, nil }
go
func NewAuthConfigurations(r io.Reader) (*AuthConfigurations, error) { var auth *AuthConfigurations confs, err := parseDockerConfig(r) if err != nil { return nil, err } auth, err = authConfigs(confs) if err != nil { return nil, err } return auth, nil }
[ "func", "NewAuthConfigurations", "(", "r", "io", ".", "Reader", ")", "(", "*", "AuthConfigurations", ",", "error", ")", "{", "var", "auth", "*", "AuthConfigurations", "\n", "confs", ",", "err", ":=", "parseDockerConfig", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "auth", ",", "err", "=", "authConfigs", "(", "confs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "auth", ",", "nil", "\n", "}" ]
// begin next 3 methods borrowed from go-dockerclient // NewAuthConfigurations finishes creating the auth config array s2i pulls from // any auth config file it is pointed to when started from the command line
[ "begin", "next", "3", "methods", "borrowed", "from", "go", "-", "dockerclient", "NewAuthConfigurations", "finishes", "creating", "the", "auth", "config", "array", "s2i", "pulls", "from", "any", "auth", "config", "file", "it", "is", "pointed", "to", "when", "started", "from", "the", "command", "line" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L139-L150
train
openshift/source-to-image
pkg/docker/util.go
parseDockerConfig
func parseDockerConfig(r io.Reader) (map[string]dockerConfig, error) { buf := new(bytes.Buffer) buf.ReadFrom(r) byteData := buf.Bytes() confsWrapper := struct { Auths map[string]dockerConfig `json:"auths"` }{} if err := json.Unmarshal(byteData, &confsWrapper); err == nil { if len(confsWrapper.Auths) > 0 { return confsWrapper.Auths, nil } } var confs map[string]dockerConfig if err := json.Unmarshal(byteData, &confs); err != nil { return nil, err } return confs, nil }
go
func parseDockerConfig(r io.Reader) (map[string]dockerConfig, error) { buf := new(bytes.Buffer) buf.ReadFrom(r) byteData := buf.Bytes() confsWrapper := struct { Auths map[string]dockerConfig `json:"auths"` }{} if err := json.Unmarshal(byteData, &confsWrapper); err == nil { if len(confsWrapper.Auths) > 0 { return confsWrapper.Auths, nil } } var confs map[string]dockerConfig if err := json.Unmarshal(byteData, &confs); err != nil { return nil, err } return confs, nil }
[ "func", "parseDockerConfig", "(", "r", "io", ".", "Reader", ")", "(", "map", "[", "string", "]", "dockerConfig", ",", "error", ")", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "buf", ".", "ReadFrom", "(", "r", ")", "\n", "byteData", ":=", "buf", ".", "Bytes", "(", ")", "\n\n", "confsWrapper", ":=", "struct", "{", "Auths", "map", "[", "string", "]", "dockerConfig", "`json:\"auths\"`", "\n", "}", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "byteData", ",", "&", "confsWrapper", ")", ";", "err", "==", "nil", "{", "if", "len", "(", "confsWrapper", ".", "Auths", ")", ">", "0", "{", "return", "confsWrapper", ".", "Auths", ",", "nil", "\n", "}", "\n", "}", "\n\n", "var", "confs", "map", "[", "string", "]", "dockerConfig", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "byteData", ",", "&", "confs", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "confs", ",", "nil", "\n", "}" ]
// parseDockerConfig does the json unmarshalling of the data we read from the // file
[ "parseDockerConfig", "does", "the", "json", "unmarshalling", "of", "the", "data", "we", "read", "from", "the", "file" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L154-L173
train
openshift/source-to-image
pkg/docker/util.go
PullImage
func PullImage(name string, d Docker, policy api.PullPolicy) (*PullResult, error) { if len(policy) == 0 { return nil, errors.New("the policy for pull image must be set") } var ( image *api.Image err error ) switch policy { case api.PullIfNotPresent: image, err = d.CheckAndPullImage(name) case api.PullAlways: glog.Infof("Pulling image %q ...", name) image, err = d.PullImage(name) case api.PullNever: glog.Infof("Checking if image %q is available locally ...", name) image, err = d.CheckImage(name) } return &PullResult{Image: image, OnBuild: d.IsImageOnBuild(name)}, err }
go
func PullImage(name string, d Docker, policy api.PullPolicy) (*PullResult, error) { if len(policy) == 0 { return nil, errors.New("the policy for pull image must be set") } var ( image *api.Image err error ) switch policy { case api.PullIfNotPresent: image, err = d.CheckAndPullImage(name) case api.PullAlways: glog.Infof("Pulling image %q ...", name) image, err = d.PullImage(name) case api.PullNever: glog.Infof("Checking if image %q is available locally ...", name) image, err = d.CheckImage(name) } return &PullResult{Image: image, OnBuild: d.IsImageOnBuild(name)}, err }
[ "func", "PullImage", "(", "name", "string", ",", "d", "Docker", ",", "policy", "api", ".", "PullPolicy", ")", "(", "*", "PullResult", ",", "error", ")", "{", "if", "len", "(", "policy", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "(", "image", "*", "api", ".", "Image", "\n", "err", "error", "\n", ")", "\n", "switch", "policy", "{", "case", "api", ".", "PullIfNotPresent", ":", "image", ",", "err", "=", "d", ".", "CheckAndPullImage", "(", "name", ")", "\n", "case", "api", ".", "PullAlways", ":", "glog", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "image", ",", "err", "=", "d", ".", "PullImage", "(", "name", ")", "\n", "case", "api", ".", "PullNever", ":", "glog", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "image", ",", "err", "=", "d", ".", "CheckImage", "(", "name", ")", "\n", "}", "\n", "return", "&", "PullResult", "{", "Image", ":", "image", ",", "OnBuild", ":", "d", ".", "IsImageOnBuild", "(", "name", ")", "}", ",", "err", "\n", "}" ]
// PullImage pulls the Docker image specified by name taking the pull policy // into the account.
[ "PullImage", "pulls", "the", "Docker", "image", "specified", "by", "name", "taking", "the", "pull", "policy", "into", "the", "account", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L254-L274
train
openshift/source-to-image
pkg/docker/util.go
extractOnBuildUsers
func extractOnBuildUsers(d Docker, imageName string) ([]string, error) { cmds, err := d.GetOnBuild(imageName) var users []string if err != nil { return users, err } for _, line := range cmds { parts := dockerLineDelim.Split(line, 2) if strings.ToLower(parts[0]) != "user" { continue } users = append(users, extractUser(parts[1])) } return users, nil }
go
func extractOnBuildUsers(d Docker, imageName string) ([]string, error) { cmds, err := d.GetOnBuild(imageName) var users []string if err != nil { return users, err } for _, line := range cmds { parts := dockerLineDelim.Split(line, 2) if strings.ToLower(parts[0]) != "user" { continue } users = append(users, extractUser(parts[1])) } return users, nil }
[ "func", "extractOnBuildUsers", "(", "d", "Docker", ",", "imageName", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "cmds", ",", "err", ":=", "d", ".", "GetOnBuild", "(", "imageName", ")", "\n", "var", "users", "[", "]", "string", "\n", "if", "err", "!=", "nil", "{", "return", "users", ",", "err", "\n", "}", "\n", "for", "_", ",", "line", ":=", "range", "cmds", "{", "parts", ":=", "dockerLineDelim", ".", "Split", "(", "line", ",", "2", ")", "\n", "if", "strings", ".", "ToLower", "(", "parts", "[", "0", "]", ")", "!=", "\"", "\"", "{", "continue", "\n", "}", "\n", "users", "=", "append", "(", "users", ",", "extractUser", "(", "parts", "[", "1", "]", ")", ")", "\n", "}", "\n", "return", "users", ",", "nil", "\n", "}" ]
// extractOnBuildUsers checks a list of Docker ONBUILD instructions for user // directives. It returns a list of users specified in the ONBUILD directives.
[ "extractOnBuildUsers", "checks", "a", "list", "of", "Docker", "ONBUILD", "instructions", "for", "user", "directives", ".", "It", "returns", "a", "list", "of", "users", "specified", "in", "the", "ONBUILD", "directives", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L361-L375
train
openshift/source-to-image
pkg/docker/util.go
GetBuilderImage
func GetBuilderImage(docker Docker, config *api.Config) (*PullResult, error) { return pullAndCheck(config.BuilderImage, docker, config.BuilderPullPolicy, config) }
go
func GetBuilderImage(docker Docker, config *api.Config) (*PullResult, error) { return pullAndCheck(config.BuilderImage, docker, config.BuilderPullPolicy, config) }
[ "func", "GetBuilderImage", "(", "docker", "Docker", ",", "config", "*", "api", ".", "Config", ")", "(", "*", "PullResult", ",", "error", ")", "{", "return", "pullAndCheck", "(", "config", ".", "BuilderImage", ",", "docker", ",", "config", ".", "BuilderPullPolicy", ",", "config", ")", "\n", "}" ]
// GetBuilderImage processes the config and performs operations necessary to // make the Docker image specified as BuilderImage available locally. It // returns information about the base image, containing metadata necessary for // choosing the right STI build strategy.
[ "GetBuilderImage", "processes", "the", "config", "and", "performs", "operations", "necessary", "to", "make", "the", "Docker", "image", "specified", "as", "BuilderImage", "available", "locally", ".", "It", "returns", "information", "about", "the", "base", "image", "containing", "metadata", "necessary", "for", "choosing", "the", "right", "STI", "build", "strategy", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L401-L403
train
openshift/source-to-image
pkg/docker/util.go
GetRebuildImage
func GetRebuildImage(docker Docker, config *api.Config) (*PullResult, error) { return pullAndCheck(config.Tag, docker, config.BuilderPullPolicy, config) }
go
func GetRebuildImage(docker Docker, config *api.Config) (*PullResult, error) { return pullAndCheck(config.Tag, docker, config.BuilderPullPolicy, config) }
[ "func", "GetRebuildImage", "(", "docker", "Docker", ",", "config", "*", "api", ".", "Config", ")", "(", "*", "PullResult", ",", "error", ")", "{", "return", "pullAndCheck", "(", "config", ".", "Tag", ",", "docker", ",", "config", ".", "BuilderPullPolicy", ",", "config", ")", "\n", "}" ]
// GetRebuildImage obtains the metadata information for the image specified in // a s2i rebuild operation. Assumptions are made that the build is available // locally since it should have been previously built.
[ "GetRebuildImage", "obtains", "the", "metadata", "information", "for", "the", "image", "specified", "in", "a", "s2i", "rebuild", "operation", ".", "Assumptions", "are", "made", "that", "the", "build", "is", "available", "locally", "since", "it", "should", "have", "been", "previously", "built", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L408-L410
train
openshift/source-to-image
pkg/docker/util.go
GetRuntimeImage
func GetRuntimeImage(docker Docker, config *api.Config) error { _, err := pullAndCheck(config.RuntimeImage, docker, config.RuntimeImagePullPolicy, config) return err }
go
func GetRuntimeImage(docker Docker, config *api.Config) error { _, err := pullAndCheck(config.RuntimeImage, docker, config.RuntimeImagePullPolicy, config) return err }
[ "func", "GetRuntimeImage", "(", "docker", "Docker", ",", "config", "*", "api", ".", "Config", ")", "error", "{", "_", ",", "err", ":=", "pullAndCheck", "(", "config", ".", "RuntimeImage", ",", "docker", ",", "config", ".", "RuntimeImagePullPolicy", ",", "config", ")", "\n", "return", "err", "\n", "}" ]
// GetRuntimeImage processes the config and performs operations necessary to // make the Docker image specified as RuntimeImage available locally.
[ "GetRuntimeImage", "processes", "the", "config", "and", "performs", "operations", "necessary", "to", "make", "the", "Docker", "image", "specified", "as", "RuntimeImage", "available", "locally", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L414-L417
train
openshift/source-to-image
pkg/docker/util.go
GetDefaultDockerConfig
func GetDefaultDockerConfig() *api.DockerConfig { cfg := &api.DockerConfig{} if cfg.Endpoint = os.Getenv("DOCKER_HOST"); cfg.Endpoint == "" { cfg.Endpoint = client.DefaultDockerHost } certPath := os.Getenv("DOCKER_CERT_PATH") if certPath == "" { certPath = cliconfig.Dir() } cfg.CertFile = filepath.Join(certPath, "cert.pem") cfg.KeyFile = filepath.Join(certPath, "key.pem") cfg.CAFile = filepath.Join(certPath, "ca.pem") if tlsVerify := os.Getenv("DOCKER_TLS_VERIFY"); tlsVerify != "" { cfg.TLSVerify = true } return cfg }
go
func GetDefaultDockerConfig() *api.DockerConfig { cfg := &api.DockerConfig{} if cfg.Endpoint = os.Getenv("DOCKER_HOST"); cfg.Endpoint == "" { cfg.Endpoint = client.DefaultDockerHost } certPath := os.Getenv("DOCKER_CERT_PATH") if certPath == "" { certPath = cliconfig.Dir() } cfg.CertFile = filepath.Join(certPath, "cert.pem") cfg.KeyFile = filepath.Join(certPath, "key.pem") cfg.CAFile = filepath.Join(certPath, "ca.pem") if tlsVerify := os.Getenv("DOCKER_TLS_VERIFY"); tlsVerify != "" { cfg.TLSVerify = true } return cfg }
[ "func", "GetDefaultDockerConfig", "(", ")", "*", "api", ".", "DockerConfig", "{", "cfg", ":=", "&", "api", ".", "DockerConfig", "{", "}", "\n\n", "if", "cfg", ".", "Endpoint", "=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "cfg", ".", "Endpoint", "==", "\"", "\"", "{", "cfg", ".", "Endpoint", "=", "client", ".", "DefaultDockerHost", "\n", "}", "\n\n", "certPath", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "certPath", "==", "\"", "\"", "{", "certPath", "=", "cliconfig", ".", "Dir", "(", ")", "\n", "}", "\n\n", "cfg", ".", "CertFile", "=", "filepath", ".", "Join", "(", "certPath", ",", "\"", "\"", ")", "\n", "cfg", ".", "KeyFile", "=", "filepath", ".", "Join", "(", "certPath", ",", "\"", "\"", ")", "\n", "cfg", ".", "CAFile", "=", "filepath", ".", "Join", "(", "certPath", ",", "\"", "\"", ")", "\n\n", "if", "tlsVerify", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "tlsVerify", "!=", "\"", "\"", "{", "cfg", ".", "TLSVerify", "=", "true", "\n", "}", "\n\n", "return", "cfg", "\n", "}" ]
// GetDefaultDockerConfig checks relevant Docker environment variables to // provide defaults for our command line flags
[ "GetDefaultDockerConfig", "checks", "relevant", "Docker", "environment", "variables", "to", "provide", "defaults", "for", "our", "command", "line", "flags" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/util.go#L421-L442
train
openshift/source-to-image
pkg/util/user/range.go
NewRange
func NewRange(from int, to int) (*Range, error) { return (&rangeBuilder{}).from(from, nil).to(to, nil).Range() }
go
func NewRange(from int, to int) (*Range, error) { return (&rangeBuilder{}).from(from, nil).to(to, nil).Range() }
[ "func", "NewRange", "(", "from", "int", ",", "to", "int", ")", "(", "*", "Range", ",", "error", ")", "{", "return", "(", "&", "rangeBuilder", "{", "}", ")", ".", "from", "(", "from", ",", "nil", ")", ".", "to", "(", "to", ",", "nil", ")", ".", "Range", "(", ")", "\n", "}" ]
// NewRange creates a new range with lower and upper bound
[ "NewRange", "creates", "a", "new", "range", "with", "lower", "and", "upper", "bound" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L36-L38
train
openshift/source-to-image
pkg/util/user/range.go
NewRangeTo
func NewRangeTo(to int) (*Range, error) { return (&rangeBuilder{}).to(to, nil).Range() }
go
func NewRangeTo(to int) (*Range, error) { return (&rangeBuilder{}).to(to, nil).Range() }
[ "func", "NewRangeTo", "(", "to", "int", ")", "(", "*", "Range", ",", "error", ")", "{", "return", "(", "&", "rangeBuilder", "{", "}", ")", ".", "to", "(", "to", ",", "nil", ")", ".", "Range", "(", ")", "\n", "}" ]
// NewRangeTo creates a new range with only the upper bound
[ "NewRangeTo", "creates", "a", "new", "range", "with", "only", "the", "upper", "bound" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L41-L43
train
openshift/source-to-image
pkg/util/user/range.go
NewRangeFrom
func NewRangeFrom(from int) (*Range, error) { return (&rangeBuilder{}).from(from, nil).Range() }
go
func NewRangeFrom(from int) (*Range, error) { return (&rangeBuilder{}).from(from, nil).Range() }
[ "func", "NewRangeFrom", "(", "from", "int", ")", "(", "*", "Range", ",", "error", ")", "{", "return", "(", "&", "rangeBuilder", "{", "}", ")", ".", "from", "(", "from", ",", "nil", ")", ".", "Range", "(", ")", "\n", "}" ]
// NewRangeFrom creates a new range with only the lower bound
[ "NewRangeFrom", "creates", "a", "new", "range", "with", "only", "the", "lower", "bound" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L46-L48
train
openshift/source-to-image
pkg/util/user/range.go
Range
func (b *rangeBuilder) Range() (*Range, error) { if b.err != nil { return nil, b.err } if b.r.from != nil && b.r.to != nil && *b.r.to < *b.r.from { return nil, ErrInvalidRange } return &b.r, nil }
go
func (b *rangeBuilder) Range() (*Range, error) { if b.err != nil { return nil, b.err } if b.r.from != nil && b.r.to != nil && *b.r.to < *b.r.from { return nil, ErrInvalidRange } return &b.r, nil }
[ "func", "(", "b", "*", "rangeBuilder", ")", "Range", "(", ")", "(", "*", "Range", ",", "error", ")", "{", "if", "b", ".", "err", "!=", "nil", "{", "return", "nil", ",", "b", ".", "err", "\n", "}", "\n", "if", "b", ".", "r", ".", "from", "!=", "nil", "&&", "b", ".", "r", ".", "to", "!=", "nil", "&&", "*", "b", ".", "r", ".", "to", "<", "*", "b", ".", "r", ".", "from", "{", "return", "nil", ",", "ErrInvalidRange", "\n", "}", "\n", "return", "&", "b", ".", "r", ",", "nil", "\n", "}" ]
// Range returns the completed Range from the rangeBuilder.
[ "Range", "returns", "the", "completed", "Range", "from", "the", "rangeBuilder", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L87-L95
train
openshift/source-to-image
pkg/util/user/range.go
ParseRange
func ParseRange(value string) (*Range, error) { value = strings.TrimSpace(value) b := &rangeBuilder{} if value == "" { return b.Range() } parts := strings.Split(value, "-") switch len(parts) { case 1: num, err := parseInt(parts[0]) return b.from(num, err).to(num, err).Range() case 2: if parts[0] != "" { b.from(parseInt(parts[0])) } if parts[1] != "" { b.to(parseInt(parts[1])) } return b.Range() default: return nil, &ErrParseRange{} } }
go
func ParseRange(value string) (*Range, error) { value = strings.TrimSpace(value) b := &rangeBuilder{} if value == "" { return b.Range() } parts := strings.Split(value, "-") switch len(parts) { case 1: num, err := parseInt(parts[0]) return b.from(num, err).to(num, err).Range() case 2: if parts[0] != "" { b.from(parseInt(parts[0])) } if parts[1] != "" { b.to(parseInt(parts[1])) } return b.Range() default: return nil, &ErrParseRange{} } }
[ "func", "ParseRange", "(", "value", "string", ")", "(", "*", "Range", ",", "error", ")", "{", "value", "=", "strings", ".", "TrimSpace", "(", "value", ")", "\n", "b", ":=", "&", "rangeBuilder", "{", "}", "\n", "if", "value", "==", "\"", "\"", "{", "return", "b", ".", "Range", "(", ")", "\n", "}", "\n", "parts", ":=", "strings", ".", "Split", "(", "value", ",", "\"", "\"", ")", "\n", "switch", "len", "(", "parts", ")", "{", "case", "1", ":", "num", ",", "err", ":=", "parseInt", "(", "parts", "[", "0", "]", ")", "\n", "return", "b", ".", "from", "(", "num", ",", "err", ")", ".", "to", "(", "num", ",", "err", ")", ".", "Range", "(", ")", "\n", "case", "2", ":", "if", "parts", "[", "0", "]", "!=", "\"", "\"", "{", "b", ".", "from", "(", "parseInt", "(", "parts", "[", "0", "]", ")", ")", "\n", "}", "\n", "if", "parts", "[", "1", "]", "!=", "\"", "\"", "{", "b", ".", "to", "(", "parseInt", "(", "parts", "[", "1", "]", ")", ")", "\n", "}", "\n", "return", "b", ".", "Range", "(", ")", "\n", "default", ":", "return", "nil", ",", "&", "ErrParseRange", "{", "}", "\n", "}", "\n", "}" ]
// ParseRange creates a Range from a given string
[ "ParseRange", "creates", "a", "Range", "from", "a", "given", "string" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L98-L120
train
openshift/source-to-image
pkg/util/user/range.go
Contains
func (r *Range) Contains(value int) bool { if r.from == nil && r.to == nil { return false } if r.from != nil && value < *r.from { return false } if r.to != nil && value > *r.to { return false } return true }
go
func (r *Range) Contains(value int) bool { if r.from == nil && r.to == nil { return false } if r.from != nil && value < *r.from { return false } if r.to != nil && value > *r.to { return false } return true }
[ "func", "(", "r", "*", "Range", ")", "Contains", "(", "value", "int", ")", "bool", "{", "if", "r", ".", "from", "==", "nil", "&&", "r", ".", "to", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "from", "!=", "nil", "&&", "value", "<", "*", "r", ".", "from", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "to", "!=", "nil", "&&", "value", ">", "*", "r", ".", "to", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Contains returns true if the argument falls inside the Range
[ "Contains", "returns", "true", "if", "the", "argument", "falls", "inside", "the", "Range" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L123-L134
train
openshift/source-to-image
pkg/util/user/range.go
String
func (r *Range) String() string { switch { case r.from == nil && r.to == nil: return "" case r.from == nil: return fmt.Sprintf("-%d", *r.to) case r.to == nil: return fmt.Sprintf("%d-", *r.from) case *r.from == *r.to: return fmt.Sprintf("%d", *r.to) default: return fmt.Sprintf("%d-%d", *r.from, *r.to) } }
go
func (r *Range) String() string { switch { case r.from == nil && r.to == nil: return "" case r.from == nil: return fmt.Sprintf("-%d", *r.to) case r.to == nil: return fmt.Sprintf("%d-", *r.from) case *r.from == *r.to: return fmt.Sprintf("%d", *r.to) default: return fmt.Sprintf("%d-%d", *r.from, *r.to) } }
[ "func", "(", "r", "*", "Range", ")", "String", "(", ")", "string", "{", "switch", "{", "case", "r", ".", "from", "==", "nil", "&&", "r", ".", "to", "==", "nil", ":", "return", "\"", "\"", "\n", "case", "r", ".", "from", "==", "nil", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "r", ".", "to", ")", "\n", "case", "r", ".", "to", "==", "nil", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "r", ".", "from", ")", "\n", "case", "*", "r", ".", "from", "==", "*", "r", ".", "to", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "r", ".", "to", ")", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "r", ".", "from", ",", "*", "r", ".", "to", ")", "\n", "}", "\n", "}" ]
// String returns a parse-able string representation of a Range
[ "String", "returns", "a", "parse", "-", "able", "string", "representation", "of", "a", "Range" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L137-L150
train
openshift/source-to-image
pkg/util/user/range.go
Set
func (r *Range) Set(value string) error { newRange, err := ParseRange(value) if err != nil { return err } *r = *newRange return nil }
go
func (r *Range) Set(value string) error { newRange, err := ParseRange(value) if err != nil { return err } *r = *newRange return nil }
[ "func", "(", "r", "*", "Range", ")", "Set", "(", "value", "string", ")", "error", "{", "newRange", ",", "err", ":=", "ParseRange", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "r", "=", "*", "newRange", "\n", "return", "nil", "\n", "}" ]
// Set sets the value of a Range object
[ "Set", "sets", "the", "value", "of", "a", "Range", "object" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L158-L165
train
openshift/source-to-image
pkg/util/user/range.go
Empty
func (r *Range) Empty() bool { return r.from == nil && r.to == nil }
go
func (r *Range) Empty() bool { return r.from == nil && r.to == nil }
[ "func", "(", "r", "*", "Range", ")", "Empty", "(", ")", "bool", "{", "return", "r", ".", "from", "==", "nil", "&&", "r", ".", "to", "==", "nil", "\n", "}" ]
// Empty returns true if the range has no bounds
[ "Empty", "returns", "true", "if", "the", "range", "has", "no", "bounds" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/user/range.go#L168-L170
train
openshift/source-to-image
pkg/util/timeout.go
Error
func (t *TimeoutError) Error() string { if len(t.message) > 0 { return fmt.Sprintf("%s timed out after %v", t.message, t.after) } return fmt.Sprintf("function timed out after %v", t.after) }
go
func (t *TimeoutError) Error() string { if len(t.message) > 0 { return fmt.Sprintf("%s timed out after %v", t.message, t.after) } return fmt.Sprintf("function timed out after %v", t.after) }
[ "func", "(", "t", "*", "TimeoutError", ")", "Error", "(", ")", "string", "{", "if", "len", "(", "t", ".", "message", ")", ">", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "message", ",", "t", ".", "after", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "after", ")", "\n", "}" ]
// Error implements the Go error interface.
[ "Error", "implements", "the", "Go", "error", "interface", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/timeout.go#L15-L20
train
openshift/source-to-image
pkg/config/config.go
Save
func Save(config *api.Config, cmd *cobra.Command) { c := Config{ BuilderImage: config.BuilderImage, Source: config.Source.String(), Tag: config.Tag, Flags: make(map[string]string), } cmd.Flags().Visit(func(f *pflag.Flag) { if f.Name == "env" { for i, env := range config.Environment { c.Flags[fmt.Sprintf("%s-%d", f.Name, i)] = fmt.Sprintf("%s=%s", env.Name, env.Value) } } else { c.Flags[f.Name] = f.Value.String() } }) data, err := json.Marshal(c) if err != nil { glog.V(1).Infof("Unable to serialize to %s: %v", DefaultConfigPath, err) return } if err := ioutil.WriteFile(DefaultConfigPath, data, 0644); err != nil { glog.V(1).Infof("Unable to save %s: %v", DefaultConfigPath, err) } return }
go
func Save(config *api.Config, cmd *cobra.Command) { c := Config{ BuilderImage: config.BuilderImage, Source: config.Source.String(), Tag: config.Tag, Flags: make(map[string]string), } cmd.Flags().Visit(func(f *pflag.Flag) { if f.Name == "env" { for i, env := range config.Environment { c.Flags[fmt.Sprintf("%s-%d", f.Name, i)] = fmt.Sprintf("%s=%s", env.Name, env.Value) } } else { c.Flags[f.Name] = f.Value.String() } }) data, err := json.Marshal(c) if err != nil { glog.V(1).Infof("Unable to serialize to %s: %v", DefaultConfigPath, err) return } if err := ioutil.WriteFile(DefaultConfigPath, data, 0644); err != nil { glog.V(1).Infof("Unable to save %s: %v", DefaultConfigPath, err) } return }
[ "func", "Save", "(", "config", "*", "api", ".", "Config", ",", "cmd", "*", "cobra", ".", "Command", ")", "{", "c", ":=", "Config", "{", "BuilderImage", ":", "config", ".", "BuilderImage", ",", "Source", ":", "config", ".", "Source", ".", "String", "(", ")", ",", "Tag", ":", "config", ".", "Tag", ",", "Flags", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "}", "\n", "cmd", ".", "Flags", "(", ")", ".", "Visit", "(", "func", "(", "f", "*", "pflag", ".", "Flag", ")", "{", "if", "f", ".", "Name", "==", "\"", "\"", "{", "for", "i", ",", "env", ":=", "range", "config", ".", "Environment", "{", "c", ".", "Flags", "[", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "Name", ",", "i", ")", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "env", ".", "Name", ",", "env", ".", "Value", ")", "\n", "}", "\n", "}", "else", "{", "c", ".", "Flags", "[", "f", ".", "Name", "]", "=", "f", ".", "Value", ".", "String", "(", ")", "\n", "}", "\n", "}", ")", "\n", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "DefaultConfigPath", ",", "err", ")", "\n", "return", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "DefaultConfigPath", ",", "data", ",", "0644", ")", ";", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "DefaultConfigPath", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Save persists the S2I command line arguments to disk.
[ "Save", "persists", "the", "S2I", "command", "line", "arguments", "to", "disk", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/config/config.go#L32-L57
train
openshift/source-to-image
pkg/config/config.go
Restore
func Restore(config *api.Config, cmd *cobra.Command) { data, err := ioutil.ReadFile(DefaultConfigPath) if err != nil { data, err = ioutil.ReadFile(".stifile") if err != nil { glog.V(1).Infof("Unable to restore %s: %v", DefaultConfigPath, err) return } glog.Infof("DEPRECATED: Use %s instead of .stifile", DefaultConfigPath) } c := Config{} if err := json.Unmarshal(data, &c); err != nil { glog.V(1).Infof("Unable to parse %s: %v", DefaultConfigPath, err) return } source, err := git.Parse(c.Source) if err != nil { glog.V(1).Infof("Unable to parse %s: %v", c.Source, err) return } config.BuilderImage = c.BuilderImage config.Source = source config.Tag = c.Tag envOverride := false if cmd.Flag("env").Changed { envOverride = true } for name, value := range c.Flags { // Do not change flags that user sets. Allow overriding of stored flags. if name == "env" { if envOverride { continue } for _, v := range strings.Split(value, ",") { cmd.Flags().Set(name, v) } } else if savedEnvMatcher.MatchString(name) { if envOverride { continue } cmd.Flags().Set("env", value) } else { if cmd.Flag(name).Changed { continue } cmd.Flags().Set(name, value) } } }
go
func Restore(config *api.Config, cmd *cobra.Command) { data, err := ioutil.ReadFile(DefaultConfigPath) if err != nil { data, err = ioutil.ReadFile(".stifile") if err != nil { glog.V(1).Infof("Unable to restore %s: %v", DefaultConfigPath, err) return } glog.Infof("DEPRECATED: Use %s instead of .stifile", DefaultConfigPath) } c := Config{} if err := json.Unmarshal(data, &c); err != nil { glog.V(1).Infof("Unable to parse %s: %v", DefaultConfigPath, err) return } source, err := git.Parse(c.Source) if err != nil { glog.V(1).Infof("Unable to parse %s: %v", c.Source, err) return } config.BuilderImage = c.BuilderImage config.Source = source config.Tag = c.Tag envOverride := false if cmd.Flag("env").Changed { envOverride = true } for name, value := range c.Flags { // Do not change flags that user sets. Allow overriding of stored flags. if name == "env" { if envOverride { continue } for _, v := range strings.Split(value, ",") { cmd.Flags().Set(name, v) } } else if savedEnvMatcher.MatchString(name) { if envOverride { continue } cmd.Flags().Set("env", value) } else { if cmd.Flag(name).Changed { continue } cmd.Flags().Set(name, value) } } }
[ "func", "Restore", "(", "config", "*", "api", ".", "Config", ",", "cmd", "*", "cobra", ".", "Command", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "DefaultConfigPath", ")", "\n", "if", "err", "!=", "nil", "{", "data", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "DefaultConfigPath", ",", "err", ")", "\n", "return", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"", "\"", ",", "DefaultConfigPath", ")", "\n", "}", "\n\n", "c", ":=", "Config", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "c", ")", ";", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "DefaultConfigPath", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "source", ",", "err", ":=", "git", ".", "Parse", "(", "c", ".", "Source", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "Source", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "config", ".", "BuilderImage", "=", "c", ".", "BuilderImage", "\n", "config", ".", "Source", "=", "source", "\n", "config", ".", "Tag", "=", "c", ".", "Tag", "\n\n", "envOverride", ":=", "false", "\n", "if", "cmd", ".", "Flag", "(", "\"", "\"", ")", ".", "Changed", "{", "envOverride", "=", "true", "\n", "}", "\n\n", "for", "name", ",", "value", ":=", "range", "c", ".", "Flags", "{", "// Do not change flags that user sets. Allow overriding of stored flags.", "if", "name", "==", "\"", "\"", "{", "if", "envOverride", "{", "continue", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "strings", ".", "Split", "(", "value", ",", "\"", "\"", ")", "{", "cmd", ".", "Flags", "(", ")", ".", "Set", "(", "name", ",", "v", ")", "\n", "}", "\n", "}", "else", "if", "savedEnvMatcher", ".", "MatchString", "(", "name", ")", "{", "if", "envOverride", "{", "continue", "\n", "}", "\n", "cmd", ".", "Flags", "(", ")", ".", "Set", "(", "\"", "\"", ",", "value", ")", "\n", "}", "else", "{", "if", "cmd", ".", "Flag", "(", "name", ")", ".", "Changed", "{", "continue", "\n", "}", "\n", "cmd", ".", "Flags", "(", ")", ".", "Set", "(", "name", ",", "value", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Restore loads the arguments from disk and prefills the Request
[ "Restore", "loads", "the", "arguments", "from", "disk", "and", "prefills", "the", "Request" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/config/config.go#L60-L113
train
openshift/source-to-image
pkg/scm/git/url.go
Parse
func Parse(rawurl string) (*URL, error) { if urlSchemeRegexp.MatchString(rawurl) && (runtime.GOOS != "windows" || !dosDriveRegexp.MatchString(rawurl)) { u, err := url.Parse(rawurl) if err != nil { return nil, err } if u.Scheme == "file" && u.Opaque == "" { if u.Host != "" { return nil, fmt.Errorf("file url %q has non-empty host %q", rawurl, u.Host) } if runtime.GOOS == "windows" && (len(u.Path) == 0 || !filepath.IsAbs(u.Path[1:])) { return nil, fmt.Errorf("file url %q has non-absolute path %q", rawurl, u.Path) } } return &URL{ URL: *u, Type: URLTypeURL, }, nil } s, fragment := splitOnByte(rawurl, '#') if m := scpRegexp.FindStringSubmatch(s); m != nil && (runtime.GOOS != "windows" || !dosDriveRegexp.MatchString(s)) { u := &url.URL{ Host: m[2], Path: m[3], Fragment: fragment, } if m[1] != "" { u.User = url.User(m[1]) } return &URL{ URL: *u, Type: URLTypeSCP, }, nil } return &URL{ URL: url.URL{ Path: s, Fragment: fragment, }, Type: URLTypeLocal, }, nil }
go
func Parse(rawurl string) (*URL, error) { if urlSchemeRegexp.MatchString(rawurl) && (runtime.GOOS != "windows" || !dosDriveRegexp.MatchString(rawurl)) { u, err := url.Parse(rawurl) if err != nil { return nil, err } if u.Scheme == "file" && u.Opaque == "" { if u.Host != "" { return nil, fmt.Errorf("file url %q has non-empty host %q", rawurl, u.Host) } if runtime.GOOS == "windows" && (len(u.Path) == 0 || !filepath.IsAbs(u.Path[1:])) { return nil, fmt.Errorf("file url %q has non-absolute path %q", rawurl, u.Path) } } return &URL{ URL: *u, Type: URLTypeURL, }, nil } s, fragment := splitOnByte(rawurl, '#') if m := scpRegexp.FindStringSubmatch(s); m != nil && (runtime.GOOS != "windows" || !dosDriveRegexp.MatchString(s)) { u := &url.URL{ Host: m[2], Path: m[3], Fragment: fragment, } if m[1] != "" { u.User = url.User(m[1]) } return &URL{ URL: *u, Type: URLTypeSCP, }, nil } return &URL{ URL: url.URL{ Path: s, Fragment: fragment, }, Type: URLTypeLocal, }, nil }
[ "func", "Parse", "(", "rawurl", "string", ")", "(", "*", "URL", ",", "error", ")", "{", "if", "urlSchemeRegexp", ".", "MatchString", "(", "rawurl", ")", "&&", "(", "runtime", ".", "GOOS", "!=", "\"", "\"", "||", "!", "dosDriveRegexp", ".", "MatchString", "(", "rawurl", ")", ")", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "rawurl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "u", ".", "Scheme", "==", "\"", "\"", "&&", "u", ".", "Opaque", "==", "\"", "\"", "{", "if", "u", ".", "Host", "!=", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "rawurl", ",", "u", ".", "Host", ")", "\n", "}", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "&&", "(", "len", "(", "u", ".", "Path", ")", "==", "0", "||", "!", "filepath", ".", "IsAbs", "(", "u", ".", "Path", "[", "1", ":", "]", ")", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "rawurl", ",", "u", ".", "Path", ")", "\n", "}", "\n", "}", "\n\n", "return", "&", "URL", "{", "URL", ":", "*", "u", ",", "Type", ":", "URLTypeURL", ",", "}", ",", "nil", "\n", "}", "\n\n", "s", ",", "fragment", ":=", "splitOnByte", "(", "rawurl", ",", "'#'", ")", "\n\n", "if", "m", ":=", "scpRegexp", ".", "FindStringSubmatch", "(", "s", ")", ";", "m", "!=", "nil", "&&", "(", "runtime", ".", "GOOS", "!=", "\"", "\"", "||", "!", "dosDriveRegexp", ".", "MatchString", "(", "s", ")", ")", "{", "u", ":=", "&", "url", ".", "URL", "{", "Host", ":", "m", "[", "2", "]", ",", "Path", ":", "m", "[", "3", "]", ",", "Fragment", ":", "fragment", ",", "}", "\n", "if", "m", "[", "1", "]", "!=", "\"", "\"", "{", "u", ".", "User", "=", "url", ".", "User", "(", "m", "[", "1", "]", ")", "\n", "}", "\n\n", "return", "&", "URL", "{", "URL", ":", "*", "u", ",", "Type", ":", "URLTypeSCP", ",", "}", ",", "nil", "\n", "}", "\n\n", "return", "&", "URL", "{", "URL", ":", "url", ".", "URL", "{", "Path", ":", "s", ",", "Fragment", ":", "fragment", ",", "}", ",", "Type", ":", "URLTypeLocal", ",", "}", ",", "nil", "\n", "}" ]
// Parse parses a "Git URL"
[ "Parse", "parses", "a", "Git", "URL" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/url.go#L87-L135
train
openshift/source-to-image
pkg/scm/git/url.go
MustParse
func MustParse(rawurl string) *URL { u, err := Parse(rawurl) if err != nil { panic(err) } return u }
go
func MustParse(rawurl string) *URL { u, err := Parse(rawurl) if err != nil { panic(err) } return u }
[ "func", "MustParse", "(", "rawurl", "string", ")", "*", "URL", "{", "u", ",", "err", ":=", "Parse", "(", "rawurl", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "u", "\n", "}" ]
// MustParse parses a "Git URL" and panics on failure
[ "MustParse", "parses", "a", "Git", "URL", "and", "panics", "on", "failure" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/url.go#L138-L144
train
openshift/source-to-image
pkg/scm/git/url.go
String
func (u URL) String() string { var s string switch u.Type { case URLTypeURL: return u.URL.String() case URLTypeSCP: if u.URL.User != nil { s = u.URL.User.Username() + "@" } s += u.URL.Host + ":" + u.URL.Path case URLTypeLocal: s = u.URL.Path } if u.URL.RawQuery != "" { s += "?" + u.URL.RawQuery } if u.URL.Fragment != "" { s += "#" + u.URL.Fragment } return s }
go
func (u URL) String() string { var s string switch u.Type { case URLTypeURL: return u.URL.String() case URLTypeSCP: if u.URL.User != nil { s = u.URL.User.Username() + "@" } s += u.URL.Host + ":" + u.URL.Path case URLTypeLocal: s = u.URL.Path } if u.URL.RawQuery != "" { s += "?" + u.URL.RawQuery } if u.URL.Fragment != "" { s += "#" + u.URL.Fragment } return s }
[ "func", "(", "u", "URL", ")", "String", "(", ")", "string", "{", "var", "s", "string", "\n", "switch", "u", ".", "Type", "{", "case", "URLTypeURL", ":", "return", "u", ".", "URL", ".", "String", "(", ")", "\n", "case", "URLTypeSCP", ":", "if", "u", ".", "URL", ".", "User", "!=", "nil", "{", "s", "=", "u", ".", "URL", ".", "User", ".", "Username", "(", ")", "+", "\"", "\"", "\n", "}", "\n", "s", "+=", "u", ".", "URL", ".", "Host", "+", "\"", "\"", "+", "u", ".", "URL", ".", "Path", "\n", "case", "URLTypeLocal", ":", "s", "=", "u", ".", "URL", ".", "Path", "\n", "}", "\n", "if", "u", ".", "URL", ".", "RawQuery", "!=", "\"", "\"", "{", "s", "+=", "\"", "\"", "+", "u", ".", "URL", ".", "RawQuery", "\n", "}", "\n", "if", "u", ".", "URL", ".", "Fragment", "!=", "\"", "\"", "{", "s", "+=", "\"", "\"", "+", "u", ".", "URL", ".", "Fragment", "\n", "}", "\n", "return", "s", "\n", "}" ]
// String returns a string representation of the URL
[ "String", "returns", "a", "string", "representation", "of", "the", "URL" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/url.go#L147-L167
train
openshift/source-to-image
pkg/scm/git/url.go
IsLocal
func (u URL) IsLocal() bool { return u.Type == URLTypeLocal || (u.Type == URLTypeURL && u.URL.Scheme == "file" && u.URL.Opaque == "") }
go
func (u URL) IsLocal() bool { return u.Type == URLTypeLocal || (u.Type == URLTypeURL && u.URL.Scheme == "file" && u.URL.Opaque == "") }
[ "func", "(", "u", "URL", ")", "IsLocal", "(", ")", "bool", "{", "return", "u", ".", "Type", "==", "URLTypeLocal", "||", "(", "u", ".", "Type", "==", "URLTypeURL", "&&", "u", ".", "URL", ".", "Scheme", "==", "\"", "\"", "&&", "u", ".", "URL", ".", "Opaque", "==", "\"", "\"", ")", "\n", "}" ]
// IsLocal returns true if the Git URL refers to a local repository
[ "IsLocal", "returns", "true", "if", "the", "Git", "URL", "refers", "to", "a", "local", "repository" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/scm/git/url.go#L177-L179
train
openshift/source-to-image
pkg/cmd/cli/cmd/rebuild.go
NewCmdRebuild
func NewCmdRebuild(cfg *api.Config) *cobra.Command { buildCmd := &cobra.Command{ Use: "rebuild <image> [<new-tag>]", Short: "Rebuild an existing image", Long: "Rebuild an existing application image that was built by S2I previously.", Run: func(cmd *cobra.Command, args []string) { // If user specifies the arguments, then we override the stored ones if len(args) >= 1 { cfg.Tag = args[0] } else { cmd.Help() return } var auths *docker.AuthConfigurations r, err := os.Open(cfg.DockerCfgPath) if err == nil { defer r.Close() auths = docker.LoadImageRegistryAuth(r) } cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.Tag) if len(cfg.BuilderPullPolicy) == 0 { cfg.BuilderPullPolicy = api.DefaultBuilderPullPolicy } if len(cfg.PreviousImagePullPolicy) == 0 { cfg.PreviousImagePullPolicy = api.DefaultPreviousImagePullPolicy } client, err := docker.NewEngineAPIClient(cfg.DockerConfig) s2ierr.CheckError(err) dkr := docker.New(client, cfg.PullAuthentication) pr, err := docker.GetRebuildImage(dkr, cfg) s2ierr.CheckError(err) err = build.GenerateConfigFromLabels(cfg, pr) s2ierr.CheckError(err) if len(args) >= 2 { cfg.Tag = args[1] } cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.BuilderImage) glog.V(2).Infof("\n%s\n", describe.Config(client, cfg)) builder, _, err := strategies.GetStrategy(client, cfg) s2ierr.CheckError(err) result, err := builder.Build(cfg) s2ierr.CheckError(err) for _, message := range result.Messages { glog.V(1).Infof(message) } }, } cmdutil.AddCommonFlags(buildCmd, cfg) return buildCmd }
go
func NewCmdRebuild(cfg *api.Config) *cobra.Command { buildCmd := &cobra.Command{ Use: "rebuild <image> [<new-tag>]", Short: "Rebuild an existing image", Long: "Rebuild an existing application image that was built by S2I previously.", Run: func(cmd *cobra.Command, args []string) { // If user specifies the arguments, then we override the stored ones if len(args) >= 1 { cfg.Tag = args[0] } else { cmd.Help() return } var auths *docker.AuthConfigurations r, err := os.Open(cfg.DockerCfgPath) if err == nil { defer r.Close() auths = docker.LoadImageRegistryAuth(r) } cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.Tag) if len(cfg.BuilderPullPolicy) == 0 { cfg.BuilderPullPolicy = api.DefaultBuilderPullPolicy } if len(cfg.PreviousImagePullPolicy) == 0 { cfg.PreviousImagePullPolicy = api.DefaultPreviousImagePullPolicy } client, err := docker.NewEngineAPIClient(cfg.DockerConfig) s2ierr.CheckError(err) dkr := docker.New(client, cfg.PullAuthentication) pr, err := docker.GetRebuildImage(dkr, cfg) s2ierr.CheckError(err) err = build.GenerateConfigFromLabels(cfg, pr) s2ierr.CheckError(err) if len(args) >= 2 { cfg.Tag = args[1] } cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.BuilderImage) glog.V(2).Infof("\n%s\n", describe.Config(client, cfg)) builder, _, err := strategies.GetStrategy(client, cfg) s2ierr.CheckError(err) result, err := builder.Build(cfg) s2ierr.CheckError(err) for _, message := range result.Messages { glog.V(1).Infof(message) } }, } cmdutil.AddCommonFlags(buildCmd, cfg) return buildCmd }
[ "func", "NewCmdRebuild", "(", "cfg", "*", "api", ".", "Config", ")", "*", "cobra", ".", "Command", "{", "buildCmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Long", ":", "\"", "\"", ",", "Run", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "// If user specifies the arguments, then we override the stored ones", "if", "len", "(", "args", ")", ">=", "1", "{", "cfg", ".", "Tag", "=", "args", "[", "0", "]", "\n", "}", "else", "{", "cmd", ".", "Help", "(", ")", "\n", "return", "\n", "}", "\n\n", "var", "auths", "*", "docker", ".", "AuthConfigurations", "\n", "r", ",", "err", ":=", "os", ".", "Open", "(", "cfg", ".", "DockerCfgPath", ")", "\n", "if", "err", "==", "nil", "{", "defer", "r", ".", "Close", "(", ")", "\n", "auths", "=", "docker", ".", "LoadImageRegistryAuth", "(", "r", ")", "\n", "}", "\n\n", "cfg", ".", "PullAuthentication", "=", "docker", ".", "GetImageRegistryAuth", "(", "auths", ",", "cfg", ".", "Tag", ")", "\n\n", "if", "len", "(", "cfg", ".", "BuilderPullPolicy", ")", "==", "0", "{", "cfg", ".", "BuilderPullPolicy", "=", "api", ".", "DefaultBuilderPullPolicy", "\n", "}", "\n", "if", "len", "(", "cfg", ".", "PreviousImagePullPolicy", ")", "==", "0", "{", "cfg", ".", "PreviousImagePullPolicy", "=", "api", ".", "DefaultPreviousImagePullPolicy", "\n", "}", "\n\n", "client", ",", "err", ":=", "docker", ".", "NewEngineAPIClient", "(", "cfg", ".", "DockerConfig", ")", "\n", "s2ierr", ".", "CheckError", "(", "err", ")", "\n", "dkr", ":=", "docker", ".", "New", "(", "client", ",", "cfg", ".", "PullAuthentication", ")", "\n", "pr", ",", "err", ":=", "docker", ".", "GetRebuildImage", "(", "dkr", ",", "cfg", ")", "\n", "s2ierr", ".", "CheckError", "(", "err", ")", "\n", "err", "=", "build", ".", "GenerateConfigFromLabels", "(", "cfg", ",", "pr", ")", "\n", "s2ierr", ".", "CheckError", "(", "err", ")", "\n\n", "if", "len", "(", "args", ")", ">=", "2", "{", "cfg", ".", "Tag", "=", "args", "[", "1", "]", "\n", "}", "\n\n", "cfg", ".", "PullAuthentication", "=", "docker", ".", "GetImageRegistryAuth", "(", "auths", ",", "cfg", ".", "BuilderImage", ")", "\n\n", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\\n", "\\n", "\"", ",", "describe", ".", "Config", "(", "client", ",", "cfg", ")", ")", "\n\n", "builder", ",", "_", ",", "err", ":=", "strategies", ".", "GetStrategy", "(", "client", ",", "cfg", ")", "\n", "s2ierr", ".", "CheckError", "(", "err", ")", "\n", "result", ",", "err", ":=", "builder", ".", "Build", "(", "cfg", ")", "\n", "s2ierr", ".", "CheckError", "(", "err", ")", "\n\n", "for", "_", ",", "message", ":=", "range", "result", ".", "Messages", "{", "glog", ".", "V", "(", "1", ")", ".", "Infof", "(", "message", ")", "\n", "}", "\n", "}", ",", "}", "\n\n", "cmdutil", ".", "AddCommonFlags", "(", "buildCmd", ",", "cfg", ")", "\n", "return", "buildCmd", "\n", "}" ]
// NewCmdRebuild implements the S2i cli rebuild command.
[ "NewCmdRebuild", "implements", "the", "S2i", "cli", "rebuild", "command", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/cmd/cli/cmd/rebuild.go#L18-L77
train
openshift/source-to-image
pkg/util/callback.go
ExecuteCallback
func (c *callbackInvoker) ExecuteCallback(callbackURL string, success bool, labels map[string]string, messages []string) []string { buf := new(bytes.Buffer) writer := bufio.NewWriter(buf) data := map[string]interface{}{ "success": success, } if len(labels) > 0 { data["labels"] = labels } jsonBuffer := new(bytes.Buffer) writer = bufio.NewWriter(jsonBuffer) jsonWriter := json.NewEncoder(writer) jsonWriter.Encode(data) writer.Flush() var ( resp *http.Response err error ) for retries := 0; retries < 3; retries++ { resp, err = c.postFunc(callbackURL, "application/json", jsonBuffer) if err != nil { errorMessage := fmt.Sprintf("Unable to invoke callback: %v", err) messages = append(messages, errorMessage) } if resp != nil { if resp.StatusCode >= 300 { errorMessage := fmt.Sprintf("Callback returned with error code: %d", resp.StatusCode) messages = append(messages, errorMessage) } break } } return messages }
go
func (c *callbackInvoker) ExecuteCallback(callbackURL string, success bool, labels map[string]string, messages []string) []string { buf := new(bytes.Buffer) writer := bufio.NewWriter(buf) data := map[string]interface{}{ "success": success, } if len(labels) > 0 { data["labels"] = labels } jsonBuffer := new(bytes.Buffer) writer = bufio.NewWriter(jsonBuffer) jsonWriter := json.NewEncoder(writer) jsonWriter.Encode(data) writer.Flush() var ( resp *http.Response err error ) for retries := 0; retries < 3; retries++ { resp, err = c.postFunc(callbackURL, "application/json", jsonBuffer) if err != nil { errorMessage := fmt.Sprintf("Unable to invoke callback: %v", err) messages = append(messages, errorMessage) } if resp != nil { if resp.StatusCode >= 300 { errorMessage := fmt.Sprintf("Callback returned with error code: %d", resp.StatusCode) messages = append(messages, errorMessage) } break } } return messages }
[ "func", "(", "c", "*", "callbackInvoker", ")", "ExecuteCallback", "(", "callbackURL", "string", ",", "success", "bool", ",", "labels", "map", "[", "string", "]", "string", ",", "messages", "[", "]", "string", ")", "[", "]", "string", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "writer", ":=", "bufio", ".", "NewWriter", "(", "buf", ")", "\n\n", "data", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "success", ",", "}", "\n\n", "if", "len", "(", "labels", ")", ">", "0", "{", "data", "[", "\"", "\"", "]", "=", "labels", "\n", "}", "\n\n", "jsonBuffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "writer", "=", "bufio", ".", "NewWriter", "(", "jsonBuffer", ")", "\n", "jsonWriter", ":=", "json", ".", "NewEncoder", "(", "writer", ")", "\n", "jsonWriter", ".", "Encode", "(", "data", ")", "\n", "writer", ".", "Flush", "(", ")", "\n\n", "var", "(", "resp", "*", "http", ".", "Response", "\n", "err", "error", "\n", ")", "\n", "for", "retries", ":=", "0", ";", "retries", "<", "3", ";", "retries", "++", "{", "resp", ",", "err", "=", "c", ".", "postFunc", "(", "callbackURL", ",", "\"", "\"", ",", "jsonBuffer", ")", "\n", "if", "err", "!=", "nil", "{", "errorMessage", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "\n", "messages", "=", "append", "(", "messages", ",", "errorMessage", ")", "\n", "}", "\n", "if", "resp", "!=", "nil", "{", "if", "resp", ".", "StatusCode", ">=", "300", "{", "errorMessage", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "resp", ".", "StatusCode", ")", "\n", "messages", "=", "append", "(", "messages", ",", "errorMessage", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "messages", "\n", "}" ]
// ExecuteCallback prepares a JSON payload and posts it to the specified callback URL
[ "ExecuteCallback", "prepares", "a", "JSON", "payload", "and", "posts", "it", "to", "the", "specified", "callback", "URL" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/callback.go#L29-L66
train
openshift/source-to-image
pkg/util/env.go
SafeForLoggingEnv
func SafeForLoggingEnv(env []string) []string { newEnv := make([]string, len(env)) copy(newEnv, env) for i, entry := range newEnv { parts := strings.SplitN(entry, "=", 2) if !proxyRegex.MatchString(parts[0]) { continue } newVal, _ := SafeForLoggingURL(parts[1]) newEnv[i] = fmt.Sprintf("%s=%s", parts[0], newVal) } return newEnv }
go
func SafeForLoggingEnv(env []string) []string { newEnv := make([]string, len(env)) copy(newEnv, env) for i, entry := range newEnv { parts := strings.SplitN(entry, "=", 2) if !proxyRegex.MatchString(parts[0]) { continue } newVal, _ := SafeForLoggingURL(parts[1]) newEnv[i] = fmt.Sprintf("%s=%s", parts[0], newVal) } return newEnv }
[ "func", "SafeForLoggingEnv", "(", "env", "[", "]", "string", ")", "[", "]", "string", "{", "newEnv", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "env", ")", ")", "\n", "copy", "(", "newEnv", ",", "env", ")", "\n", "for", "i", ",", "entry", ":=", "range", "newEnv", "{", "parts", ":=", "strings", ".", "SplitN", "(", "entry", ",", "\"", "\"", ",", "2", ")", "\n", "if", "!", "proxyRegex", ".", "MatchString", "(", "parts", "[", "0", "]", ")", "{", "continue", "\n", "}", "\n", "newVal", ",", "_", ":=", "SafeForLoggingURL", "(", "parts", "[", "1", "]", ")", "\n", "newEnv", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "parts", "[", "0", "]", ",", "newVal", ")", "\n", "}", "\n", "return", "newEnv", "\n", "}" ]
// SafeForLoggingEnv attempts to strip sensitive information from proxy // environment variable strings in key=value form.
[ "SafeForLoggingEnv", "attempts", "to", "strip", "sensitive", "information", "from", "proxy", "environment", "variable", "strings", "in", "key", "=", "value", "form", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/env.go#L46-L58
train
openshift/source-to-image
pkg/create/create.go
New
func New(name, dst string) *Bootstrap { return &Bootstrap{ImageName: name, DestinationDir: dst} }
go
func New(name, dst string) *Bootstrap { return &Bootstrap{ImageName: name, DestinationDir: dst} }
[ "func", "New", "(", "name", ",", "dst", "string", ")", "*", "Bootstrap", "{", "return", "&", "Bootstrap", "{", "ImageName", ":", "name", ",", "DestinationDir", ":", "dst", "}", "\n", "}" ]
// New returns a new bootstrap for given image name and destination directory
[ "New", "returns", "a", "new", "bootstrap", "for", "given", "image", "name", "and", "destination", "directory" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/create/create.go#L20-L22
train
openshift/source-to-image
pkg/create/create.go
AddSTIScripts
func (b *Bootstrap) AddSTIScripts() { os.MkdirAll(b.DestinationDir+"/"+"s2i/bin", 0700) b.process(templates.AssembleScript, "s2i/bin/assemble", 0755) b.process(templates.RunScript, "s2i/bin/run", 0755) b.process(templates.UsageScript, "s2i/bin/usage", 0755) b.process(templates.SaveArtifactsScript, "s2i/bin/save-artifacts", 0755) }
go
func (b *Bootstrap) AddSTIScripts() { os.MkdirAll(b.DestinationDir+"/"+"s2i/bin", 0700) b.process(templates.AssembleScript, "s2i/bin/assemble", 0755) b.process(templates.RunScript, "s2i/bin/run", 0755) b.process(templates.UsageScript, "s2i/bin/usage", 0755) b.process(templates.SaveArtifactsScript, "s2i/bin/save-artifacts", 0755) }
[ "func", "(", "b", "*", "Bootstrap", ")", "AddSTIScripts", "(", ")", "{", "os", ".", "MkdirAll", "(", "b", ".", "DestinationDir", "+", "\"", "\"", "+", "\"", "\"", ",", "0700", ")", "\n", "b", ".", "process", "(", "templates", ".", "AssembleScript", ",", "\"", "\"", ",", "0755", ")", "\n", "b", ".", "process", "(", "templates", ".", "RunScript", ",", "\"", "\"", ",", "0755", ")", "\n", "b", ".", "process", "(", "templates", ".", "UsageScript", ",", "\"", "\"", ",", "0755", ")", "\n", "b", ".", "process", "(", "templates", ".", "SaveArtifactsScript", ",", "\"", "\"", ",", "0755", ")", "\n", "}" ]
// AddSTIScripts creates the STI scripts directory structure and process // templates for STI scripts
[ "AddSTIScripts", "creates", "the", "STI", "scripts", "directory", "structure", "and", "process", "templates", "for", "STI", "scripts" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/create/create.go#L26-L32
train
openshift/source-to-image
pkg/cmd/cli/cli.go
NewCmdCLI
func NewCmdCLI() *cobra.Command { // Applying partial glog flag initialization workaround from: https://github.com/kubernetes/kubernetes/issues/17162 // Without this fake command line parse, glog will compain its flags have not been interpreted flag.CommandLine.Parse([]string{}) cfg := &api.Config{} s2iCmd := &cobra.Command{ Use: "s2i", Long: "Source-to-image (S2I) is a tool for building repeatable docker images.\n\n" + "A command line interface that injects and assembles source code into a docker image.\n" + "Complete documentation is available at http://github.com/openshift/source-to-image", Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, } cfg.DockerConfig = docker.GetDefaultDockerConfig() s2iCmd.PersistentFlags().StringVarP(&(cfg.DockerConfig.Endpoint), "url", "U", cfg.DockerConfig.Endpoint, "Set the url of the docker socket to use") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CertFile), "cert", cfg.DockerConfig.CertFile, "Set the path of the docker TLS certificate file") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.KeyFile), "key", cfg.DockerConfig.KeyFile, "Set the path of the docker TLS key file") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CAFile), "ca", cfg.DockerConfig.CAFile, "Set the path of the docker TLS ca file") s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.UseTLS), "tls", cfg.DockerConfig.UseTLS, "Use TLS to connect to docker; implied by --tlsverify") s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.TLSVerify), "tlsverify", cfg.DockerConfig.TLSVerify, "Use TLS to connect to docker and verify the remote") s2iCmd.AddCommand(cmd.NewCmdVersion()) s2iCmd.AddCommand(cmd.NewCmdBuild(cfg)) s2iCmd.AddCommand(cmd.NewCmdRebuild(cfg)) s2iCmd.AddCommand(cmd.NewCmdUsage(cfg)) s2iCmd.AddCommand(cmd.NewCmdCreate()) cmdutil.SetupGlog(s2iCmd.PersistentFlags()) basename := filepath.Base(os.Args[0]) // Make case-insensitive and strip executable suffix if present if runtime.GOOS == "windows" { basename = strings.ToLower(basename) basename = strings.TrimSuffix(basename, ".exe") } if basename == "sti" { glog.Warning("sti binary is deprecated, use s2i instead") } s2iCmd.AddCommand(cmd.NewCmdCompletion(s2iCmd)) return s2iCmd }
go
func NewCmdCLI() *cobra.Command { // Applying partial glog flag initialization workaround from: https://github.com/kubernetes/kubernetes/issues/17162 // Without this fake command line parse, glog will compain its flags have not been interpreted flag.CommandLine.Parse([]string{}) cfg := &api.Config{} s2iCmd := &cobra.Command{ Use: "s2i", Long: "Source-to-image (S2I) is a tool for building repeatable docker images.\n\n" + "A command line interface that injects and assembles source code into a docker image.\n" + "Complete documentation is available at http://github.com/openshift/source-to-image", Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, } cfg.DockerConfig = docker.GetDefaultDockerConfig() s2iCmd.PersistentFlags().StringVarP(&(cfg.DockerConfig.Endpoint), "url", "U", cfg.DockerConfig.Endpoint, "Set the url of the docker socket to use") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CertFile), "cert", cfg.DockerConfig.CertFile, "Set the path of the docker TLS certificate file") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.KeyFile), "key", cfg.DockerConfig.KeyFile, "Set the path of the docker TLS key file") s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CAFile), "ca", cfg.DockerConfig.CAFile, "Set the path of the docker TLS ca file") s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.UseTLS), "tls", cfg.DockerConfig.UseTLS, "Use TLS to connect to docker; implied by --tlsverify") s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.TLSVerify), "tlsverify", cfg.DockerConfig.TLSVerify, "Use TLS to connect to docker and verify the remote") s2iCmd.AddCommand(cmd.NewCmdVersion()) s2iCmd.AddCommand(cmd.NewCmdBuild(cfg)) s2iCmd.AddCommand(cmd.NewCmdRebuild(cfg)) s2iCmd.AddCommand(cmd.NewCmdUsage(cfg)) s2iCmd.AddCommand(cmd.NewCmdCreate()) cmdutil.SetupGlog(s2iCmd.PersistentFlags()) basename := filepath.Base(os.Args[0]) // Make case-insensitive and strip executable suffix if present if runtime.GOOS == "windows" { basename = strings.ToLower(basename) basename = strings.TrimSuffix(basename, ".exe") } if basename == "sti" { glog.Warning("sti binary is deprecated, use s2i instead") } s2iCmd.AddCommand(cmd.NewCmdCompletion(s2iCmd)) return s2iCmd }
[ "func", "NewCmdCLI", "(", ")", "*", "cobra", ".", "Command", "{", "// Applying partial glog flag initialization workaround from: https://github.com/kubernetes/kubernetes/issues/17162", "// Without this fake command line parse, glog will compain its flags have not been interpreted", "flag", ".", "CommandLine", ".", "Parse", "(", "[", "]", "string", "{", "}", ")", "\n\n", "cfg", ":=", "&", "api", ".", "Config", "{", "}", "\n", "s2iCmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Long", ":", "\"", "\\n", "\\n", "\"", "+", "\"", "\\n", "\"", "+", "\"", "\"", ",", "Run", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "cmd", ".", "Help", "(", ")", "\n", "}", ",", "}", "\n", "cfg", ".", "DockerConfig", "=", "docker", ".", "GetDefaultDockerConfig", "(", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "StringVarP", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "Endpoint", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "Endpoint", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "StringVar", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "CertFile", ")", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "CertFile", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "StringVar", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "KeyFile", ")", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "KeyFile", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "StringVar", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "CAFile", ")", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "CAFile", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "BoolVar", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "UseTLS", ")", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "UseTLS", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "PersistentFlags", "(", ")", ".", "BoolVar", "(", "&", "(", "cfg", ".", "DockerConfig", ".", "TLSVerify", ")", ",", "\"", "\"", ",", "cfg", ".", "DockerConfig", ".", "TLSVerify", ",", "\"", "\"", ")", "\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdVersion", "(", ")", ")", "\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdBuild", "(", "cfg", ")", ")", "\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdRebuild", "(", "cfg", ")", ")", "\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdUsage", "(", "cfg", ")", ")", "\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdCreate", "(", ")", ")", "\n", "cmdutil", ".", "SetupGlog", "(", "s2iCmd", ".", "PersistentFlags", "(", ")", ")", "\n", "basename", ":=", "filepath", ".", "Base", "(", "os", ".", "Args", "[", "0", "]", ")", "\n", "// Make case-insensitive and strip executable suffix if present", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "basename", "=", "strings", ".", "ToLower", "(", "basename", ")", "\n", "basename", "=", "strings", ".", "TrimSuffix", "(", "basename", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "basename", "==", "\"", "\"", "{", "glog", ".", "Warning", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s2iCmd", ".", "AddCommand", "(", "cmd", ".", "NewCmdCompletion", "(", "s2iCmd", ")", ")", "\n\n", "return", "s2iCmd", "\n", "}" ]
// NewCmdCLI implements the S2I command line functionality.
[ "NewCmdCLI", "implements", "the", "S2I", "command", "line", "functionality", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/cmd/cli/cli.go#L24-L65
train
openshift/source-to-image
pkg/cmd/cli/cmd/create.go
NewCmdCreate
func NewCmdCreate() *cobra.Command { return &cobra.Command{ Use: "create <imageName> <destination>", Short: "Bootstrap a new S2I image repository", Long: "Bootstrap a new S2I image with given imageName inside the destination directory", Run: func(cmd *cobra.Command, args []string) { if len(args) < 2 { cmd.Help() return } b := create.New(args[0], args[1]) b.AddSTIScripts() b.AddDockerfile() b.AddReadme() b.AddTests() }, } }
go
func NewCmdCreate() *cobra.Command { return &cobra.Command{ Use: "create <imageName> <destination>", Short: "Bootstrap a new S2I image repository", Long: "Bootstrap a new S2I image with given imageName inside the destination directory", Run: func(cmd *cobra.Command, args []string) { if len(args) < 2 { cmd.Help() return } b := create.New(args[0], args[1]) b.AddSTIScripts() b.AddDockerfile() b.AddReadme() b.AddTests() }, } }
[ "func", "NewCmdCreate", "(", ")", "*", "cobra", ".", "Command", "{", "return", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Long", ":", "\"", "\"", ",", "Run", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "len", "(", "args", ")", "<", "2", "{", "cmd", ".", "Help", "(", ")", "\n", "return", "\n", "}", "\n", "b", ":=", "create", ".", "New", "(", "args", "[", "0", "]", ",", "args", "[", "1", "]", ")", "\n", "b", ".", "AddSTIScripts", "(", ")", "\n", "b", ".", "AddDockerfile", "(", ")", "\n", "b", ".", "AddReadme", "(", ")", "\n", "b", ".", "AddTests", "(", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewCmdCreate implements the S2I cli create command.
[ "NewCmdCreate", "implements", "the", "S2I", "cli", "create", "command", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/cmd/cli/cmd/create.go#L10-L27
train
openshift/source-to-image
pkg/docker/fake_docker.go
IsImageInLocalRegistry
func (f *FakeDocker) IsImageInLocalRegistry(imageName string) (bool, error) { f.LocalRegistryImage = imageName return f.LocalRegistryResult, f.LocalRegistryError }
go
func (f *FakeDocker) IsImageInLocalRegistry(imageName string) (bool, error) { f.LocalRegistryImage = imageName return f.LocalRegistryResult, f.LocalRegistryError }
[ "func", "(", "f", "*", "FakeDocker", ")", "IsImageInLocalRegistry", "(", "imageName", "string", ")", "(", "bool", ",", "error", ")", "{", "f", ".", "LocalRegistryImage", "=", "imageName", "\n", "return", "f", ".", "LocalRegistryResult", ",", "f", ".", "LocalRegistryError", "\n", "}" ]
// IsImageInLocalRegistry checks if the image exists in the fake local registry
[ "IsImageInLocalRegistry", "checks", "if", "the", "image", "exists", "in", "the", "fake", "local", "registry" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L61-L64
train
openshift/source-to-image
pkg/docker/fake_docker.go
IsImageOnBuild
func (f *FakeDocker) IsImageOnBuild(imageName string) bool { f.IsOnBuildImage = imageName return f.IsOnBuildResult }
go
func (f *FakeDocker) IsImageOnBuild(imageName string) bool { f.IsOnBuildImage = imageName return f.IsOnBuildResult }
[ "func", "(", "f", "*", "FakeDocker", ")", "IsImageOnBuild", "(", "imageName", "string", ")", "bool", "{", "f", ".", "IsOnBuildImage", "=", "imageName", "\n", "return", "f", ".", "IsOnBuildResult", "\n", "}" ]
// IsImageOnBuild returns true if the builder has onbuild instructions
[ "IsImageOnBuild", "returns", "true", "if", "the", "builder", "has", "onbuild", "instructions" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L67-L70
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetOnBuild
func (f *FakeDocker) GetOnBuild(imageName string) ([]string, error) { f.OnBuildImage = imageName return f.OnBuildResult, f.OnBuildError }
go
func (f *FakeDocker) GetOnBuild(imageName string) ([]string, error) { f.OnBuildImage = imageName return f.OnBuildResult, f.OnBuildError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetOnBuild", "(", "imageName", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "f", ".", "OnBuildImage", "=", "imageName", "\n", "return", "f", ".", "OnBuildResult", ",", "f", ".", "OnBuildError", "\n", "}" ]
// GetOnBuild returns the list of onbuild instructions for the given image
[ "GetOnBuild", "returns", "the", "list", "of", "onbuild", "instructions", "for", "the", "given", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L83-L86
train
openshift/source-to-image
pkg/docker/fake_docker.go
RemoveContainer
func (f *FakeDocker) RemoveContainer(id string) error { f.RemoveContainerID = id return f.RemoveContainerError }
go
func (f *FakeDocker) RemoveContainer(id string) error { f.RemoveContainerID = id return f.RemoveContainerError }
[ "func", "(", "f", "*", "FakeDocker", ")", "RemoveContainer", "(", "id", "string", ")", "error", "{", "f", ".", "RemoveContainerID", "=", "id", "\n", "return", "f", ".", "RemoveContainerError", "\n", "}" ]
// RemoveContainer removes a fake Docker container
[ "RemoveContainer", "removes", "a", "fake", "Docker", "container" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L89-L92
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetScriptsURL
func (f *FakeDocker) GetScriptsURL(image string) (string, error) { f.DefaultURLImage = image return f.DefaultURLResult, f.DefaultURLError }
go
func (f *FakeDocker) GetScriptsURL(image string) (string, error) { f.DefaultURLImage = image return f.DefaultURLResult, f.DefaultURLError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetScriptsURL", "(", "image", "string", ")", "(", "string", ",", "error", ")", "{", "f", ".", "DefaultURLImage", "=", "image", "\n", "return", "f", ".", "DefaultURLResult", ",", "f", ".", "DefaultURLError", "\n", "}" ]
// GetScriptsURL returns a default STI scripts URL
[ "GetScriptsURL", "returns", "a", "default", "STI", "scripts", "URL" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L100-L103
train
openshift/source-to-image
pkg/docker/fake_docker.go
RunContainer
func (f *FakeDocker) RunContainer(opts RunContainerOptions) error { f.RunContainerOpts = opts if f.RunContainerErrorBeforeStart { return f.RunContainerError } if opts.Stdout != nil { opts.Stdout.Close() } if opts.Stderr != nil { opts.Stderr.Close() } if opts.OnStart != nil { if err := opts.OnStart(""); err != nil { return err } } if opts.Stdin != nil { _, err := io.Copy(ioutil.Discard, opts.Stdin) if err != nil { return err } } if opts.PostExec != nil { opts.PostExec.PostExecute(f.RunContainerContainerID, string(opts.Command)) } return f.RunContainerError }
go
func (f *FakeDocker) RunContainer(opts RunContainerOptions) error { f.RunContainerOpts = opts if f.RunContainerErrorBeforeStart { return f.RunContainerError } if opts.Stdout != nil { opts.Stdout.Close() } if opts.Stderr != nil { opts.Stderr.Close() } if opts.OnStart != nil { if err := opts.OnStart(""); err != nil { return err } } if opts.Stdin != nil { _, err := io.Copy(ioutil.Discard, opts.Stdin) if err != nil { return err } } if opts.PostExec != nil { opts.PostExec.PostExecute(f.RunContainerContainerID, string(opts.Command)) } return f.RunContainerError }
[ "func", "(", "f", "*", "FakeDocker", ")", "RunContainer", "(", "opts", "RunContainerOptions", ")", "error", "{", "f", ".", "RunContainerOpts", "=", "opts", "\n", "if", "f", ".", "RunContainerErrorBeforeStart", "{", "return", "f", ".", "RunContainerError", "\n", "}", "\n", "if", "opts", ".", "Stdout", "!=", "nil", "{", "opts", ".", "Stdout", ".", "Close", "(", ")", "\n", "}", "\n", "if", "opts", ".", "Stderr", "!=", "nil", "{", "opts", ".", "Stderr", ".", "Close", "(", ")", "\n", "}", "\n", "if", "opts", ".", "OnStart", "!=", "nil", "{", "if", "err", ":=", "opts", ".", "OnStart", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "opts", ".", "Stdin", "!=", "nil", "{", "_", ",", "err", ":=", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "opts", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "opts", ".", "PostExec", "!=", "nil", "{", "opts", ".", "PostExec", ".", "PostExecute", "(", "f", ".", "RunContainerContainerID", ",", "string", "(", "opts", ".", "Command", ")", ")", "\n", "}", "\n", "return", "f", ".", "RunContainerError", "\n", "}" ]
// RunContainer runs a fake Docker container
[ "RunContainer", "runs", "a", "fake", "Docker", "container" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L116-L142
train
openshift/source-to-image
pkg/docker/fake_docker.go
UploadToContainerWithTarWriter
func (f *FakeDocker) UploadToContainerWithTarWriter(fs fs.FileSystem, srcPath, destPath, container string, makeTarWriter func(io.Writer) tar.Writer) error { return errors.New("not implemented") }
go
func (f *FakeDocker) UploadToContainerWithTarWriter(fs fs.FileSystem, srcPath, destPath, container string, makeTarWriter func(io.Writer) tar.Writer) error { return errors.New("not implemented") }
[ "func", "(", "f", "*", "FakeDocker", ")", "UploadToContainerWithTarWriter", "(", "fs", "fs", ".", "FileSystem", ",", "srcPath", ",", "destPath", ",", "container", "string", ",", "makeTarWriter", "func", "(", "io", ".", "Writer", ")", "tar", ".", "Writer", ")", "error", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// UploadToContainerWithTarWriter uploads artifacts to the container.
[ "UploadToContainerWithTarWriter", "uploads", "artifacts", "to", "the", "container", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L150-L152
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetImageID
func (f *FakeDocker) GetImageID(image string) (string, error) { f.GetImageIDImage = image return f.GetImageIDResult, f.GetImageIDError }
go
func (f *FakeDocker) GetImageID(image string) (string, error) { f.GetImageIDImage = image return f.GetImageIDResult, f.GetImageIDError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetImageID", "(", "image", "string", ")", "(", "string", ",", "error", ")", "{", "f", ".", "GetImageIDImage", "=", "image", "\n", "return", "f", ".", "GetImageIDResult", ",", "f", ".", "GetImageIDError", "\n", "}" ]
// GetImageID returns a fake Docker image ID
[ "GetImageID", "returns", "a", "fake", "Docker", "image", "ID" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L160-L163
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetImageUser
func (f *FakeDocker) GetImageUser(image string) (string, error) { f.GetImageUserImage = image return f.GetImageUserResult, f.GetImageUserError }
go
func (f *FakeDocker) GetImageUser(image string) (string, error) { f.GetImageUserImage = image return f.GetImageUserResult, f.GetImageUserError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetImageUser", "(", "image", "string", ")", "(", "string", ",", "error", ")", "{", "f", ".", "GetImageUserImage", "=", "image", "\n", "return", "f", ".", "GetImageUserResult", ",", "f", ".", "GetImageUserError", "\n", "}" ]
// GetImageUser returns a fake user
[ "GetImageUser", "returns", "a", "fake", "user" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L166-L169
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetImageEntrypoint
func (f *FakeDocker) GetImageEntrypoint(image string) ([]string, error) { return f.GetImageEntrypointResult, f.GetImageEntrypointError }
go
func (f *FakeDocker) GetImageEntrypoint(image string) ([]string, error) { return f.GetImageEntrypointResult, f.GetImageEntrypointError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetImageEntrypoint", "(", "image", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "f", ".", "GetImageEntrypointResult", ",", "f", ".", "GetImageEntrypointError", "\n", "}" ]
// GetImageEntrypoint returns an empty entrypoint
[ "GetImageEntrypoint", "returns", "an", "empty", "entrypoint" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L172-L174
train
openshift/source-to-image
pkg/docker/fake_docker.go
CommitContainer
func (f *FakeDocker) CommitContainer(opts CommitContainerOptions) (string, error) { f.CommitContainerOpts = opts return f.CommitContainerResult, f.CommitContainerError }
go
func (f *FakeDocker) CommitContainer(opts CommitContainerOptions) (string, error) { f.CommitContainerOpts = opts return f.CommitContainerResult, f.CommitContainerError }
[ "func", "(", "f", "*", "FakeDocker", ")", "CommitContainer", "(", "opts", "CommitContainerOptions", ")", "(", "string", ",", "error", ")", "{", "f", ".", "CommitContainerOpts", "=", "opts", "\n", "return", "f", ".", "CommitContainerResult", ",", "f", ".", "CommitContainerError", "\n", "}" ]
// CommitContainer commits a fake Docker container
[ "CommitContainer", "commits", "a", "fake", "Docker", "container" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L177-L180
train
openshift/source-to-image
pkg/docker/fake_docker.go
RemoveImage
func (f *FakeDocker) RemoveImage(name string) error { f.RemoveImageName = name return f.RemoveImageError }
go
func (f *FakeDocker) RemoveImage(name string) error { f.RemoveImageName = name return f.RemoveImageError }
[ "func", "(", "f", "*", "FakeDocker", ")", "RemoveImage", "(", "name", "string", ")", "error", "{", "f", ".", "RemoveImageName", "=", "name", "\n", "return", "f", ".", "RemoveImageError", "\n", "}" ]
// RemoveImage removes a fake Docker image
[ "RemoveImage", "removes", "a", "fake", "Docker", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L183-L186
train
openshift/source-to-image
pkg/docker/fake_docker.go
CheckImage
func (f *FakeDocker) CheckImage(name string) (*api.Image, error) { return nil, nil }
go
func (f *FakeDocker) CheckImage(name string) (*api.Image, error) { return nil, nil }
[ "func", "(", "f", "*", "FakeDocker", ")", "CheckImage", "(", "name", "string", ")", "(", "*", "api", ".", "Image", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// CheckImage checks image in local registry
[ "CheckImage", "checks", "image", "in", "local", "registry" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L189-L191
train
openshift/source-to-image
pkg/docker/fake_docker.go
PullImage
func (f *FakeDocker) PullImage(imageName string) (*api.Image, error) { if f.PullResult { return &api.Image{}, nil } return nil, f.PullError }
go
func (f *FakeDocker) PullImage(imageName string) (*api.Image, error) { if f.PullResult { return &api.Image{}, nil } return nil, f.PullError }
[ "func", "(", "f", "*", "FakeDocker", ")", "PullImage", "(", "imageName", "string", ")", "(", "*", "api", ".", "Image", ",", "error", ")", "{", "if", "f", ".", "PullResult", "{", "return", "&", "api", ".", "Image", "{", "}", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "f", ".", "PullError", "\n", "}" ]
// PullImage pulls a fake docker image
[ "PullImage", "pulls", "a", "fake", "docker", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L194-L199
train
openshift/source-to-image
pkg/docker/fake_docker.go
CheckAndPullImage
func (f *FakeDocker) CheckAndPullImage(name string) (*api.Image, error) { if f.PullResult { return &api.Image{}, nil } return nil, f.PullError }
go
func (f *FakeDocker) CheckAndPullImage(name string) (*api.Image, error) { if f.PullResult { return &api.Image{}, nil } return nil, f.PullError }
[ "func", "(", "f", "*", "FakeDocker", ")", "CheckAndPullImage", "(", "name", "string", ")", "(", "*", "api", ".", "Image", ",", "error", ")", "{", "if", "f", ".", "PullResult", "{", "return", "&", "api", ".", "Image", "{", "}", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "f", ".", "PullError", "\n", "}" ]
// CheckAndPullImage pulls a fake docker image
[ "CheckAndPullImage", "pulls", "a", "fake", "docker", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L202-L207
train
openshift/source-to-image
pkg/docker/fake_docker.go
BuildImage
func (f *FakeDocker) BuildImage(opts BuildImageOptions) error { f.BuildImageOpts = opts if opts.Stdin != nil { _, err := io.Copy(ioutil.Discard, opts.Stdin) if err != nil { return err } } return f.BuildImageError }
go
func (f *FakeDocker) BuildImage(opts BuildImageOptions) error { f.BuildImageOpts = opts if opts.Stdin != nil { _, err := io.Copy(ioutil.Discard, opts.Stdin) if err != nil { return err } } return f.BuildImageError }
[ "func", "(", "f", "*", "FakeDocker", ")", "BuildImage", "(", "opts", "BuildImageOptions", ")", "error", "{", "f", ".", "BuildImageOpts", "=", "opts", "\n", "if", "opts", ".", "Stdin", "!=", "nil", "{", "_", ",", "err", ":=", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "opts", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "f", ".", "BuildImageError", "\n", "}" ]
// BuildImage builds image
[ "BuildImage", "builds", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L210-L219
train
openshift/source-to-image
pkg/docker/fake_docker.go
GetLabels
func (f *FakeDocker) GetLabels(name string) (map[string]string, error) { return f.Labels, f.LabelsError }
go
func (f *FakeDocker) GetLabels(name string) (map[string]string, error) { return f.Labels, f.LabelsError }
[ "func", "(", "f", "*", "FakeDocker", ")", "GetLabels", "(", "name", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "return", "f", ".", "Labels", ",", "f", ".", "LabelsError", "\n", "}" ]
// GetLabels returns the labels of the image
[ "GetLabels", "returns", "the", "labels", "of", "the", "image" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/docker/fake_docker.go#L222-L224
train
openshift/source-to-image
pkg/util/fs/fs.go
NewFileSystem
func NewFileSystem() FileSystem { return &fs{ fileModes: make(map[string]os.FileMode), keepSymlinks: false, } }
go
func NewFileSystem() FileSystem { return &fs{ fileModes: make(map[string]os.FileMode), keepSymlinks: false, } }
[ "func", "NewFileSystem", "(", ")", "FileSystem", "{", "return", "&", "fs", "{", "fileModes", ":", "make", "(", "map", "[", "string", "]", "os", ".", "FileMode", ")", ",", "keepSymlinks", ":", "false", ",", "}", "\n", "}" ]
// NewFileSystem creates a new instance of the default FileSystem // implementation
[ "NewFileSystem", "creates", "a", "new", "instance", "of", "the", "default", "FileSystem", "implementation" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L50-L55
train
openshift/source-to-image
pkg/util/fs/fs.go
Stat
func (h *fs) Stat(path string) (os.FileInfo, error) { fi, err := os.Stat(path) if runtime.GOOS == "windows" && err == nil { fi = h.enrichFileInfo(path, fi) } return fi, err }
go
func (h *fs) Stat(path string) (os.FileInfo, error) { fi, err := os.Stat(path) if runtime.GOOS == "windows" && err == nil { fi = h.enrichFileInfo(path, fi) } return fi, err }
[ "func", "(", "h", "*", "fs", ")", "Stat", "(", "path", "string", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "fi", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "&&", "err", "==", "nil", "{", "fi", "=", "h", ".", "enrichFileInfo", "(", "path", ",", "fi", ")", "\n", "}", "\n", "return", "fi", ",", "err", "\n", "}" ]
// Stat returns a FileInfo describing the named file.
[ "Stat", "returns", "a", "FileInfo", "describing", "the", "named", "file", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L118-L124
train
openshift/source-to-image
pkg/util/fs/fs.go
ReadDir
func (h *fs) ReadDir(path string) ([]os.FileInfo, error) { fis, err := ioutil.ReadDir(path) if runtime.GOOS == "windows" && err == nil { h.enrichFileInfos(path, fis) } return fis, err }
go
func (h *fs) ReadDir(path string) ([]os.FileInfo, error) { fis, err := ioutil.ReadDir(path) if runtime.GOOS == "windows" && err == nil { h.enrichFileInfos(path, fis) } return fis, err }
[ "func", "(", "h", "*", "fs", ")", "ReadDir", "(", "path", "string", ")", "(", "[", "]", "os", ".", "FileInfo", ",", "error", ")", "{", "fis", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "path", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "&&", "err", "==", "nil", "{", "h", ".", "enrichFileInfos", "(", "path", ",", "fis", ")", "\n", "}", "\n", "return", "fis", ",", "err", "\n", "}" ]
// ReadDir reads the directory named by dirname and returns a list of directory // entries sorted by filename.
[ "ReadDir", "reads", "the", "directory", "named", "by", "dirname", "and", "returns", "a", "list", "of", "directory", "entries", "sorted", "by", "filename", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L137-L143
train
openshift/source-to-image
pkg/util/fs/fs.go
Chmod
func (h *fs) Chmod(file string, mode os.FileMode) error { err := os.Chmod(file, mode) if runtime.GOOS == "windows" && err == nil { h.m.Lock() h.fileModes[file] = mode h.m.Unlock() return nil } return err }
go
func (h *fs) Chmod(file string, mode os.FileMode) error { err := os.Chmod(file, mode) if runtime.GOOS == "windows" && err == nil { h.m.Lock() h.fileModes[file] = mode h.m.Unlock() return nil } return err }
[ "func", "(", "h", "*", "fs", ")", "Chmod", "(", "file", "string", ",", "mode", "os", ".", "FileMode", ")", "error", "{", "err", ":=", "os", ".", "Chmod", "(", "file", ",", "mode", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "&&", "err", "==", "nil", "{", "h", ".", "m", ".", "Lock", "(", ")", "\n", "h", ".", "fileModes", "[", "file", "]", "=", "mode", "\n", "h", ".", "m", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Chmod sets the file mode
[ "Chmod", "sets", "the", "file", "mode" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L146-L155
train
openshift/source-to-image
pkg/util/fs/fs.go
Rename
func (h *fs) Rename(from, to string) error { return os.Rename(from, to) }
go
func (h *fs) Rename(from, to string) error { return os.Rename(from, to) }
[ "func", "(", "h", "*", "fs", ")", "Rename", "(", "from", ",", "to", "string", ")", "error", "{", "return", "os", ".", "Rename", "(", "from", ",", "to", ")", "\n", "}" ]
// Rename renames or moves a file
[ "Rename", "renames", "or", "moves", "a", "file" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L158-L160
train
openshift/source-to-image
pkg/util/fs/fs.go
MkdirAllWithPermissions
func (h *fs) MkdirAllWithPermissions(dirname string, perm os.FileMode) error { return os.MkdirAll(dirname, perm) }
go
func (h *fs) MkdirAllWithPermissions(dirname string, perm os.FileMode) error { return os.MkdirAll(dirname, perm) }
[ "func", "(", "h", "*", "fs", ")", "MkdirAllWithPermissions", "(", "dirname", "string", ",", "perm", "os", ".", "FileMode", ")", "error", "{", "return", "os", ".", "MkdirAll", "(", "dirname", ",", "perm", ")", "\n", "}" ]
// MkdirAllWithPermissions creates the directory and all its parents with the provided permissions
[ "MkdirAllWithPermissions", "creates", "the", "directory", "and", "all", "its", "parents", "with", "the", "provided", "permissions" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L168-L170
train
openshift/source-to-image
pkg/util/fs/fs.go
Exists
func (h *fs) Exists(file string) bool { _, err := h.Stat(file) return err == nil }
go
func (h *fs) Exists(file string) bool { _, err := h.Stat(file) return err == nil }
[ "func", "(", "h", "*", "fs", ")", "Exists", "(", "file", "string", ")", "bool", "{", "_", ",", "err", ":=", "h", ".", "Stat", "(", "file", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// Exists determines whether the given file exists
[ "Exists", "determines", "whether", "the", "given", "file", "exists" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L178-L181
train
openshift/source-to-image
pkg/util/fs/fs.go
Copy
func (h *fs) Copy(source string, dest string) (err error) { return doCopy(h, source, dest) }
go
func (h *fs) Copy(source string, dest string) (err error) { return doCopy(h, source, dest) }
[ "func", "(", "h", "*", "fs", ")", "Copy", "(", "source", "string", ",", "dest", "string", ")", "(", "err", "error", ")", "{", "return", "doCopy", "(", "h", ",", "source", ",", "dest", ")", "\n", "}" ]
// Copy copies the source to a destination. // If the source is a file, then the destination has to be a file as well, // otherwise you will get an error. // If the source is a directory, then the destination has to be a directory and // we copy the content of the source directory to destination directory // recursively.
[ "Copy", "copies", "the", "source", "to", "a", "destination", ".", "If", "the", "source", "is", "a", "file", "then", "the", "destination", "has", "to", "be", "a", "file", "as", "well", "otherwise", "you", "will", "get", "an", "error", ".", "If", "the", "source", "is", "a", "directory", "then", "the", "destination", "has", "to", "be", "a", "directory", "and", "we", "copy", "the", "content", "of", "the", "source", "directory", "to", "destination", "directory", "recursively", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L189-L191
train
openshift/source-to-image
pkg/util/fs/fs.go
handleSymlink
func handleSymlink(h FileSystem, source, dest string) (bool, error) { lstatinfo, lstaterr := h.Lstat(source) _, staterr := h.Stat(source) if lstaterr == nil && lstatinfo.Mode()&os.ModeSymlink != 0 { if os.IsNotExist(staterr) { glog.V(5).Infof("(broken) L %q -> %q", source, dest) } else if h.ShouldKeepSymlinks() { glog.V(5).Infof("L %q -> %q", source, dest) } else { // symlink not handled here, will copy the file content return false, nil } linkdest, err := h.Readlink(source) if err != nil { return true, err } return true, h.Symlink(linkdest, dest) } // symlink not handled here, will copy the file content return false, nil }
go
func handleSymlink(h FileSystem, source, dest string) (bool, error) { lstatinfo, lstaterr := h.Lstat(source) _, staterr := h.Stat(source) if lstaterr == nil && lstatinfo.Mode()&os.ModeSymlink != 0 { if os.IsNotExist(staterr) { glog.V(5).Infof("(broken) L %q -> %q", source, dest) } else if h.ShouldKeepSymlinks() { glog.V(5).Infof("L %q -> %q", source, dest) } else { // symlink not handled here, will copy the file content return false, nil } linkdest, err := h.Readlink(source) if err != nil { return true, err } return true, h.Symlink(linkdest, dest) } // symlink not handled here, will copy the file content return false, nil }
[ "func", "handleSymlink", "(", "h", "FileSystem", ",", "source", ",", "dest", "string", ")", "(", "bool", ",", "error", ")", "{", "lstatinfo", ",", "lstaterr", ":=", "h", ".", "Lstat", "(", "source", ")", "\n", "_", ",", "staterr", ":=", "h", ".", "Stat", "(", "source", ")", "\n", "if", "lstaterr", "==", "nil", "&&", "lstatinfo", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "!=", "0", "{", "if", "os", ".", "IsNotExist", "(", "staterr", ")", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "source", ",", "dest", ")", "\n", "}", "else", "if", "h", ".", "ShouldKeepSymlinks", "(", ")", "{", "glog", ".", "V", "(", "5", ")", ".", "Infof", "(", "\"", "\"", ",", "source", ",", "dest", ")", "\n", "}", "else", "{", "// symlink not handled here, will copy the file content", "return", "false", ",", "nil", "\n", "}", "\n", "linkdest", ",", "err", ":=", "h", ".", "Readlink", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "return", "true", ",", "h", ".", "Symlink", "(", "linkdest", ",", "dest", ")", "\n", "}", "\n", "// symlink not handled here, will copy the file content", "return", "false", ",", "nil", "\n", "}" ]
// If src is symlink and symlink copy has been enabled, copy as a symlink. // Otherwise ignore symlink and let rest of the code follow the symlink // and copy the content of the file
[ "If", "src", "is", "symlink", "and", "symlink", "copy", "has", "been", "enabled", "copy", "as", "a", "symlink", ".", "Otherwise", "ignore", "symlink", "and", "let", "rest", "of", "the", "code", "follow", "the", "symlink", "and", "copy", "the", "content", "of", "the", "file" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L209-L230
train
openshift/source-to-image
pkg/util/fs/fs.go
CopyContents
func (h *fs) CopyContents(src string, dest string) (err error) { sourceinfo, err := h.Stat(src) if err != nil { return err } if err = os.MkdirAll(dest, sourceinfo.Mode()); err != nil { return err } directory, err := os.Open(src) if err != nil { return err } defer directory.Close() objects, err := directory.Readdir(-1) if err != nil { return err } for _, obj := range objects { source := path.Join(src, obj.Name()) destination := path.Join(dest, obj.Name()) if err := h.Copy(source, destination); err != nil { return err } } return }
go
func (h *fs) CopyContents(src string, dest string) (err error) { sourceinfo, err := h.Stat(src) if err != nil { return err } if err = os.MkdirAll(dest, sourceinfo.Mode()); err != nil { return err } directory, err := os.Open(src) if err != nil { return err } defer directory.Close() objects, err := directory.Readdir(-1) if err != nil { return err } for _, obj := range objects { source := path.Join(src, obj.Name()) destination := path.Join(dest, obj.Name()) if err := h.Copy(source, destination); err != nil { return err } } return }
[ "func", "(", "h", "*", "fs", ")", "CopyContents", "(", "src", "string", ",", "dest", "string", ")", "(", "err", "error", ")", "{", "sourceinfo", ",", "err", ":=", "h", ".", "Stat", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "os", ".", "MkdirAll", "(", "dest", ",", "sourceinfo", ".", "Mode", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "directory", ",", "err", ":=", "os", ".", "Open", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "directory", ".", "Close", "(", ")", "\n", "objects", ",", "err", ":=", "directory", ".", "Readdir", "(", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "obj", ":=", "range", "objects", "{", "source", ":=", "path", ".", "Join", "(", "src", ",", "obj", ".", "Name", "(", ")", ")", "\n", "destination", ":=", "path", ".", "Join", "(", "dest", ",", "obj", ".", "Name", "(", ")", ")", "\n", "if", "err", ":=", "h", ".", "Copy", "(", "source", ",", "destination", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// CopyContents copies the content of the source directory to a destination // directory. // If the destination directory does not exists, it will be created. // The source directory itself will not be copied, only its content. If you // want this behavior, the destination must include the source directory name.
[ "CopyContents", "copies", "the", "content", "of", "the", "source", "directory", "to", "a", "destination", "directory", ".", "If", "the", "destination", "directory", "does", "not", "exists", "it", "will", "be", "created", ".", "The", "source", "directory", "itself", "will", "not", "be", "copied", "only", "its", "content", ".", "If", "you", "want", "this", "behavior", "the", "destination", "must", "include", "the", "source", "directory", "name", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L273-L298
train
openshift/source-to-image
pkg/util/fs/fs.go
RemoveDirectory
func (h *fs) RemoveDirectory(dir string) error { glog.V(2).Infof("Removing directory '%s'", dir) // HACK: If deleting a directory in windows, call out to the system to do the deletion // TODO: Remove this workaround when we switch to go 1.7 -- os.RemoveAll should // be fixed for Windows in that release. https://github.com/golang/go/issues/9606 if runtime.GOOS == "windows" { command := exec.Command("cmd.exe", "/c", fmt.Sprintf("rd /s /q %s", dir)) output, err := command.Output() if err != nil { glog.Errorf("Error removing directory %q: %v %s", dir, err, string(output)) return err } return nil } err := os.RemoveAll(dir) if err != nil { glog.Errorf("Error removing directory '%s': %v", dir, err) } return err }
go
func (h *fs) RemoveDirectory(dir string) error { glog.V(2).Infof("Removing directory '%s'", dir) // HACK: If deleting a directory in windows, call out to the system to do the deletion // TODO: Remove this workaround when we switch to go 1.7 -- os.RemoveAll should // be fixed for Windows in that release. https://github.com/golang/go/issues/9606 if runtime.GOOS == "windows" { command := exec.Command("cmd.exe", "/c", fmt.Sprintf("rd /s /q %s", dir)) output, err := command.Output() if err != nil { glog.Errorf("Error removing directory %q: %v %s", dir, err, string(output)) return err } return nil } err := os.RemoveAll(dir) if err != nil { glog.Errorf("Error removing directory '%s': %v", dir, err) } return err }
[ "func", "(", "h", "*", "fs", ")", "RemoveDirectory", "(", "dir", "string", ")", "error", "{", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "dir", ")", "\n\n", "// HACK: If deleting a directory in windows, call out to the system to do the deletion", "// TODO: Remove this workaround when we switch to go 1.7 -- os.RemoveAll should", "// be fixed for Windows in that release. https://github.com/golang/go/issues/9606", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "command", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dir", ")", ")", "\n", "output", ",", "err", ":=", "command", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ",", "string", "(", "output", ")", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "err", ":=", "os", ".", "RemoveAll", "(", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// RemoveDirectory removes the specified directory and all its contents
[ "RemoveDirectory", "removes", "the", "specified", "directory", "and", "all", "its", "contents" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L301-L322
train
openshift/source-to-image
pkg/util/fs/fs.go
CreateWorkingDirectory
func (h *fs) CreateWorkingDirectory() (directory string, err error) { directory, err = ioutil.TempDir("", "s2i") if err != nil { return "", s2ierr.NewWorkDirError(directory, err) } return directory, err }
go
func (h *fs) CreateWorkingDirectory() (directory string, err error) { directory, err = ioutil.TempDir("", "s2i") if err != nil { return "", s2ierr.NewWorkDirError(directory, err) } return directory, err }
[ "func", "(", "h", "*", "fs", ")", "CreateWorkingDirectory", "(", ")", "(", "directory", "string", ",", "err", "error", ")", "{", "directory", ",", "err", "=", "ioutil", ".", "TempDir", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "s2ierr", ".", "NewWorkDirError", "(", "directory", ",", "err", ")", "\n", "}", "\n\n", "return", "directory", ",", "err", "\n", "}" ]
// CreateWorkingDirectory creates a directory to be used for STI
[ "CreateWorkingDirectory", "creates", "a", "directory", "to", "be", "used", "for", "STI" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L325-L332
train
openshift/source-to-image
pkg/util/fs/fs.go
Open
func (h *fs) Open(filename string) (io.ReadCloser, error) { return os.Open(filename) }
go
func (h *fs) Open(filename string) (io.ReadCloser, error) { return os.Open(filename) }
[ "func", "(", "h", "*", "fs", ")", "Open", "(", "filename", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "os", ".", "Open", "(", "filename", ")", "\n", "}" ]
// Open opens a file and returns a ReadCloser interface to that file
[ "Open", "opens", "a", "file", "and", "returns", "a", "ReadCloser", "interface", "to", "that", "file" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L335-L337
train
openshift/source-to-image
pkg/util/fs/fs.go
Create
func (h *fs) Create(filename string) (io.WriteCloser, error) { return os.Create(filename) }
go
func (h *fs) Create(filename string) (io.WriteCloser, error) { return os.Create(filename) }
[ "func", "(", "h", "*", "fs", ")", "Create", "(", "filename", "string", ")", "(", "io", ".", "WriteCloser", ",", "error", ")", "{", "return", "os", ".", "Create", "(", "filename", ")", "\n", "}" ]
// Create creates a file and returns a WriteCloser interface to that file
[ "Create", "creates", "a", "file", "and", "returns", "a", "WriteCloser", "interface", "to", "that", "file" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L340-L342
train
openshift/source-to-image
pkg/util/fs/fs.go
WriteFile
func (h *fs) WriteFile(filename string, data []byte) error { return ioutil.WriteFile(filename, data, 0700) }
go
func (h *fs) WriteFile(filename string, data []byte) error { return ioutil.WriteFile(filename, data, 0700) }
[ "func", "(", "h", "*", "fs", ")", "WriteFile", "(", "filename", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "return", "ioutil", ".", "WriteFile", "(", "filename", ",", "data", ",", "0700", ")", "\n", "}" ]
// WriteFile opens a file and writes data to it, returning error if such // occurred
[ "WriteFile", "opens", "a", "file", "and", "writes", "data", "to", "it", "returning", "error", "if", "such", "occurred" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L346-L348
train
openshift/source-to-image
pkg/util/fs/fs.go
Walk
func (h *fs) Walk(root string, walkFn filepath.WalkFunc) error { wrapper := func(path string, info os.FileInfo, err error) error { if runtime.GOOS == "windows" && err == nil { info = h.enrichFileInfo(path, info) } return walkFn(path, info, err) } return filepath.Walk(root, wrapper) }
go
func (h *fs) Walk(root string, walkFn filepath.WalkFunc) error { wrapper := func(path string, info os.FileInfo, err error) error { if runtime.GOOS == "windows" && err == nil { info = h.enrichFileInfo(path, info) } return walkFn(path, info, err) } return filepath.Walk(root, wrapper) }
[ "func", "(", "h", "*", "fs", ")", "Walk", "(", "root", "string", ",", "walkFn", "filepath", ".", "WalkFunc", ")", "error", "{", "wrapper", ":=", "func", "(", "path", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "&&", "err", "==", "nil", "{", "info", "=", "h", ".", "enrichFileInfo", "(", "path", ",", "info", ")", "\n", "}", "\n", "return", "walkFn", "(", "path", ",", "info", ",", "err", ")", "\n", "}", "\n", "return", "filepath", ".", "Walk", "(", "root", ",", "wrapper", ")", "\n", "}" ]
// Walk walks the file tree rooted at root, calling walkFn for each file or // directory in the tree, including root.
[ "Walk", "walks", "the", "file", "tree", "rooted", "at", "root", "calling", "walkFn", "for", "each", "file", "or", "directory", "in", "the", "tree", "including", "root", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L352-L360
train
openshift/source-to-image
pkg/util/fs/fs.go
Readlink
func (h *fs) Readlink(name string) (string, error) { return os.Readlink(name) }
go
func (h *fs) Readlink(name string) (string, error) { return os.Readlink(name) }
[ "func", "(", "h", "*", "fs", ")", "Readlink", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "os", ".", "Readlink", "(", "name", ")", "\n", "}" ]
// Readlink reads the destination of a symlink
[ "Readlink", "reads", "the", "destination", "of", "a", "symlink" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L390-L392
train
openshift/source-to-image
pkg/util/fs/fs.go
Symlink
func (h *fs) Symlink(oldname, newname string) error { return os.Symlink(oldname, newname) }
go
func (h *fs) Symlink(oldname, newname string) error { return os.Symlink(oldname, newname) }
[ "func", "(", "h", "*", "fs", ")", "Symlink", "(", "oldname", ",", "newname", "string", ")", "error", "{", "return", "os", ".", "Symlink", "(", "oldname", ",", "newname", ")", "\n", "}" ]
// Symlink creates a symlink at newname, pointing to oldname
[ "Symlink", "creates", "a", "symlink", "at", "newname", "pointing", "to", "oldname" ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/util/fs/fs.go#L395-L397
train
openshift/source-to-image
pkg/api/types.go
AsBinds
func (l *VolumeList) AsBinds() []string { result := make([]string, len(*l)) for index, v := range *l { result[index] = strings.Join([]string{v.Source, v.Destination}, ":") } return result }
go
func (l *VolumeList) AsBinds() []string { result := make([]string, len(*l)) for index, v := range *l { result[index] = strings.Join([]string{v.Source, v.Destination}, ":") } return result }
[ "func", "(", "l", "*", "VolumeList", ")", "AsBinds", "(", ")", "[", "]", "string", "{", "result", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "*", "l", ")", ")", "\n", "for", "index", ",", "v", ":=", "range", "*", "l", "{", "result", "[", "index", "]", "=", "strings", ".", "Join", "(", "[", "]", "string", "{", "v", ".", "Source", ",", "v", ".", "Destination", "}", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// AsBinds converts the list of volume definitions to go-dockerclient compatible // list of bind mounts.
[ "AsBinds", "converts", "the", "list", "of", "volume", "definitions", "to", "go", "-", "dockerclient", "compatible", "list", "of", "bind", "mounts", "." ]
2ba8a349386aff03c26729096b0225a691355fe9
https://github.com/openshift/source-to-image/blob/2ba8a349386aff03c26729096b0225a691355fe9/pkg/api/types.go#L628-L634
train