idx
int64
0
167k
question
stringlengths
60
3.56k
target
stringlengths
5
1.43k
len_question
int64
21
889
len_target
int64
3
529
167,100
func getChildPID ( ppid int ) ( int , error ) { var pid int // If possible, get the child in O(1). Fallback on O(n) when the kernel does not have // either CONFIG_PROC_CHILDREN or CONFIG_CHECKPOINT_RESTORE _ , err := os . Stat ( " " ) if err == nil { b , err := ioutil . ReadFile ( fmt . Sprintf ( " " , ppid , ppid ) ) ...
Returns the pid of the child or ErrChildNotReady if not ready
489
14
167,101
func ( p * Pod ) getAppsHashes ( ) ( [ ] types . Hash , error ) { apps , err := p . getApps ( ) if err != nil { return nil , err } var hashes [ ] types . Hash for _ , a := range apps { hashes = append ( hashes , a . Image . ID ) } return hashes , nil }
getAppsHashes returns a list of the app hashes in the pod
75
14
167,102
func ( p * Pod ) getApps ( ) ( schema . AppList , error ) { _ , pm , err := p . PodManifest ( ) if err != nil { return nil , err } return pm . Apps , nil }
getApps returns a list of apps in the pod
49
10
167,103
func ( p * Pod ) getDirNames ( path string ) ( [ ] string , error ) { dir , err := p . openFile ( path , syscall . O_RDONLY | syscall . O_DIRECTORY ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } defer dir . Close ( ) ld , err := dir . Readdirnames ( 0 ) if err != nil { return nil , errwr...
getDirNames returns the list of names from a pod s directory
126
13
167,104
func ( p * Pod ) Sync ( ) error { cfd , err := p . Fd ( ) if err != nil { return errwrap . Wrap ( fmt . Errorf ( " " , p . UUID . String ( ) ) , err ) } if err := sys . Syncfs ( cfd ) ; err != nil { return errwrap . Wrap ( fmt . Errorf ( " " , p . UUID . String ( ) ) , err ) } return nil }
Sync syncs the pod data . By now it calls a syncfs on the filesystem containing the pod s directory .
100
23
167,105
func WalkPods ( dataDir string , include IncludeMask , f func ( * Pod ) ) error { if err := initPods ( dataDir ) ; err != nil { return err } ls , err := listPods ( dataDir , include ) if err != nil { return errwrap . Wrap ( errors . New ( " " ) , err ) } sort . Strings ( ls ) for _ , uuid := range ls { u , err := types...
WalkPods iterates over the included directories calling function f for every pod found . The pod will be closed after the function f is executed .
355
29
167,106
func ( p * Pod ) PodManifest ( ) ( [ ] byte , * schema . PodManifest , error ) { pmb , err := p . readFile ( " " ) if err != nil { return nil , nil , errwrap . Wrap ( errors . New ( " " ) , err ) } pm := & schema . PodManifest { } if err = pm . UnmarshalJSON ( pmb ) ; err != nil { return nil , nil , errwrap . Wrap ( er...
PodManifest reads the pod manifest returns the raw bytes and the unmarshalled object .
123
18
167,107
func ( p * Pod ) AppImageManifest ( appName string ) ( * schema . ImageManifest , error ) { appACName , err := types . NewACName ( appName ) if err != nil { return nil , err } imb , err := ioutil . ReadFile ( common . AppImageManifestPath ( p . Path ( ) , * appACName ) ) if err != nil { return nil , err } aim := & sche...
AppImageManifest returns an ImageManifest for the app .
148
13
167,108
func ( p * Pod ) CreationTime ( ) ( time . Time , error ) { if ! ( p . isPrepared || p . isRunning ( ) || p . IsAfterRun ( ) ) { return time . Time { } , nil } t , err := p . getModTime ( " " ) if err == nil { return t , nil } if ! os . IsNotExist ( err ) { return t , err } // backwards compatibility with rkt before v1...
CreationTime returns the time when the pod was created . This happens at prepare time .
114
18
167,109
func ( p * Pod ) StartTime ( ) ( time . Time , error ) { var ( t time . Time retErr error ) if ! p . isRunning ( ) && ! p . IsAfterRun ( ) { // hasn't started return t , nil } // check pid and ppid since stage1s can choose one xor the other for _ , ctimeFile := range [ ] string { " " , " " } { t , err := p . getModTime...
StartTime returns the time when the pod was started .
177
11
167,110
func ( p * Pod ) GCMarkedTime ( ) ( time . Time , error ) { if ! p . isGarbage && ! p . isExitedGarbage { return time . Time { } , nil } // At this point, the pod is in either exited-garbage dir, garbage dir or gone already. podPath := p . Path ( ) if podPath == " " { // Pod is gone. return time . Time { } , nil } st :...
GCMarkedTime returns the time when the pod is marked by gc .
175
16
167,111
func ( p * Pod ) Pid ( ) ( int , error ) { if pid , err := p . readIntFromFile ( " " ) ; err == nil { return pid , nil } if pid , err := p . readIntFromFile ( " " ) ; err != nil { return - 1 , err } else { return pid , nil } }
Pid returns the pid of the stage1 process that started the pod .
75
15
167,112
func ( p * Pod ) Stage1RootfsPath ( ) ( string , error ) { stage1RootfsPath := " " if p . UsesOverlay ( ) { stage1TreeStoreID , err := p . GetStage1TreeStoreID ( ) if err != nil { return " " , err } stage1RootfsPath = fmt . Sprintf ( " " , stage1TreeStoreID ) } return filepath . Join ( p . Path ( ) , stage1RootfsPath )...
Stage1RootfsPath returns the stage1 path of the pod .
107
14
167,113
func ( p * Pod ) JournalLogPath ( ) ( string , error ) { stage1RootfsPath , err := p . Stage1RootfsPath ( ) if err != nil { return " " , err } return filepath . Join ( stage1RootfsPath , " " ) , nil }
JournalLogPath returns the path to the journal log dir of the pod .
63
15
167,114
func ( p * Pod ) State ( ) string { switch { case p . isEmbryo : return Embryo case p . isPreparing : return Preparing case p . isAbortedPrepare : return AbortedPrepare case p . isPrepared : return Prepared case p . isDeleting : return Deleting case p . isExitedDeleting : return ExitedDeleting case p . isExited : // th...
State returns the current state of the pod
135
8
167,115
func ( p * Pod ) isRunning ( ) bool { // when none of these things, running! return ! p . isEmbryo && ! p . isAbortedPrepare && ! p . isPreparing && ! p . isPrepared && ! p . isExited && ! p . isExitedGarbage && ! p . isExitedDeleting && ! p . isGarbage && ! p . isDeleting && ! p . isGone }
isRunning does the annoying tests to infer if a pod is in a running state
101
16
167,116
func ( p * Pod ) PodManifestAvailable ( ) bool { if p . isPreparing || p . isAbortedPrepare || p . isDeleting { return false } return true }
PodManifestAvailable returns whether the caller should reasonably expect PodManifest to function in the pod s current state . Namely in Preparing AbortedPrepare and Deleting it s possible for the manifest to not be present
42
45
167,117
func ( p * Pod ) IsAfterRun ( ) bool { return p . isExitedDeleting || p . isDeleting || p . isExited || p . isGarbage }
IsAfterRun returns true if the pod is in a post - running state otherwise it returns false .
42
20
167,118
func ( p * Pod ) IsFinished ( ) bool { return p . isExited || p . isAbortedPrepare || p . isGarbage || p . isGone }
IsFinished returns true if the pod is in a terminal state else false .
40
16
167,119
func ( p * Pod ) AppExitCode ( appName string ) ( int , error ) { stage1RootfsPath , err := p . Stage1RootfsPath ( ) if err != nil { return - 1 , err } statusFile := common . AppStatusPathFromStage1Rootfs ( stage1RootfsPath , appName ) return p . readIntFromFile ( statusFile ) }
AppExitCode returns the app s exit code . It returns an error if the exit code file doesn t exit or the content of the file is invalid .
83
31
167,120
func StopPod ( dir string , force bool , uuid * types . UUID ) error { s1rootfs := common . Stage1RootfsPath ( dir ) if err := os . Chdir ( dir ) ; err != nil { return fmt . Errorf ( " " , err ) } ep , err := getStage1Entrypoint ( dir , stopEntrypoint ) if err != nil { return fmt . Errorf ( " " , err ) } args := [ ] st...
StopPod stops the given pod .
194
7
167,121
func ( c * Config ) MarshalJSON ( ) ( [ ] byte , error ) { stage0 := [ ] interface { } { } for host , auth := range c . AuthPerHost { var typ string var credentials interface { } switch h := auth . ( type ) { case * basicAuthHeaderer : typ = " " credentials = h . auth case * oAuthBearerTokenHeaderer : typ = " " credent...
MarshalJSON marshals the config for user output .
573
11
167,122
func ResolveAuthPerHost ( authPerHost map [ string ] Headerer ) map [ string ] http . Header { hostHeaders := make ( map [ string ] http . Header , len ( authPerHost ) ) for k , v := range authPerHost { hostHeaders [ k ] = v . GetHeader ( ) } return hostHeaders }
ResolveAuthPerHost takes a map of strings to Headerer and resolves the Headerers to http . Headers
75
23
167,123
func GetConfigFrom ( dirs ... string ) ( * Config , error ) { cfg := newConfig ( ) for _ , cd := range dirs { subcfg , err := GetConfigFromDir ( cd ) if err != nil { return nil , err } mergeConfigs ( cfg , subcfg ) } return cfg , nil }
GetConfigFrom gets the Config instance with configuration taken from given paths . Subsequent paths override settings from the previous paths .
72
24
167,124
func GetConfigFromDir ( dir string ) ( * Config , error ) { subcfg := newConfig ( ) if valid , err := validDir ( dir ) ; err != nil { return nil , err } else if ! valid { return subcfg , nil } if err := readConfigDir ( subcfg , dir ) ; err != nil { return nil , err } return subcfg , nil }
GetConfigFromDir gets the Config instance with configuration taken from given directory .
82
15
167,125
func WriteEnvFile ( env [ ] string , uidRange * user . UidRange , envFilePath string ) error { ef := bytes . Buffer { } for _ , v := range env { fmt . Fprintf ( & ef , " \n " , v ) } if err := os . MkdirAll ( filepath . Dir ( envFilePath ) , 0755 ) ; err != nil { return err } if err := ioutil . WriteFile ( envFilePath ...
WriteEnvFile creates an environment file for given app name . To ensure the minimum required environment variables by the appc spec are set to sensible defaults env should be the result of calling ComposeEnviron . The containing directory and its ancestors will be created if necessary .
156
54
167,126
func ComposeEnviron ( env types . Environment ) [ ] string { var composed [ ] string for dk , dv := range defaultEnv { if _ , exists := env . Get ( dk ) ; ! exists { composed = append ( composed , fmt . Sprintf ( " " , dk , dv ) ) } } for _ , e := range env { composed = append ( composed , fmt . Sprintf ( " " , e . Nam...
ComposeEnviron formats the environment into a slice of strings each of the form key = value . The minimum required environment variables by the appc spec will be set to sensible defaults here if they re not provided by env .
106
45
167,127
func ( f mountFlags ) String ( ) string { var s [ ] string maybeAppendFlag := func ( ff uintptr , desc string ) { if uintptr ( f ) & ff != 0 { s = append ( s , desc ) } } maybeAppendFlag ( syscall . MS_DIRSYNC , " " ) maybeAppendFlag ( syscall . MS_MANDLOCK , " " ) maybeAppendFlag ( syscall . MS_NOATIME , " " ) maybeAp...
String returns a human readable representation of mountFlags based on which bits are set . E . g . for a value of syscall . MS_RDONLY|syscall . MS_BIND it will print MS_RDONLY|MS_BIND
425
54
167,128
func newValidator ( image io . ReadSeeker ) ( * validator , error ) { manifest , err := aci . ManifestFromImage ( image ) if err != nil { return nil , err } v := & validator { image : image , manifest : manifest , } return v , nil }
newValidator returns a validator instance if passed image is indeed an ACI .
63
17
167,129
func ( v * validator ) ValidateName ( imageName string ) error { name := v . ImageName ( ) if name != imageName { return fmt . Errorf ( " " , imageName , name ) } return nil }
ValidateName checks if desired image name is actually the same as the one in the image manifest .
49
20
167,130
func ( v * validator ) ValidateLabels ( labels map [ types . ACIdentifier ] string ) error { for n , rv := range labels { if av , ok := v . manifest . GetLabel ( n . String ( ) ) ; ok { if rv != av { return fmt . Errorf ( " " , n , rv , av ) } } else { return fmt . Errorf ( " " , n ) } } return nil }
ValidateLabels checks if desired image labels are actually the same as the ones in the image manifest .
97
21
167,131
func ( v * validator ) ValidateWithSignature ( ks * keystore . Keystore , sig io . ReadSeeker ) ( * openpgp . Entity , error ) { if ks == nil { return nil , nil } if _ , err := v . image . Seek ( 0 , 0 ) ; err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } if _ , err := sig . Seek ( 0 , 0 ) ; err...
ValidateWithSignature verifies the image against a given signature file .
193
15
167,132
func Register ( distType Type , f newDistribution ) { if _ , ok := distributions [ distType ] ; ok { panic ( fmt . Errorf ( " " , distType ) ) } distributions [ distType ] = f }
Register registers a function that returns a new instance of the given distribution . This is intended to be called from the init function in packages that implement distribution functions .
49
31
167,133
func Get ( u * url . URL ) ( Distribution , error ) { c , err := parseCIMD ( u ) if err != nil { return nil , fmt . Errorf ( " " , u . String ( ) , err ) } if u . Scheme != Scheme { return nil , fmt . Errorf ( " " , u . String ( ) ) } if _ , ok := distributions [ c . Type ] ; ! ok { return nil , fmt . Errorf ( " " , c ...
Get returns a Distribution from the input URI . It returns an error if the uri string is wrong or referencing an unknown distribution type .
118
27
167,134
func Parse ( rawuri string ) ( Distribution , error ) { u , err := url . Parse ( rawuri ) if err != nil { return nil , fmt . Errorf ( " " , rawuri , err ) } return Get ( u ) }
Parse parses the provided distribution URI string and returns a Distribution .
54
14
167,135
func newCompletion ( w io . Writer ) func ( * cobra . Command , [ ] string ) int { return func ( cmd * cobra . Command , args [ ] string ) int { return runCompletion ( w , cmd , args ) } }
newCompletion creates a new command with a bounded writer . Writer is used to print the generated shell - completion script which is intended to be consumed by the CLI users .
54
34
167,136
func runCompletion ( w io . Writer , cmd * cobra . Command , args [ ] string ) ( exit int ) { if len ( args ) == 0 { stderr . Print ( " " ) return 254 } if len ( args ) > 1 { stderr . Print ( " " ) return 254 } // Right now only bash completion is supported, but zsh could be // supported in a future as well. completion...
runCompletion is a command handler to generate the shell script with shell completion functions . It ensures that there are enough arguments to generate the completion scripts .
169
30