_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q20900
HasChrootCapability
train
func HasChrootCapability() bool { // Checking the capabilities should be enough, but in case there're // problem retrieving them, fallback checking for the effective uid // (hoping it hasn't dropped its CAP_SYS_CHROOT). caps, err := capability.NewPid(0) if err == nil { return caps.Get(capability.EFFECTIVE, capab...
go
{ "resource": "" }
q20901
LookupGidFromFile
train
func LookupGidFromFile(groupName, groupFile string) (gid int, err error) { groups, err := parseGroupFile(groupFile) if err != nil { return -1, errwrap.Wrap(fmt.Errorf("error parsing %q file", groupFile), err) } group, ok := groups[groupName] if !ok { return -1, fmt.Errorf("%q group not found", groupName) } ...
go
{ "resource": "" }
q20902
TryExclusiveKeyLock
train
func TryExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) { return createAndLock(lockDir, key, keyLockExclusive|keyLockNonBlocking) }
go
{ "resource": "" }
q20903
ExclusiveKeyLock
train
func ExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) { return createAndLock(lockDir, key, keyLockExclusive) }
go
{ "resource": "" }
q20904
Unlock
train
func (l *KeyLock) Unlock() error { err := l.keyLock.Unlock() if err != nil { return err } return nil }
go
{ "resource": "" }
q20905
CleanKeyLocks
train
func CleanKeyLocks(lockDir string) error { f, err := os.Open(lockDir) if err != nil { return errwrap.Wrap(errors.New("error opening lockDir"), err) } defer f.Close() files, err := f.Readdir(0) if err != nil { return errwrap.Wrap(errors.New("error getting lock files list"), err) } for _, f := range files { ...
go
{ "resource": "" }
q20906
GetPubKeyLocations
train
func (m *Manager) GetPubKeyLocations(prefix string) ([]string, error) { ensureLogger(m.Debug) if prefix == "" { return nil, fmt.Errorf("empty prefix") } kls, err := m.metaDiscoverPubKeyLocations(prefix) if err != nil { return nil, errwrap.Wrap(errors.New("prefix meta discovery error"), err) } if len(kls) =...
go
{ "resource": "" }
q20907
AddKeys
train
func (m *Manager) AddKeys(pkls []string, prefix string, accept AcceptOption) error { ensureLogger(m.Debug) if m.Ks == nil { return fmt.Errorf("no keystore available to add keys to") } for _, pkl := range pkls { u, err := url.Parse(pkl) if err != nil { return err } pk, err := m.getPubKey(u) if err !=...
go
{ "resource": "" }
q20908
metaDiscoverPubKeyLocations
train
func (m *Manager) metaDiscoverPubKeyLocations(prefix string) ([]string, error) { app, err := discovery.NewAppFromString(prefix) if err != nil { return nil, err } hostHeaders := config.ResolveAuthPerHost(m.AuthPerHost) insecure := discovery.InsecureNone if m.InsecureAllowHTTP { insecure = insecure | discovery...
go
{ "resource": "" }
q20909
downloadKey
train
func downloadKey(u *url.URL, skipTLSCheck bool) (*os.File, error) { tf, err := ioutil.TempFile("", "") if err != nil { return nil, errwrap.Wrap(errors.New("error creating tempfile"), err) } os.Remove(tf.Name()) // no need to keep the tempfile around defer func() { if tf != nil { tf.Close() } }() // TO...
go
{ "resource": "" }
q20910
displayKey
train
func displayKey(prefix, location string, key *os.File) error { defer key.Seek(0, os.SEEK_SET) kr, err := openpgp.ReadArmoredKeyRing(key) if err != nil { return errwrap.Wrap(errors.New("error reading key"), err) } log.Printf("prefix: %q\nkey: %q", prefix, location) for _, k := range kr { stdout.Printf("gpg k...
go
{ "resource": "" }
q20911
reviewKey
train
func reviewKey() (bool, error) { in := bufio.NewReader(os.Stdin) for { stdout.Printf("Are you sure you want to trust this key (yes/no)?") input, err := in.ReadString('\n') if err != nil { return false, errwrap.Wrap(errors.New("error reading input"), err) } switch input { case "yes\n": return true, n...
go
{ "resource": "" }
q20912
setupTapDevice
train
func setupTapDevice(podID types.UUID) (netlink.Link, error) { // network device names are limited to 16 characters // the suffix %d will be replaced by the kernel with a suitable number nameTemplate := fmt.Sprintf("rkt-%s-tap%%d", podID.String()[0:4]) ifName, err := tuntap.CreatePersistentIface(nameTemplate, tuntap...
go
{ "resource": "" }
q20913
setupMacVTapDevice
train
func setupMacVTapDevice(podID types.UUID, config MacVTapNetConf, interfaceNumber int) (netlink.Link, error) { master, err := netlink.LinkByName(config.Master) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("cannot find master device '%v'", config.Master), err) } var mode netlink.MacvlanMode switch config.Mo...
go
{ "resource": "" }
q20914
kvmTeardown
train
func (n *Networking) kvmTeardown() { if err := n.teardownForwarding(); err != nil { stderr.PrintE("error removing forwarded ports (kvm)", err) } n.teardownKvmNets() }
go
{ "resource": "" }
q20915
Hash
train
func (f *fileFetcher) Hash(aciPath string, a *asc) (string, error) { ensureLogger(f.Debug) absPath, err := filepath.Abs(aciPath) if err != nil { return "", errwrap.Wrap(fmt.Errorf("failed to get an absolute path for %q", aciPath), err) } aciPath = absPath aciFile, err := f.getFile(aciPath, a) if err != nil { ...
go
{ "resource": "" }
q20916
getVerifiedFile
train
func (f *fileFetcher) getVerifiedFile(aciPath string, a *asc) (*os.File, error) { var aciFile *os.File // closed on error var errClose error // error signaling to close aciFile f.maybeOverrideAsc(aciPath, a) ascFile, err := a.Get() if err != nil { return nil, errwrap.Wrap(errors.New("error opening signature f...
go
{ "resource": "" }
q20917
NewLoggingMounter
train
func NewLoggingMounter(m Mounter, um Unmounter, logf func(string, ...interface{})) MountUnmounter { return &loggingMounter{m, um, logf} }
go
{ "resource": "" }
q20918
Extend
train
func Extend(description string) error { connection := tpmclient.New("localhost:12041", timeout) err := connection.Extend(15, 0x1000, nil, description) return err }
go
{ "resource": "" }
q20919
Stage1RootfsPath
train
func Stage1RootfsPath(root string) string { return filepath.Join(Stage1ImagePath(root), aci.RootfsDir) }
go
{ "resource": "" }
q20920
Stage1ManifestPath
train
func Stage1ManifestPath(root string) string { return filepath.Join(Stage1ImagePath(root), aci.ManifestFile) }
go
{ "resource": "" }
q20921
AppStatusPath
train
func AppStatusPath(root, appName string) string { return filepath.Join(AppsStatusesPath(root), appName) }
go
{ "resource": "" }
q20922
AppStatusPathFromStage1Rootfs
train
func AppStatusPathFromStage1Rootfs(rootfs, appName string) string { return filepath.Join(AppsStatusesPathFromStage1Rootfs(rootfs), appName) }
go
{ "resource": "" }
q20923
AppPath
train
func AppPath(root string, appName types.ACName) string { return filepath.Join(AppsPath(root), appName.String()) }
go
{ "resource": "" }
q20924
AppRootfsPath
train
func AppRootfsPath(root string, appName types.ACName) string { return filepath.Join(AppPath(root, appName), aci.RootfsDir) }
go
{ "resource": "" }
q20925
RelAppPath
train
func RelAppPath(appName types.ACName) string { return filepath.Join(stage2Dir, appName.String()) }
go
{ "resource": "" }
q20926
RelAppRootfsPath
train
func RelAppRootfsPath(appName types.ACName) string { return filepath.Join(RelAppPath(appName), aci.RootfsDir) }
go
{ "resource": "" }
q20927
ImageManifestPath
train
func ImageManifestPath(root string, appName types.ACName) string { return filepath.Join(AppPath(root, appName), aci.ManifestFile) }
go
{ "resource": "" }
q20928
AppInfoPath
train
func AppInfoPath(root string, appName types.ACName) string { return filepath.Join(AppsInfoPath(root), appName.String()) }
go
{ "resource": "" }
q20929
AppTreeStoreIDPath
train
func AppTreeStoreIDPath(root string, appName types.ACName) string { return filepath.Join(AppInfoPath(root, appName), AppTreeStoreIDFilename) }
go
{ "resource": "" }
q20930
AppImageManifestPath
train
func AppImageManifestPath(root string, appName types.ACName) string { return filepath.Join(AppInfoPath(root, appName), aci.ManifestFile) }
go
{ "resource": "" }
q20931
CreateSharedVolumesPath
train
func CreateSharedVolumesPath(root string) (string, error) { sharedVolPath := SharedVolumesPath(root) if err := os.MkdirAll(sharedVolPath, SharedVolumePerm); err != nil { return "", errwrap.Wrap(errors.New("could not create shared volumes directory"), err) } // In case it already existed and we didn't make it, en...
go
{ "resource": "" }
q20932
MetadataServicePublicURL
train
func MetadataServicePublicURL(ip net.IP, token string) string { return fmt.Sprintf("http://%v:%v/%v", ip, MetadataServicePort, token) }
go
{ "resource": "" }
q20933
LookupPath
train
func LookupPath(bin string, paths string) (string, error) { pathsArr := filepath.SplitList(paths) for _, path := range pathsArr { binPath := filepath.Join(path, bin) binAbsPath, err := filepath.Abs(binPath) if err != nil { return "", fmt.Errorf("unable to find absolute path for %s", binPath) } if fileuti...
go
{ "resource": "" }
q20934
SystemdVersion
train
func SystemdVersion(systemdBinaryPath string) (int, error) { versionBytes, err := exec.Command(systemdBinaryPath, "--version").CombinedOutput() if err != nil { return -1, errwrap.Wrap(fmt.Errorf("unable to probe %s version", systemdBinaryPath), err) } versionStr := strings.SplitN(string(versionBytes), "\n", 2)[0]...
go
{ "resource": "" }
q20935
SupportsOverlay
train
func SupportsOverlay() error { // ignore exec.Command error, modprobe may not be present on the system, // or the kernel module will fail to load. // we'll find out by reading the side effect in /proc/filesystems _ = exec.Command("modprobe", "overlay").Run() f, err := os.Open("/proc/filesystems") if err != nil {...
go
{ "resource": "" }
q20936
RemoveEmptyLines
train
func RemoveEmptyLines(str string) []string { lines := make([]string, 0) for _, v := range strings.Split(str, "\n") { if len(v) > 0 { lines = append(lines, v) } } return lines }
go
{ "resource": "" }
q20937
GetExitStatus
train
func GetExitStatus(err error) (int, error) { if err == nil { return 0, nil } if exiterr, ok := err.(*exec.ExitError); ok { // the program has exited with an exit code != 0 if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { return status.ExitStatus(), nil } } return -1, err }
go
{ "resource": "" }
q20938
ImageNameToAppName
train
func ImageNameToAppName(name types.ACIdentifier) (*types.ACName, error) { parts := strings.Split(name.String(), "/") last := parts[len(parts)-1] sn, err := types.SanitizeACName(last) if err != nil { return nil, err } return types.MustACName(sn), nil }
go
{ "resource": "" }
q20939
GetNetworkDescriptions
train
func GetNetworkDescriptions(n *networking.Networking) []NetDescriber { var nds []NetDescriber for _, an := range n.GetActiveNetworks() { nds = append(nds, an) } return nds }
go
{ "resource": "" }
q20940
GetKVMNetArgs
train
func GetKVMNetArgs(nds []NetDescriber) ([]string, error) { var lkvmArgs []string for _, nd := range nds { lkvmArgs = append(lkvmArgs, "--network") lkvmArg := fmt.Sprintf("mode=tap,tapif=%s,host_ip=%s,guest_ip=%s", nd.IfName(), nd.Gateway(), nd.GuestIP()) lkvmArgs = append(lkvmArgs, lkvmArg) } return lkvmAr...
go
{ "resource": "" }
q20941
generateMacAddress
train
func generateMacAddress() (net.HardwareAddr, error) { mac := []byte{ 2, // locally administered unicast 0x65, 0x02, // OUI (randomly chosen by jell) 0, 0, 0, // bytes to randomly overwrite } _, err := rand.Read(mac[3:6]) if err != nil { return nil, errwrap.Wrap(errors.New("cannot generate random m...
go
{ "resource": "" }
q20942
replacePlaceholders
train
func replacePlaceholders(str string, kv ...string) string { for ph, value := range toMap(kv...) { str = strings.Replace(str, "!!!"+ph+"!!!", value, -1) } return str }
go
{ "resource": "" }
q20943
standardFlags
train
func standardFlags(cmd string) (*flag.FlagSet, *string) { f := flag.NewFlagSet(appName()+" "+cmd, flag.ExitOnError) target := f.String("target", "", "Make target (example: $(FOO_BINARY))") return f, target }
go
{ "resource": "" }
q20944
netPluginAdd
train
func (e *podEnv) netPluginAdd(n *activeNet, netns string) error { output, err := e.execNetPlugin("ADD", n, netns) if err != nil { return pluginErr(err, output) } pr := cnitypes.Result{} if err = json.Unmarshal(output, &pr); err != nil { err = errwrap.Wrap(fmt.Errorf("parsing %q", string(output)), err) retur...
go
{ "resource": "" }
q20945
copyPod
train
func copyPod(pod *v1alpha.Pod) *v1alpha.Pod { p := &v1alpha.Pod{ Id: pod.Id, Manifest: pod.Manifest, Annotations: pod.Annotations, } for _, app := range pod.Apps { p.Apps = append(p.Apps, &v1alpha.App{ Name: app.Name, Image: app.Image, Annotations: app.Annotations, }) } ...
go
{ "resource": "" }
q20946
copyImage
train
func copyImage(img *v1alpha.Image) *v1alpha.Image { return &v1alpha.Image{ BaseFormat: img.BaseFormat, Id: img.Id, Name: img.Name, Version: img.Version, ImportTimestamp: img.ImportTimestamp, Manifest: img.Manifest, Size: img.Size, Annotations: ...
go
{ "resource": "" }
q20947
GetInfo
train
func (s *v1AlphaAPIServer) GetInfo(context.Context, *v1alpha.GetInfoRequest) (*v1alpha.GetInfoResponse, error) { return &v1alpha.GetInfoResponse{ Info: &v1alpha.Info{ RktVersion: version.Version, AppcVersion: schema.AppContainerVersion.String(), ApiVersion: supportedAPIVersion, GlobalFlags: &v1alpha.Gl...
go
{ "resource": "" }
q20948
containsAllKeyValues
train
func containsAllKeyValues(actualKVs []*v1alpha.KeyValue, requiredKVs []*v1alpha.KeyValue) bool { for _, requiredKV := range requiredKVs { actualValue, ok := findInKeyValues(actualKVs, requiredKV.Key) if !ok || actualValue != requiredKV.Value { return false } } return true }
go
{ "resource": "" }
q20949
satisfiesPodFilter
train
func satisfiesPodFilter(pod v1alpha.Pod, filter v1alpha.PodFilter) bool { // Filter according to the ID. if len(filter.Ids) > 0 { s := set.NewString(filter.Ids...) if !s.Has(pod.Id) { return false } } // Filter according to the state. if len(filter.States) > 0 { foundState := false for _, state := ra...
go
{ "resource": "" }
q20950
satisfiesAnyPodFilters
train
func satisfiesAnyPodFilters(pod *v1alpha.Pod, filters []*v1alpha.PodFilter) bool { // No filters, return true directly. if len(filters) == 0 { return true } for _, filter := range filters { if satisfiesPodFilter(*pod, *filter) { return true } } return false }
go
{ "resource": "" }
q20951
getApplist
train
func getApplist(manifest *schema.PodManifest) []*v1alpha.App { var apps []*v1alpha.App for _, app := range manifest.Apps { img := &v1alpha.Image{ BaseFormat: &v1alpha.ImageFormat{ // Only support appc image now. If it's a docker image, then it // will be transformed to appc before storing in the disk sto...
go
{ "resource": "" }
q20952
getNetworks
train
func getNetworks(p *pkgPod.Pod) []*v1alpha.Network { var networks []*v1alpha.Network for _, n := range p.Nets { networks = append(networks, &v1alpha.Network{ Name: n.NetName, // There will be IPv6 support soon so distinguish between v4 and v6 Ipv4: n.IP.String(), }) } return networks }
go
{ "resource": "" }
q20953
fillStaticAppInfo
train
func fillStaticAppInfo(store *imagestore.Store, pod *pkgPod.Pod, v1pod *v1alpha.Pod) error { var errlist []error // Fill static app image info. for _, app := range v1pod.Apps { // Fill app's image info. app.Image = &v1alpha.Image{ BaseFormat: &v1alpha.ImageFormat{ // Only support appc image now. If it's ...
go
{ "resource": "" }
q20954
getBasicPod
train
func (s *v1AlphaAPIServer) getBasicPod(p *pkgPod.Pod) *v1alpha.Pod { mtime, mtimeErr := getPodManifestModTime(p) if mtimeErr != nil { stderr.PrintE(fmt.Sprintf("failed to read the pod manifest's mtime for pod %q", p.UUID), mtimeErr) } // Couldn't use pod.uuid directly as it's a pointer. itemValue, found := s.po...
go
{ "resource": "" }
q20955
aciInfoToV1AlphaAPIImage
train
func aciInfoToV1AlphaAPIImage(store *imagestore.Store, aciInfo *imagestore.ACIInfo) (*v1alpha.Image, error) { manifest, err := store.GetImageManifestJSON(aciInfo.BlobKey) if err != nil { stderr.PrintE("failed to read the image manifest", err) return nil, err } var im schema.ImageManifest if err = json.Unmarsh...
go
{ "resource": "" }
q20956
satisfiesImageFilter
train
func satisfiesImageFilter(image v1alpha.Image, filter v1alpha.ImageFilter) bool { // Filter according to the IDs. if len(filter.Ids) > 0 { s := set.NewString(filter.Ids...) if !s.Has(image.Id) { return false } } // Filter according to the image full names. if len(filter.FullNames) > 0 { s := set.NewStr...
go
{ "resource": "" }
q20957
satisfiesAnyImageFilters
train
func satisfiesAnyImageFilters(image *v1alpha.Image, filters []*v1alpha.ImageFilter) bool { // No filters, return true directly. if len(filters) == 0 { return true } for _, filter := range filters { if satisfiesImageFilter(*image, *filter) { return true } } return false }
go
{ "resource": "" }
q20958
runAPIService
train
func runAPIService(cmd *cobra.Command, args []string) (exit int) { // Set up the signal handler here so we can make sure the // signals are caught after print the starting message. signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM) stderr.Print("API service starting...") listeners, err := openAPISockets() i...
go
{ "resource": "" }
q20959
WriteUnit
train
func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) { if uw.err != nil { return } file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { uw.err = errwrap.Wrap(errors.New(errmsg), err) return } defer file.Close() if _, err = io.Copy(file,...
go
{ "resource": "" }
q20960
writeShutdownService
train
func (uw *UnitWriter) writeShutdownService(exec string, opts ...*unit.UnitOption) { if uw.err != nil { return } flavor, systemdVersion, err := GetFlavor(uw.p) if err != nil { uw.err = errwrap.Wrap(errors.New("failed to create shutdown service"), err) return } opts = append(opts, []*unit.UnitOption{ // T...
go
{ "resource": "" }
q20961
Activate
train
func (uw *UnitWriter) Activate(unit, wantPath string) { if uw.err != nil { return } if err := os.Symlink(path.Join("..", unit), wantPath); err != nil && !os.IsExist(err) { uw.err = errwrap.Wrap(errors.New("failed to link service want"), err) } }
go
{ "resource": "" }
q20962
AppUnit
train
func (uw *UnitWriter) AppUnit(ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) { if uw.err != nil { return } if len(ra.App.Exec) == 0 { uw.err = fmt.Errorf(`image %q has an empty "exec" (try --exec=BINARY)`, uw.p.AppNameToImageName(ra.Name)) return } pa, err := prepareApp(uw.p, ra) if e...
go
{ "resource": "" }
q20963
AppReaperUnit
train
func (uw *UnitWriter) AppReaperUnit(appName types.ACName, binPath string, opts ...*unit.UnitOption) { if uw.err != nil { return } opts = append(opts, []*unit.UnitOption{ unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s Reaper", appName)), unit.NewUnitOption("Unit", "DefaultDependencies", "false"), ...
go
{ "resource": "" }
q20964
AppSocketUnit
train
func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, streamName string, opts ...*unit.UnitOption) { opts = append(opts, []*unit.UnitOption{ unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s socket for %s", streamName, appName)), unit.NewUnitOption("Unit", "DefaultDependencies", "no"), ...
go
{ "resource": "" }
q20965
appendOptionsList
train
func appendOptionsList(opts []*unit.UnitOption, section, property, prefix string, vals ...string) []*unit.UnitOption { for _, v := range vals { opts = append(opts, unit.NewUnitOption(section, property, fmt.Sprintf("%s%s", prefix, v))) } return opts }
go
{ "resource": "" }
q20966
AppsForPod
train
func AppsForPod(uuid, dataDir string, appName string) ([]*v1.App, error) { p, err := pkgPod.PodFromUUIDString(dataDir, uuid) if err != nil { return nil, err } defer p.Close() return appsForPod(p, appName, appStateInMutablePod) }
go
{ "resource": "" }
q20967
newApp
train
func newApp(ra *schema.RuntimeApp, podManifest *schema.PodManifest, pod *pkgPod.Pod, appState appStateFunc) (*v1.App, error) { app := &v1.App{ Name: ra.Name.String(), ImageID: ra.Image.ID.String(), UserAnnotations: ra.App.UserAnnotations, UserLabels: ra.App.UserLabels, } podVols := p...
go
{ "resource": "" }
q20968
appStateInImmutablePod
train
func appStateInImmutablePod(app *v1.App, pod *pkgPod.Pod) error { app.State = appStateFromPod(pod) t, err := pod.CreationTime() if err != nil { return err } createdAt := t.UnixNano() app.CreatedAt = &createdAt code, err := pod.AppExitCode(app.Name) if err == nil { // there is an exit code, it is definitel...
go
{ "resource": "" }
q20969
SaveRuntime
train
func (p *Pod) SaveRuntime() error { path := filepath.Join(p.Root, RuntimeConfigPath) buf, err := json.Marshal(p.RuntimePod) if err != nil { return err } return ioutil.WriteFile(path, buf, 0644) }
go
{ "resource": "" }
q20970
LoadPodManifest
train
func LoadPodManifest(root string) (*schema.PodManifest, error) { buf, err := ioutil.ReadFile(common.PodManifestPath(root)) if err != nil { return nil, errwrap.Wrap(errors.New("failed reading pod manifest"), err) } pm := &schema.PodManifest{} if err := json.Unmarshal(buf, pm); err != nil { return nil, errwrap....
go
{ "resource": "" }
q20971
FetchImages
train
func (f *Fetcher) FetchImages(al *apps.Apps) error { return al.Walk(func(app *apps.App) error { d, err := DistFromImageString(app.Image) if err != nil { return err } h, err := f.FetchImage(d, app.Image, app.Asc) if err != nil { return err } app.ImageID = *h return nil }) }
go
{ "resource": "" }
q20972
FetchImage
train
func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) { ensureLogger(f.Debug) db := &distBundle{ dist: d, image: image, } a := f.getAsc(ascPath) hash, err := f.fetchSingleImage(db, a) if err != nil { return nil, err } if f.WithDeps { err = f.fetchImageDeps(hash) ...
go
{ "resource": "" }
q20973
fetchImageDeps
train
func (f *Fetcher) fetchImageDeps(hash string) error { imgsl := list.New() seen := map[string]dist.Distribution{} f.addImageDeps(hash, imgsl, seen) for el := imgsl.Front(); el != nil; el = el.Next() { a := &asc{} d := el.Value.(*dist.Appc) str := d.String() db := &distBundle{ dist: d, image: str, } ...
go
{ "resource": "" }
q20974
New
train
func New(out io.Writer, prefix string, debug bool) *Logger { l := &Logger{ debug: debug, Logger: log.New(out, prefix, 0), } l.SetFlags(0) return l }
go
{ "resource": "" }
q20975
Error
train
func (l *Logger) Error(e error) { l.Print(l.formatErr(e, "")) }
go
{ "resource": "" }
q20976
Errorf
train
func (l *Logger) Errorf(format string, a ...interface{}) { l.Print(l.formatErr(fmt.Errorf(format, a...), "")) }
go
{ "resource": "" }
q20977
PanicE
train
func (l *Logger) PanicE(msg string, e error) { l.Panic(l.formatErr(e, msg)) }
go
{ "resource": "" }
q20978
Warn
train
func Warn(format string, values ...interface{}) { fmt.Fprintf(os.Stderr, fmt.Sprintf("%s%c", format, '\n'), values...) }
go
{ "resource": "" }
q20979
MustAbs
train
func MustAbs(dir string) string { absDir, err := filepath.Abs(dir) if err != nil { panic(fmt.Sprintf("Failed to get absolute path of a directory %q: %v\n", dir, err)) } return filepath.Clean(absDir) }
go
{ "resource": "" }
q20980
parseDuration
train
func parseDuration(s string) (time.Duration, error) { if s == "" { return time.Duration(-1), nil } b, err := strconv.ParseBool(s) switch { case err != nil: return time.ParseDuration(s) case b: return time.Duration(-1), nil } return time.Duration(0), nil }
go
{ "resource": "" }
q20981
newContext
train
func newContext(t time.Duration) context.Context { ctx := context.Background() if t > 0 { ctx, _ = context.WithTimeout(ctx, t) } return ctx }
go
{ "resource": "" }
q20982
getExitStatuses
train
func getExitStatuses(p *pkgPod.Pod) (map[string]int, error) { _, manifest, err := p.PodManifest() if err != nil { return nil, err } stats := make(map[string]int) for _, app := range manifest.Apps { exitCode, err := p.AppExitCode(app.Name.String()) if err != nil { continue } stats[app.Name.String()] =...
go
{ "resource": "" }
q20983
printStatus
train
func printStatus(p *pkgPod.Pod) error { if flagFormat != outputFormatTabbed { pod, err := lib.NewPodFromInternalPod(p) if err != nil { return fmt.Errorf("error converting pod: %v", err) } switch flagFormat { case outputFormatJSON: result, err := json.Marshal(pod) if err != nil { return fmt.Error...
go
{ "resource": "" }
q20984
ascURLFromImgURL
train
func ascURLFromImgURL(u *url.URL) *url.URL { copy := *u copy.Path = ascPathFromImgPath(copy.Path) return &copy }
go
{ "resource": "" }
q20985
printIdentities
train
func printIdentities(entity *openpgp.Entity) { lines := []string{"signature verified:"} for _, v := range entity.Identities { lines = append(lines, fmt.Sprintf(" %s", v.Name)) } log.Print(strings.Join(lines, "\n")) }
go
{ "resource": "" }
q20986
DistFromImageString
train
func DistFromImageString(is string) (dist.Distribution, error) { u, err := url.Parse(is) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("failed to parse image url %q", is), err) } // Convert user friendly image string names to internal distribution URIs // file:///full/path/to/aci/file.aci -> archive:aci:f...
go
{ "resource": "" }
q20987
parseCIMD
train
func parseCIMD(u *url.URL) (*cimd, error) { if u.Scheme != Scheme { return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme) } parts := strings.SplitN(u.Opaque, ":", 3) if len(parts) < 3 { return nil, fmt.Errorf("malformed distribution uri: %q", u.String()) } version, err := strconv.ParseUint(strings.TrimPr...
go
{ "resource": "" }
q20988
NewCIMDString
train
func NewCIMDString(typ Type, version uint32, data string) string { return fmt.Sprintf("%s:%s:v=%d:%s", Scheme, typ, version, data) }
go
{ "resource": "" }
q20989
getApp
train
func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) { _, manifest, err := p.PodManifest() if err != nil { return nil, errwrap.Wrap(errors.New("problem getting the pod's manifest"), err) } apps := manifest.Apps if flagExportAppName != "" { exportAppName, err := types.NewACName(flagExportAppName) if err !...
go
{ "resource": "" }
q20990
mountOverlay
train
func mountOverlay(pod *pkgPod.Pod, app *schema.RuntimeApp, dest string) error { if _, err := os.Stat(dest); err != nil { return err } s, err := imagestore.NewStore(getDataDir()) if err != nil { return errwrap.Wrap(errors.New("cannot open store"), err) } ts, err := treestore.NewStore(treeStoreDir(), s) if e...
go
{ "resource": "" }
q20991
buildAci
train
func buildAci(root, manifestPath, target string, uidRange *user.UidRange) (e error) { mode := os.O_CREATE | os.O_WRONLY if flagOverwriteACI { mode |= os.O_TRUNC } else { mode |= os.O_EXCL } aciFile, err := os.OpenFile(target, mode, 0644) if err != nil { if os.IsExist(err) { return errors.New("target file...
go
{ "resource": "" }
q20992
ensureSuperuser
train
func ensureSuperuser(cf func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) { if os.Geteuid() != 0 { stderr.Print("cannot run as unprivileged user") cmdExitCode = 254 return } cf(cmd, args) } }
go
{ "resource": "" }
q20993
generateSeccompFilter
train
func generateSeccompFilter(p *stage1commontypes.Pod, pa *preparedApp) (*seccompFilter, error) { sf := seccompFilter{} seenIsolators := 0 for _, i := range pa.app.App.Isolators { var flag string var err error if seccomp, ok := i.Value().(types.LinuxSeccompSet); ok { seenIsolators++ // By appc spec, only o...
go
{ "resource": "" }
q20994
seccompUnitOptions
train
func seccompUnitOptions(opts []*unit.UnitOption, sf *seccompFilter) ([]*unit.UnitOption, error) { if sf == nil { return opts, nil } if sf.errno != "" { opts = append(opts, unit.NewUnitOption("Service", "SystemCallErrorNumber", sf.errno)) } var filterPrefix string switch sf.mode { case ModeWhitelist: filte...
go
{ "resource": "" }
q20995
parseLinuxSeccompSet
train
func parseLinuxSeccompSet(p *stage1commontypes.Pod, s types.LinuxSeccompSet) (syscallFilter []string, flag string, err error) { for _, item := range s.Set() { if item[0] == '@' { // Wildcards wildcard := strings.SplitN(string(item), "/", 2) if len(wildcard) != 2 { continue } scope := wildcard[0] ...
go
{ "resource": "" }
q20996
main
train
func main() { flag.Parse() stage1initcommon.InitDebug(debug) log, diag, _ = rktlog.NewLogSet("app-rm", debug) if !debug { diag.SetOutput(ioutil.Discard) } appName, err := types.NewACName(flagApp) if err != nil { log.FatalE("invalid app name", err) } enterCmd := stage1common.PrepareEnterCmd(false) swit...
go
{ "resource": "" }
q20997
cleanupStage1
train
func cleanupStage1(appName *types.ACName, enterCmd []string) error { // TODO(lucab): re-evaluate once/if we support systemd as non-pid1 (eg. host pid-ns inheriting) mnts, err := mountinfo.ParseMounts(1) if err != nil { return err } appRootFs := filepath.Join("/opt/stage2", appName.String(), "rootfs") mnts = mnt...
go
{ "resource": "" }
q20998
renameExited
train
func renameExited() error { if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeRunDir, func(p *pkgPod.Pod) { if p.State() == pkgPod.Exited { stderr.Printf("moving pod %q to garbage", p.UUID) if err := p.ToExitedGarbage(); err != nil && err != os.ErrNotExist { stderr.PrintE("rename error", err) } } ...
go
{ "resource": "" }
q20999
renameAborted
train
func renameAborted() error { if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludePrepareDir, func(p *pkgPod.Pod) { if p.State() == pkgPod.AbortedPrepare { stderr.Printf("moving failed prepare %q to garbage", p.UUID) if err := p.ToGarbage(); err != nil && err != os.ErrNotExist { stderr.PrintE("rename erro...
go
{ "resource": "" }