id
int32 0
167k
| 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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
143,500 |
cloudfoundry/bosh-cli
|
installation/mocks/mocks.go
|
From
|
func (mr *MockJobResolverMockRecorder) From(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "From", reflect.TypeOf((*MockJobResolver)(nil).From), arg0)
}
|
go
|
func (mr *MockJobResolverMockRecorder) From(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "From", reflect.TypeOf((*MockJobResolver)(nil).From), arg0)
}
|
[
"func",
"(",
"mr",
"*",
"MockJobResolverMockRecorder",
")",
"From",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockJobResolver",
")",
"(",
"nil",
")",
".",
"From",
")",
",",
"arg0",
")",
"\n",
"}"
] |
// From indicates an expected call of From
|
[
"From",
"indicates",
"an",
"expected",
"call",
"of",
"From"
] |
0ee5b2abedb27e521dc6e70719023e7b382cab79
|
https://github.com/cloudfoundry/bosh-cli/blob/0ee5b2abedb27e521dc6e70719023e7b382cab79/installation/mocks/mocks.go#L250-L252
|
143,501 |
cloudfoundry/bosh-cli
|
installation/mocks/mocks.go
|
NewMockPackageCompiler
|
func NewMockPackageCompiler(ctrl *gomock.Controller) *MockPackageCompiler {
mock := &MockPackageCompiler{ctrl: ctrl}
mock.recorder = &MockPackageCompilerMockRecorder{mock}
return mock
}
|
go
|
func NewMockPackageCompiler(ctrl *gomock.Controller) *MockPackageCompiler {
mock := &MockPackageCompiler{ctrl: ctrl}
mock.recorder = &MockPackageCompilerMockRecorder{mock}
return mock
}
|
[
"func",
"NewMockPackageCompiler",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockPackageCompiler",
"{",
"mock",
":=",
"&",
"MockPackageCompiler",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockPackageCompilerMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] |
// NewMockPackageCompiler creates a new mock instance
|
[
"NewMockPackageCompiler",
"creates",
"a",
"new",
"mock",
"instance"
] |
0ee5b2abedb27e521dc6e70719023e7b382cab79
|
https://github.com/cloudfoundry/bosh-cli/blob/0ee5b2abedb27e521dc6e70719023e7b382cab79/installation/mocks/mocks.go#L266-L270
|
143,502 |
cloudfoundry/bosh-cli
|
installation/mocks/mocks.go
|
For
|
func (mr *MockPackageCompilerMockRecorder) For(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "For", reflect.TypeOf((*MockPackageCompiler)(nil).For), arg0, arg1)
}
|
go
|
func (mr *MockPackageCompilerMockRecorder) For(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "For", reflect.TypeOf((*MockPackageCompiler)(nil).For), arg0, arg1)
}
|
[
"func",
"(",
"mr",
"*",
"MockPackageCompilerMockRecorder",
")",
"For",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockPackageCompiler",
")",
"(",
"nil",
")",
".",
"For",
")",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] |
// For indicates an expected call of For
|
[
"For",
"indicates",
"an",
"expected",
"call",
"of",
"For"
] |
0ee5b2abedb27e521dc6e70719023e7b382cab79
|
https://github.com/cloudfoundry/bosh-cli/blob/0ee5b2abedb27e521dc6e70719023e7b382cab79/installation/mocks/mocks.go#L286-L288
|
143,503 |
cloudfoundry/bosh-cli
|
installation/mocks/mocks.go
|
RenderAndUploadFrom
|
func (m *MockJobRenderer) RenderAndUploadFrom(arg0 manifest.Manifest, arg1 []job.Job, arg2 ui.Stage) ([]installation.RenderedJobRef, error) {
ret := m.ctrl.Call(m, "RenderAndUploadFrom", arg0, arg1, arg2)
ret0, _ := ret[0].([]installation.RenderedJobRef)
ret1, _ := ret[1].(error)
return ret0, ret1
}
|
go
|
func (m *MockJobRenderer) RenderAndUploadFrom(arg0 manifest.Manifest, arg1 []job.Job, arg2 ui.Stage) ([]installation.RenderedJobRef, error) {
ret := m.ctrl.Call(m, "RenderAndUploadFrom", arg0, arg1, arg2)
ret0, _ := ret[0].([]installation.RenderedJobRef)
ret1, _ := ret[1].(error)
return ret0, ret1
}
|
[
"func",
"(",
"m",
"*",
"MockJobRenderer",
")",
"RenderAndUploadFrom",
"(",
"arg0",
"manifest",
".",
"Manifest",
",",
"arg1",
"[",
"]",
"job",
".",
"Job",
",",
"arg2",
"ui",
".",
"Stage",
")",
"(",
"[",
"]",
"installation",
".",
"RenderedJobRef",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"installation",
".",
"RenderedJobRef",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] |
// RenderAndUploadFrom mocks base method
|
[
"RenderAndUploadFrom",
"mocks",
"base",
"method"
] |
0ee5b2abedb27e521dc6e70719023e7b382cab79
|
https://github.com/cloudfoundry/bosh-cli/blob/0ee5b2abedb27e521dc6e70719023e7b382cab79/installation/mocks/mocks.go#L314-L319
|
143,504 |
cloudfoundry/bosh-cli
|
installation/mocks/mocks.go
|
RenderAndUploadFrom
|
func (mr *MockJobRendererMockRecorder) RenderAndUploadFrom(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RenderAndUploadFrom", reflect.TypeOf((*MockJobRenderer)(nil).RenderAndUploadFrom), arg0, arg1, arg2)
}
|
go
|
func (mr *MockJobRendererMockRecorder) RenderAndUploadFrom(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RenderAndUploadFrom", reflect.TypeOf((*MockJobRenderer)(nil).RenderAndUploadFrom), arg0, arg1, arg2)
}
|
[
"func",
"(",
"mr",
"*",
"MockJobRendererMockRecorder",
")",
"RenderAndUploadFrom",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockJobRenderer",
")",
"(",
"nil",
")",
".",
"RenderAndUploadFrom",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"}"
] |
// RenderAndUploadFrom indicates an expected call of RenderAndUploadFrom
|
[
"RenderAndUploadFrom",
"indicates",
"an",
"expected",
"call",
"of",
"RenderAndUploadFrom"
] |
0ee5b2abedb27e521dc6e70719023e7b382cab79
|
https://github.com/cloudfoundry/bosh-cli/blob/0ee5b2abedb27e521dc6e70719023e7b382cab79/installation/mocks/mocks.go#L322-L324
|
143,505 |
CloudyKit/jet
|
func.go
|
Get
|
func (a *Arguments) Get(argumentIndex int) reflect.Value {
if argumentIndex < len(a.argVal) {
return a.argVal[argumentIndex]
}
if argumentIndex < len(a.argVal)+len(a.argExpr) {
return a.runtime.evalPrimaryExpressionGroup(a.argExpr[argumentIndex-len(a.argVal)])
}
return reflect.Value{}
}
|
go
|
func (a *Arguments) Get(argumentIndex int) reflect.Value {
if argumentIndex < len(a.argVal) {
return a.argVal[argumentIndex]
}
if argumentIndex < len(a.argVal)+len(a.argExpr) {
return a.runtime.evalPrimaryExpressionGroup(a.argExpr[argumentIndex-len(a.argVal)])
}
return reflect.Value{}
}
|
[
"func",
"(",
"a",
"*",
"Arguments",
")",
"Get",
"(",
"argumentIndex",
"int",
")",
"reflect",
".",
"Value",
"{",
"if",
"argumentIndex",
"<",
"len",
"(",
"a",
".",
"argVal",
")",
"{",
"return",
"a",
".",
"argVal",
"[",
"argumentIndex",
"]",
"\n",
"}",
"\n",
"if",
"argumentIndex",
"<",
"len",
"(",
"a",
".",
"argVal",
")",
"+",
"len",
"(",
"a",
".",
"argExpr",
")",
"{",
"return",
"a",
".",
"runtime",
".",
"evalPrimaryExpressionGroup",
"(",
"a",
".",
"argExpr",
"[",
"argumentIndex",
"-",
"len",
"(",
"a",
".",
"argVal",
")",
"]",
")",
"\n",
"}",
"\n",
"return",
"reflect",
".",
"Value",
"{",
"}",
"\n",
"}"
] |
// Get gets an argument by index.
|
[
"Get",
"gets",
"an",
"argument",
"by",
"index",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/func.go#L30-L38
|
143,506 |
CloudyKit/jet
|
func.go
|
Panicf
|
func (a *Arguments) Panicf(format string, v ...interface{}) {
panic(fmt.Errorf(format, v...))
}
|
go
|
func (a *Arguments) Panicf(format string, v ...interface{}) {
panic(fmt.Errorf(format, v...))
}
|
[
"func",
"(",
"a",
"*",
"Arguments",
")",
"Panicf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] |
// Panicf panics with formatted error message.
|
[
"Panicf",
"panics",
"with",
"formatted",
"error",
"message",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/func.go#L41-L43
|
143,507 |
CloudyKit/jet
|
func.go
|
RequireNumOfArguments
|
func (a *Arguments) RequireNumOfArguments(funcname string, min, max int) {
num := len(a.argExpr) + len(a.argVal)
if min >= 0 && num < min {
a.Panicf("unexpected number of arguments in a call to %s", funcname)
} else if max >= 0 && num > max {
a.Panicf("unexpected number of arguments in a call to %s", funcname)
}
}
|
go
|
func (a *Arguments) RequireNumOfArguments(funcname string, min, max int) {
num := len(a.argExpr) + len(a.argVal)
if min >= 0 && num < min {
a.Panicf("unexpected number of arguments in a call to %s", funcname)
} else if max >= 0 && num > max {
a.Panicf("unexpected number of arguments in a call to %s", funcname)
}
}
|
[
"func",
"(",
"a",
"*",
"Arguments",
")",
"RequireNumOfArguments",
"(",
"funcname",
"string",
",",
"min",
",",
"max",
"int",
")",
"{",
"num",
":=",
"len",
"(",
"a",
".",
"argExpr",
")",
"+",
"len",
"(",
"a",
".",
"argVal",
")",
"\n",
"if",
"min",
">=",
"0",
"&&",
"num",
"<",
"min",
"{",
"a",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"funcname",
")",
"\n",
"}",
"else",
"if",
"max",
">=",
"0",
"&&",
"num",
">",
"max",
"{",
"a",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"funcname",
")",
"\n",
"}",
"\n",
"}"
] |
// RequireNumOfArguments panics if the number of arguments is not in the range specified by min and max.
// In case there is no minimum pass -1, in case there is no maximum pass -1 respectively.
|
[
"RequireNumOfArguments",
"panics",
"if",
"the",
"number",
"of",
"arguments",
"is",
"not",
"in",
"the",
"range",
"specified",
"by",
"min",
"and",
"max",
".",
"In",
"case",
"there",
"is",
"no",
"minimum",
"pass",
"-",
"1",
"in",
"case",
"there",
"is",
"no",
"maximum",
"pass",
"-",
"1",
"respectively",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/func.go#L47-L54
|
143,508 |
CloudyKit/jet
|
func.go
|
NumOfArguments
|
func (a *Arguments) NumOfArguments() int {
return len(a.argExpr) + len(a.argVal)
}
|
go
|
func (a *Arguments) NumOfArguments() int {
return len(a.argExpr) + len(a.argVal)
}
|
[
"func",
"(",
"a",
"*",
"Arguments",
")",
"NumOfArguments",
"(",
")",
"int",
"{",
"return",
"len",
"(",
"a",
".",
"argExpr",
")",
"+",
"len",
"(",
"a",
".",
"argVal",
")",
"\n",
"}"
] |
// NumOfArguments returns the number of arguments
|
[
"NumOfArguments",
"returns",
"the",
"number",
"of",
"arguments"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/func.go#L57-L59
|
143,509 |
CloudyKit/jet
|
loaders/multi/multi.go
|
AddLoaders
|
func (m *Multi) AddLoaders(loaders ...jet.Loader) {
m.loaders = append(m.loaders, loaders...)
}
|
go
|
func (m *Multi) AddLoaders(loaders ...jet.Loader) {
m.loaders = append(m.loaders, loaders...)
}
|
[
"func",
"(",
"m",
"*",
"Multi",
")",
"AddLoaders",
"(",
"loaders",
"...",
"jet",
".",
"Loader",
")",
"{",
"m",
".",
"loaders",
"=",
"append",
"(",
"m",
".",
"loaders",
",",
"loaders",
"...",
")",
"\n",
"}"
] |
// AddLoaders adds the passed loaders to the list of loaders.
|
[
"AddLoaders",
"adds",
"the",
"passed",
"loaders",
"to",
"the",
"list",
"of",
"loaders",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loaders/multi/multi.go#L22-L24
|
143,510 |
CloudyKit/jet
|
loaders/multi/multi.go
|
Open
|
func (m *Multi) Open(name string) (io.ReadCloser, error) {
for _, loader := range m.loaders {
if f, err := loader.Open(name); err == nil {
return f, nil
}
}
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
|
go
|
func (m *Multi) Open(name string) (io.ReadCloser, error) {
for _, loader := range m.loaders {
if f, err := loader.Open(name); err == nil {
return f, nil
}
}
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
|
[
"func",
"(",
"m",
"*",
"Multi",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"for",
"_",
",",
"loader",
":=",
"range",
"m",
".",
"loaders",
"{",
"if",
"f",
",",
"err",
":=",
"loader",
".",
"Open",
"(",
"name",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"name",
",",
"Err",
":",
"os",
".",
"ErrNotExist",
"}",
"\n",
"}"
] |
// Open will open the file passed by trying all loaders in succession.
|
[
"Open",
"will",
"open",
"the",
"file",
"passed",
"by",
"trying",
"all",
"loaders",
"in",
"succession",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loaders/multi/multi.go#L32-L39
|
143,511 |
CloudyKit/jet
|
loaders/multi/multi.go
|
Exists
|
func (m *Multi) Exists(name string) (string, bool) {
for _, loader := range m.loaders {
if fileName, ok := loader.Exists(name); ok {
return fileName, true
}
}
return "", false
}
|
go
|
func (m *Multi) Exists(name string) (string, bool) {
for _, loader := range m.loaders {
if fileName, ok := loader.Exists(name); ok {
return fileName, true
}
}
return "", false
}
|
[
"func",
"(",
"m",
"*",
"Multi",
")",
"Exists",
"(",
"name",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"for",
"_",
",",
"loader",
":=",
"range",
"m",
".",
"loaders",
"{",
"if",
"fileName",
",",
"ok",
":=",
"loader",
".",
"Exists",
"(",
"name",
")",
";",
"ok",
"{",
"return",
"fileName",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] |
// Exists checks all loaders in succession, returning the full path of the template and
// bool true if the template file was found, otherwise it returns an empty string and false.
|
[
"Exists",
"checks",
"all",
"loaders",
"in",
"succession",
"returning",
"the",
"full",
"path",
"of",
"the",
"template",
"and",
"bool",
"true",
"if",
"the",
"template",
"file",
"was",
"found",
"otherwise",
"it",
"returns",
"an",
"empty",
"string",
"and",
"false",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loaders/multi/multi.go#L43-L50
|
143,512 |
CloudyKit/jet
|
lex.go
|
lexSpace
|
func lexSpace(l *lexer) stateFn {
for isSpace(l.peek()) {
l.next()
}
l.emit(itemSpace)
return lexInsideAction
}
|
go
|
func lexSpace(l *lexer) stateFn {
for isSpace(l.peek()) {
l.next()
}
l.emit(itemSpace)
return lexInsideAction
}
|
[
"func",
"lexSpace",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"for",
"isSpace",
"(",
"l",
".",
"peek",
"(",
")",
")",
"{",
"l",
".",
"next",
"(",
")",
"\n",
"}",
"\n",
"l",
".",
"emit",
"(",
"itemSpace",
")",
"\n",
"return",
"lexInsideAction",
"\n",
"}"
] |
// lexSpace scans a run of space characters.
// One space has already been seen.
|
[
"lexSpace",
"scans",
"a",
"run",
"of",
"space",
"characters",
".",
"One",
"space",
"has",
"already",
"been",
"seen",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/lex.go#L487-L493
|
143,513 |
CloudyKit/jet
|
lex.go
|
lexIdentifier
|
func lexIdentifier(l *lexer) stateFn {
Loop:
for {
switch r := l.next(); {
case isAlphaNumeric(r):
// absorb.
default:
l.backup()
word := l.input[l.start:l.pos]
if !l.atTerminator() {
return l.errorf("bad character %#U", r)
}
switch {
case key[word] > itemKeyword:
l.emit(key[word])
case word[0] == '.':
l.emit(itemField)
case word == "true", word == "false":
l.emit(itemBool)
default:
l.emit(itemIdentifier)
}
break Loop
}
}
return lexInsideAction
}
|
go
|
func lexIdentifier(l *lexer) stateFn {
Loop:
for {
switch r := l.next(); {
case isAlphaNumeric(r):
// absorb.
default:
l.backup()
word := l.input[l.start:l.pos]
if !l.atTerminator() {
return l.errorf("bad character %#U", r)
}
switch {
case key[word] > itemKeyword:
l.emit(key[word])
case word[0] == '.':
l.emit(itemField)
case word == "true", word == "false":
l.emit(itemBool)
default:
l.emit(itemIdentifier)
}
break Loop
}
}
return lexInsideAction
}
|
[
"func",
"lexIdentifier",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"Loop",
":",
"for",
"{",
"switch",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"{",
"case",
"isAlphaNumeric",
"(",
"r",
")",
":",
"// absorb.",
"default",
":",
"l",
".",
"backup",
"(",
")",
"\n",
"word",
":=",
"l",
".",
"input",
"[",
"l",
".",
"start",
":",
"l",
".",
"pos",
"]",
"\n",
"if",
"!",
"l",
".",
"atTerminator",
"(",
")",
"{",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"key",
"[",
"word",
"]",
">",
"itemKeyword",
":",
"l",
".",
"emit",
"(",
"key",
"[",
"word",
"]",
")",
"\n",
"case",
"word",
"[",
"0",
"]",
"==",
"'.'",
":",
"l",
".",
"emit",
"(",
"itemField",
")",
"\n",
"case",
"word",
"==",
"\"",
"\"",
",",
"word",
"==",
"\"",
"\"",
":",
"l",
".",
"emit",
"(",
"itemBool",
")",
"\n",
"default",
":",
"l",
".",
"emit",
"(",
"itemIdentifier",
")",
"\n",
"}",
"\n",
"break",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lexInsideAction",
"\n",
"}"
] |
// lexIdentifier scans an alphanumeric.
|
[
"lexIdentifier",
"scans",
"an",
"alphanumeric",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/lex.go#L496-L522
|
143,514 |
CloudyKit/jet
|
lex.go
|
lexChar
|
func lexChar(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case '\\':
if r := l.next(); r != eof && r != '\n' {
break
}
fallthrough
case eof, '\n':
return l.errorf("unterminated character constant")
case '\'':
break Loop
}
}
l.emit(itemCharConstant)
return lexInsideAction
}
|
go
|
func lexChar(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case '\\':
if r := l.next(); r != eof && r != '\n' {
break
}
fallthrough
case eof, '\n':
return l.errorf("unterminated character constant")
case '\'':
break Loop
}
}
l.emit(itemCharConstant)
return lexInsideAction
}
|
[
"func",
"lexChar",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"Loop",
":",
"for",
"{",
"switch",
"l",
".",
"next",
"(",
")",
"{",
"case",
"'\\\\'",
":",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"r",
"!=",
"eof",
"&&",
"r",
"!=",
"'\\n'",
"{",
"break",
"\n",
"}",
"\n",
"fallthrough",
"\n",
"case",
"eof",
",",
"'\\n'",
":",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"'\\''",
":",
"break",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"emit",
"(",
"itemCharConstant",
")",
"\n",
"return",
"lexInsideAction",
"\n",
"}"
] |
// lexChar scans a character constant. The initial quote is already
// scanned. Syntax checking is done by the parser.
|
[
"lexChar",
"scans",
"a",
"character",
"constant",
".",
"The",
"initial",
"quote",
"is",
"already",
"scanned",
".",
"Syntax",
"checking",
"is",
"done",
"by",
"the",
"parser",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/lex.go#L573-L590
|
143,515 |
CloudyKit/jet
|
lex.go
|
lexQuote
|
func lexQuote(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case '\\':
if r := l.next(); r != eof && r != '\n' {
break
}
fallthrough
case eof, '\n':
return l.errorf("unterminated quoted string")
case '"':
break Loop
}
}
l.emit(itemString)
return lexInsideAction
}
|
go
|
func lexQuote(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case '\\':
if r := l.next(); r != eof && r != '\n' {
break
}
fallthrough
case eof, '\n':
return l.errorf("unterminated quoted string")
case '"':
break Loop
}
}
l.emit(itemString)
return lexInsideAction
}
|
[
"func",
"lexQuote",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"Loop",
":",
"for",
"{",
"switch",
"l",
".",
"next",
"(",
")",
"{",
"case",
"'\\\\'",
":",
"if",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"r",
"!=",
"eof",
"&&",
"r",
"!=",
"'\\n'",
"{",
"break",
"\n",
"}",
"\n",
"fallthrough",
"\n",
"case",
"eof",
",",
"'\\n'",
":",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"'\"'",
":",
"break",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"emit",
"(",
"itemString",
")",
"\n",
"return",
"lexInsideAction",
"\n",
"}"
] |
// lexQuote scans a quoted string.
|
[
"lexQuote",
"scans",
"a",
"quoted",
"string",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/lex.go#L632-L649
|
143,516 |
CloudyKit/jet
|
lex.go
|
lexRawQuote
|
func lexRawQuote(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case eof:
return l.errorf("unterminated raw quoted string")
case '`':
break Loop
}
}
l.emit(itemRawString)
return lexInsideAction
}
|
go
|
func lexRawQuote(l *lexer) stateFn {
Loop:
for {
switch l.next() {
case eof:
return l.errorf("unterminated raw quoted string")
case '`':
break Loop
}
}
l.emit(itemRawString)
return lexInsideAction
}
|
[
"func",
"lexRawQuote",
"(",
"l",
"*",
"lexer",
")",
"stateFn",
"{",
"Loop",
":",
"for",
"{",
"switch",
"l",
".",
"next",
"(",
")",
"{",
"case",
"eof",
":",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"'`'",
":",
"break",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"emit",
"(",
"itemRawString",
")",
"\n",
"return",
"lexInsideAction",
"\n",
"}"
] |
// lexRawQuote scans a raw quoted string.
|
[
"lexRawQuote",
"scans",
"a",
"raw",
"quoted",
"string",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/lex.go#L652-L664
|
143,517 |
CloudyKit/jet
|
utils/visitor.go
|
Walk
|
func Walk(t *jet.Template, v Visitor) {
v.Visit(VisitorContext{Visitor: v}, t.Root)
}
|
go
|
func Walk(t *jet.Template, v Visitor) {
v.Visit(VisitorContext{Visitor: v}, t.Root)
}
|
[
"func",
"Walk",
"(",
"t",
"*",
"jet",
".",
"Template",
",",
"v",
"Visitor",
")",
"{",
"v",
".",
"Visit",
"(",
"VisitorContext",
"{",
"Visitor",
":",
"v",
"}",
",",
"t",
".",
"Root",
")",
"\n",
"}"
] |
// Walk walks the template ast and calls the Visit method on each node of the tree
// if you're not familiar with the Visitor pattern please check the visitor_test.go
// for usage examples
|
[
"Walk",
"walks",
"the",
"template",
"ast",
"and",
"calls",
"the",
"Visit",
"method",
"on",
"each",
"node",
"of",
"the",
"tree",
"if",
"you",
"re",
"not",
"familiar",
"with",
"the",
"Visitor",
"pattern",
"please",
"check",
"the",
"visitor_test",
".",
"go",
"for",
"usage",
"examples"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/utils/visitor.go#L12-L14
|
143,518 |
CloudyKit/jet
|
examples/todos/main.go
|
Render
|
func (t *tTODO) Render(r *jet.Runtime) {
done := "yes"
if !t.Done {
done = "no"
}
r.Write([]byte(fmt.Sprintf("TODO: %s (done: %s)", t.Text, done)))
}
|
go
|
func (t *tTODO) Render(r *jet.Runtime) {
done := "yes"
if !t.Done {
done = "no"
}
r.Write([]byte(fmt.Sprintf("TODO: %s (done: %s)", t.Text, done)))
}
|
[
"func",
"(",
"t",
"*",
"tTODO",
")",
"Render",
"(",
"r",
"*",
"jet",
".",
"Runtime",
")",
"{",
"done",
":=",
"\"",
"\"",
"\n",
"if",
"!",
"t",
".",
"Done",
"{",
"done",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"r",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Text",
",",
"done",
")",
")",
")",
"\n",
"}"
] |
// Render implements jet.Renderer interface
|
[
"Render",
"implements",
"jet",
".",
"Renderer",
"interface"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/examples/todos/main.go#L68-L74
|
143,519 |
CloudyKit/jet
|
parse.go
|
parseTemplate
|
func (t *Template) parseTemplate() (next Node) {
t.Root = t.newList(t.peek().pos)
// {{ extends|import stringLiteral }}
for t.peek().typ != itemEOF {
delim := t.next()
if delim.typ == itemText && strings.TrimSpace(delim.val) == "" {
continue //skips empty text nodes
}
if delim.typ == itemLeftDelim {
token := t.nextNonSpace()
if token.typ == itemExtends || token.typ == itemImport {
s := t.expectString("extends|import")
if token.typ == itemExtends {
if t.extends != nil {
t.errorf("Unexpected extends clause, only one extends clause is valid per template")
} else if len(t.imports) > 0 {
t.errorf("Unexpected extends clause, all import clause should come after extends clause")
}
var err error
t.extends, err = t.set.getTemplateWhileParsing(t.Name, s)
if err != nil {
t.error(err)
}
} else {
tt, err := t.set.getTemplateWhileParsing(t.Name, s)
if err != nil {
t.error(err)
}
t.imports = append(t.imports, tt)
}
t.expect(itemRightDelim, "extends|import")
} else {
t.backup2(delim)
break
}
} else {
t.backup()
break
}
}
for t.peek().typ != itemEOF {
switch n := t.textOrAction(); n.Type() {
case nodeEnd, nodeElse, nodeContent:
t.errorf("unexpected %s", n)
default:
t.Root.append(n)
}
}
return nil
}
|
go
|
func (t *Template) parseTemplate() (next Node) {
t.Root = t.newList(t.peek().pos)
// {{ extends|import stringLiteral }}
for t.peek().typ != itemEOF {
delim := t.next()
if delim.typ == itemText && strings.TrimSpace(delim.val) == "" {
continue //skips empty text nodes
}
if delim.typ == itemLeftDelim {
token := t.nextNonSpace()
if token.typ == itemExtends || token.typ == itemImport {
s := t.expectString("extends|import")
if token.typ == itemExtends {
if t.extends != nil {
t.errorf("Unexpected extends clause, only one extends clause is valid per template")
} else if len(t.imports) > 0 {
t.errorf("Unexpected extends clause, all import clause should come after extends clause")
}
var err error
t.extends, err = t.set.getTemplateWhileParsing(t.Name, s)
if err != nil {
t.error(err)
}
} else {
tt, err := t.set.getTemplateWhileParsing(t.Name, s)
if err != nil {
t.error(err)
}
t.imports = append(t.imports, tt)
}
t.expect(itemRightDelim, "extends|import")
} else {
t.backup2(delim)
break
}
} else {
t.backup()
break
}
}
for t.peek().typ != itemEOF {
switch n := t.textOrAction(); n.Type() {
case nodeEnd, nodeElse, nodeContent:
t.errorf("unexpected %s", n)
default:
t.Root.append(n)
}
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"Template",
")",
"parseTemplate",
"(",
")",
"(",
"next",
"Node",
")",
"{",
"t",
".",
"Root",
"=",
"t",
".",
"newList",
"(",
"t",
".",
"peek",
"(",
")",
".",
"pos",
")",
"\n",
"// {{ extends|import stringLiteral }}",
"for",
"t",
".",
"peek",
"(",
")",
".",
"typ",
"!=",
"itemEOF",
"{",
"delim",
":=",
"t",
".",
"next",
"(",
")",
"\n",
"if",
"delim",
".",
"typ",
"==",
"itemText",
"&&",
"strings",
".",
"TrimSpace",
"(",
"delim",
".",
"val",
")",
"==",
"\"",
"\"",
"{",
"continue",
"//skips empty text nodes",
"\n",
"}",
"\n",
"if",
"delim",
".",
"typ",
"==",
"itemLeftDelim",
"{",
"token",
":=",
"t",
".",
"nextNonSpace",
"(",
")",
"\n",
"if",
"token",
".",
"typ",
"==",
"itemExtends",
"||",
"token",
".",
"typ",
"==",
"itemImport",
"{",
"s",
":=",
"t",
".",
"expectString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"token",
".",
"typ",
"==",
"itemExtends",
"{",
"if",
"t",
".",
"extends",
"!=",
"nil",
"{",
"t",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"t",
".",
"imports",
")",
">",
"0",
"{",
"t",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"t",
".",
"extends",
",",
"err",
"=",
"t",
".",
"set",
".",
"getTemplateWhileParsing",
"(",
"t",
".",
"Name",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"t",
".",
"error",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"tt",
",",
"err",
":=",
"t",
".",
"set",
".",
"getTemplateWhileParsing",
"(",
"t",
".",
"Name",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"t",
".",
"error",
"(",
"err",
")",
"\n",
"}",
"\n",
"t",
".",
"imports",
"=",
"append",
"(",
"t",
".",
"imports",
",",
"tt",
")",
"\n",
"}",
"\n",
"t",
".",
"expect",
"(",
"itemRightDelim",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"t",
".",
"backup2",
"(",
"delim",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"else",
"{",
"t",
".",
"backup",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"t",
".",
"peek",
"(",
")",
".",
"typ",
"!=",
"itemEOF",
"{",
"switch",
"n",
":=",
"t",
".",
"textOrAction",
"(",
")",
";",
"n",
".",
"Type",
"(",
")",
"{",
"case",
"nodeEnd",
",",
"nodeElse",
",",
"nodeContent",
":",
"t",
".",
"errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"default",
":",
"t",
".",
"Root",
".",
"append",
"(",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// parse is the top-level parser for a template, essentially the same
// It runs to EOF.
|
[
"parse",
"is",
"the",
"top",
"-",
"level",
"parser",
"for",
"a",
"template",
"essentially",
"the",
"same",
"It",
"runs",
"to",
"EOF",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/parse.go#L198-L248
|
143,520 |
CloudyKit/jet
|
node.go
|
simplifyComplex
|
func (n *NumberNode) simplifyComplex() {
n.IsFloat = imag(n.Complex128) == 0
if n.IsFloat {
n.Float64 = real(n.Complex128)
n.IsInt = float64(int64(n.Float64)) == n.Float64
if n.IsInt {
n.Int64 = int64(n.Float64)
}
n.IsUint = float64(uint64(n.Float64)) == n.Float64
if n.IsUint {
n.Uint64 = uint64(n.Float64)
}
}
}
|
go
|
func (n *NumberNode) simplifyComplex() {
n.IsFloat = imag(n.Complex128) == 0
if n.IsFloat {
n.Float64 = real(n.Complex128)
n.IsInt = float64(int64(n.Float64)) == n.Float64
if n.IsInt {
n.Int64 = int64(n.Float64)
}
n.IsUint = float64(uint64(n.Float64)) == n.Float64
if n.IsUint {
n.Uint64 = uint64(n.Float64)
}
}
}
|
[
"func",
"(",
"n",
"*",
"NumberNode",
")",
"simplifyComplex",
"(",
")",
"{",
"n",
".",
"IsFloat",
"=",
"imag",
"(",
"n",
".",
"Complex128",
")",
"==",
"0",
"\n",
"if",
"n",
".",
"IsFloat",
"{",
"n",
".",
"Float64",
"=",
"real",
"(",
"n",
".",
"Complex128",
")",
"\n",
"n",
".",
"IsInt",
"=",
"float64",
"(",
"int64",
"(",
"n",
".",
"Float64",
")",
")",
"==",
"n",
".",
"Float64",
"\n",
"if",
"n",
".",
"IsInt",
"{",
"n",
".",
"Int64",
"=",
"int64",
"(",
"n",
".",
"Float64",
")",
"\n",
"}",
"\n",
"n",
".",
"IsUint",
"=",
"float64",
"(",
"uint64",
"(",
"n",
".",
"Float64",
")",
")",
"==",
"n",
".",
"Float64",
"\n",
"if",
"n",
".",
"IsUint",
"{",
"n",
".",
"Uint64",
"=",
"uint64",
"(",
"n",
".",
"Float64",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// simplifyComplex pulls out any other types that are represented by the complex number.
// These all require that the imaginary part be zero.
|
[
"simplifyComplex",
"pulls",
"out",
"any",
"other",
"types",
"that",
"are",
"represented",
"by",
"the",
"complex",
"number",
".",
"These",
"all",
"require",
"that",
"the",
"imaginary",
"part",
"be",
"zero",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/node.go#L310-L323
|
143,521 |
CloudyKit/jet
|
loader.go
|
Open
|
func (l *OSFileSystemLoader) Open(name string) (io.ReadCloser, error) {
return os.Open(name)
}
|
go
|
func (l *OSFileSystemLoader) Open(name string) (io.ReadCloser, error) {
return os.Open(name)
}
|
[
"func",
"(",
"l",
"*",
"OSFileSystemLoader",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"os",
".",
"Open",
"(",
"name",
")",
"\n",
"}"
] |
// Open opens a file from OS file system.
|
[
"Open",
"opens",
"a",
"file",
"from",
"OS",
"file",
"system",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loader.go#L54-L56
|
143,522 |
CloudyKit/jet
|
loader.go
|
AddPath
|
func (l *OSFileSystemLoader) AddPath(path string) {
l.dirs = append(l.dirs, path)
}
|
go
|
func (l *OSFileSystemLoader) AddPath(path string) {
l.dirs = append(l.dirs, path)
}
|
[
"func",
"(",
"l",
"*",
"OSFileSystemLoader",
")",
"AddPath",
"(",
"path",
"string",
")",
"{",
"l",
".",
"dirs",
"=",
"append",
"(",
"l",
".",
"dirs",
",",
"path",
")",
"\n",
"}"
] |
// AddPath adds the path to the internal list of paths searched when loading templates.
|
[
"AddPath",
"adds",
"the",
"path",
"to",
"the",
"internal",
"list",
"of",
"paths",
"searched",
"when",
"loading",
"templates",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loader.go#L71-L73
|
143,523 |
CloudyKit/jet
|
eval.go
|
YieldBlock
|
func (st *Runtime) YieldBlock(name string, context interface{}) {
block, has := st.getBlock(name)
if has == false {
panic(fmt.Errorf("Block %q was not found!!", name))
}
if context != nil {
current := st.context
st.context = reflect.ValueOf(context)
st.executeList(block.List)
st.context = current
}
st.executeList(block.List)
}
|
go
|
func (st *Runtime) YieldBlock(name string, context interface{}) {
block, has := st.getBlock(name)
if has == false {
panic(fmt.Errorf("Block %q was not found!!", name))
}
if context != nil {
current := st.context
st.context = reflect.ValueOf(context)
st.executeList(block.List)
st.context = current
}
st.executeList(block.List)
}
|
[
"func",
"(",
"st",
"*",
"Runtime",
")",
"YieldBlock",
"(",
"name",
"string",
",",
"context",
"interface",
"{",
"}",
")",
"{",
"block",
",",
"has",
":=",
"st",
".",
"getBlock",
"(",
"name",
")",
"\n\n",
"if",
"has",
"==",
"false",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n\n",
"if",
"context",
"!=",
"nil",
"{",
"current",
":=",
"st",
".",
"context",
"\n",
"st",
".",
"context",
"=",
"reflect",
".",
"ValueOf",
"(",
"context",
")",
"\n",
"st",
".",
"executeList",
"(",
"block",
".",
"List",
")",
"\n",
"st",
".",
"context",
"=",
"current",
"\n",
"}",
"\n\n",
"st",
".",
"executeList",
"(",
"block",
".",
"List",
")",
"\n",
"}"
] |
// YieldBlock yields a block in the current context, will panic if the context is not available
|
[
"YieldBlock",
"yields",
"a",
"block",
"in",
"the",
"current",
"context",
"will",
"panic",
"if",
"the",
"context",
"is",
"not",
"available"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/eval.go#L106-L121
|
143,524 |
CloudyKit/jet
|
eval.go
|
YieldTemplate
|
func (st *Runtime) YieldTemplate(name string, context interface{}) {
t, err := st.set.GetTemplate(name)
if err != nil {
panic(fmt.Errorf("include: template %q was not found", name))
}
st.newScope()
st.blocks = t.processedBlocks
Root := t.Root
if t.extends != nil {
Root = t.extends.Root
}
if context != nil {
c := st.context
st.context = reflect.ValueOf(context)
st.executeList(Root)
st.context = c
} else {
st.executeList(Root)
}
st.releaseScope()
}
|
go
|
func (st *Runtime) YieldTemplate(name string, context interface{}) {
t, err := st.set.GetTemplate(name)
if err != nil {
panic(fmt.Errorf("include: template %q was not found", name))
}
st.newScope()
st.blocks = t.processedBlocks
Root := t.Root
if t.extends != nil {
Root = t.extends.Root
}
if context != nil {
c := st.context
st.context = reflect.ValueOf(context)
st.executeList(Root)
st.context = c
} else {
st.executeList(Root)
}
st.releaseScope()
}
|
[
"func",
"(",
"st",
"*",
"Runtime",
")",
"YieldTemplate",
"(",
"name",
"string",
",",
"context",
"interface",
"{",
"}",
")",
"{",
"t",
",",
"err",
":=",
"st",
".",
"set",
".",
"GetTemplate",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n\n",
"st",
".",
"newScope",
"(",
")",
"\n",
"st",
".",
"blocks",
"=",
"t",
".",
"processedBlocks",
"\n\n",
"Root",
":=",
"t",
".",
"Root",
"\n",
"if",
"t",
".",
"extends",
"!=",
"nil",
"{",
"Root",
"=",
"t",
".",
"extends",
".",
"Root",
"\n",
"}",
"\n\n",
"if",
"context",
"!=",
"nil",
"{",
"c",
":=",
"st",
".",
"context",
"\n",
"st",
".",
"context",
"=",
"reflect",
".",
"ValueOf",
"(",
"context",
")",
"\n",
"st",
".",
"executeList",
"(",
"Root",
")",
"\n",
"st",
".",
"context",
"=",
"c",
"\n",
"}",
"else",
"{",
"st",
".",
"executeList",
"(",
"Root",
")",
"\n",
"}",
"\n\n",
"st",
".",
"releaseScope",
"(",
")",
"\n",
"}"
] |
// YieldTemplate yields a template same as include
|
[
"YieldTemplate",
"yields",
"a",
"template",
"same",
"as",
"include"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/eval.go#L133-L158
|
143,525 |
CloudyKit/jet
|
eval.go
|
Resolve
|
func (state *Runtime) Resolve(name string) reflect.Value {
if name == "." {
return state.context
}
sc := state.scope
// try to resolve variables in the current scope
vl, ok := sc.variables[name]
// if not found walks parent scopes
for !ok && sc.parent != nil {
sc = sc.parent
vl, ok = sc.variables[name]
}
// if not found check globals
if !ok {
state.set.gmx.RLock()
vl, ok = state.set.globals[name]
state.set.gmx.RUnlock()
// not found check defaultVariables
if !ok {
vl, ok = defaultVariables[name]
}
}
return vl
}
|
go
|
func (state *Runtime) Resolve(name string) reflect.Value {
if name == "." {
return state.context
}
sc := state.scope
// try to resolve variables in the current scope
vl, ok := sc.variables[name]
// if not found walks parent scopes
for !ok && sc.parent != nil {
sc = sc.parent
vl, ok = sc.variables[name]
}
// if not found check globals
if !ok {
state.set.gmx.RLock()
vl, ok = state.set.globals[name]
state.set.gmx.RUnlock()
// not found check defaultVariables
if !ok {
vl, ok = defaultVariables[name]
}
}
return vl
}
|
[
"func",
"(",
"state",
"*",
"Runtime",
")",
"Resolve",
"(",
"name",
"string",
")",
"reflect",
".",
"Value",
"{",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"state",
".",
"context",
"\n",
"}",
"\n\n",
"sc",
":=",
"state",
".",
"scope",
"\n",
"// try to resolve variables in the current scope",
"vl",
",",
"ok",
":=",
"sc",
".",
"variables",
"[",
"name",
"]",
"\n",
"// if not found walks parent scopes",
"for",
"!",
"ok",
"&&",
"sc",
".",
"parent",
"!=",
"nil",
"{",
"sc",
"=",
"sc",
".",
"parent",
"\n",
"vl",
",",
"ok",
"=",
"sc",
".",
"variables",
"[",
"name",
"]",
"\n",
"}",
"\n\n",
"// if not found check globals",
"if",
"!",
"ok",
"{",
"state",
".",
"set",
".",
"gmx",
".",
"RLock",
"(",
")",
"\n",
"vl",
",",
"ok",
"=",
"state",
".",
"set",
".",
"globals",
"[",
"name",
"]",
"\n",
"state",
".",
"set",
".",
"gmx",
".",
"RUnlock",
"(",
")",
"\n",
"// not found check defaultVariables",
"if",
"!",
"ok",
"{",
"vl",
",",
"ok",
"=",
"defaultVariables",
"[",
"name",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"vl",
"\n",
"}"
] |
// Resolve resolves a value from the execution context
|
[
"Resolve",
"resolves",
"a",
"value",
"from",
"the",
"execution",
"context"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/eval.go#L195-L221
|
143,526 |
CloudyKit/jet
|
loaders/httpfs/loader.go
|
Open
|
func (l *httpFileSystemLoader) Open(name string) (io.ReadCloser, error) {
if l.fs == nil {
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
return l.fs.Open(name)
}
|
go
|
func (l *httpFileSystemLoader) Open(name string) (io.ReadCloser, error) {
if l.fs == nil {
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
return l.fs.Open(name)
}
|
[
"func",
"(",
"l",
"*",
"httpFileSystemLoader",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"l",
".",
"fs",
"==",
"nil",
"{",
"return",
"nil",
",",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"name",
",",
"Err",
":",
"os",
".",
"ErrNotExist",
"}",
"\n",
"}",
"\n",
"return",
"l",
".",
"fs",
".",
"Open",
"(",
"name",
")",
"\n",
"}"
] |
// Open opens the file via the internal http.FileSystem. It is the callers duty to close the file.
|
[
"Open",
"opens",
"the",
"file",
"via",
"the",
"internal",
"http",
".",
"FileSystem",
".",
"It",
"is",
"the",
"callers",
"duty",
"to",
"close",
"the",
"file",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/loaders/httpfs/loader.go#L21-L26
|
143,527 |
CloudyKit/jet
|
template.go
|
AddGlobal
|
func (s *Set) AddGlobal(key string, i interface{}) *Set {
s.gmx.Lock()
if s.globals == nil {
s.globals = make(VarMap)
}
s.globals[key] = reflect.ValueOf(i)
s.gmx.Unlock()
return s
}
|
go
|
func (s *Set) AddGlobal(key string, i interface{}) *Set {
s.gmx.Lock()
if s.globals == nil {
s.globals = make(VarMap)
}
s.globals[key] = reflect.ValueOf(i)
s.gmx.Unlock()
return s
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"AddGlobal",
"(",
"key",
"string",
",",
"i",
"interface",
"{",
"}",
")",
"*",
"Set",
"{",
"s",
".",
"gmx",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
".",
"globals",
"==",
"nil",
"{",
"s",
".",
"globals",
"=",
"make",
"(",
"VarMap",
")",
"\n",
"}",
"\n",
"s",
".",
"globals",
"[",
"key",
"]",
"=",
"reflect",
".",
"ValueOf",
"(",
"i",
")",
"\n",
"s",
".",
"gmx",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// AddGlobal add or set a global variable into the Set
|
[
"AddGlobal",
"add",
"or",
"set",
"a",
"global",
"variable",
"into",
"the",
"Set"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L62-L70
|
143,528 |
CloudyKit/jet
|
template.go
|
NewSetLoader
|
func NewSetLoader(escapee SafeWriter, loader Loader) *Set {
return &Set{loader: loader, tmx: &sync.RWMutex{}, gmx: &sync.RWMutex{}, escapee: escapee, templates: make(map[string]*Template), defaultExtensions: append([]string{}, defaultExtensions...)}
}
|
go
|
func NewSetLoader(escapee SafeWriter, loader Loader) *Set {
return &Set{loader: loader, tmx: &sync.RWMutex{}, gmx: &sync.RWMutex{}, escapee: escapee, templates: make(map[string]*Template), defaultExtensions: append([]string{}, defaultExtensions...)}
}
|
[
"func",
"NewSetLoader",
"(",
"escapee",
"SafeWriter",
",",
"loader",
"Loader",
")",
"*",
"Set",
"{",
"return",
"&",
"Set",
"{",
"loader",
":",
"loader",
",",
"tmx",
":",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"gmx",
":",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"escapee",
":",
"escapee",
",",
"templates",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Template",
")",
",",
"defaultExtensions",
":",
"append",
"(",
"[",
"]",
"string",
"{",
"}",
",",
"defaultExtensions",
"...",
")",
"}",
"\n",
"}"
] |
// NewSetLoader creates a new set with custom Loader
|
[
"NewSetLoader",
"creates",
"a",
"new",
"set",
"with",
"custom",
"Loader"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L77-L79
|
143,529 |
CloudyKit/jet
|
template.go
|
NewSet
|
func NewSet(escapee SafeWriter, dirs ...string) *Set {
return NewSetLoader(escapee, &OSFileSystemLoader{dirs: dirs})
}
|
go
|
func NewSet(escapee SafeWriter, dirs ...string) *Set {
return NewSetLoader(escapee, &OSFileSystemLoader{dirs: dirs})
}
|
[
"func",
"NewSet",
"(",
"escapee",
"SafeWriter",
",",
"dirs",
"...",
"string",
")",
"*",
"Set",
"{",
"return",
"NewSetLoader",
"(",
"escapee",
",",
"&",
"OSFileSystemLoader",
"{",
"dirs",
":",
"dirs",
"}",
")",
"\n",
"}"
] |
// NewSet creates a new set, dirs is a list of directories to be searched for templates
|
[
"NewSet",
"creates",
"a",
"new",
"set",
"dirs",
"is",
"a",
"list",
"of",
"directories",
"to",
"be",
"searched",
"for",
"templates"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L87-L89
|
143,530 |
CloudyKit/jet
|
template.go
|
AddPath
|
func (s *Set) AddPath(path string) {
if loader, ok := s.loader.(hasAddPath); ok {
loader.AddPath(path)
} else {
panic(fmt.Sprintf("AddPath() not supported on custom loader of type %T", s.loader))
}
}
|
go
|
func (s *Set) AddPath(path string) {
if loader, ok := s.loader.(hasAddPath); ok {
loader.AddPath(path)
} else {
panic(fmt.Sprintf("AddPath() not supported on custom loader of type %T", s.loader))
}
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"AddPath",
"(",
"path",
"string",
")",
"{",
"if",
"loader",
",",
"ok",
":=",
"s",
".",
"loader",
".",
"(",
"hasAddPath",
")",
";",
"ok",
"{",
"loader",
".",
"AddPath",
"(",
"path",
")",
"\n",
"}",
"else",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"loader",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// AddPath add path to the lookup list, when loading a template the Set will
// look into the lookup list for the file matching the provided name.
|
[
"AddPath",
"add",
"path",
"to",
"the",
"lookup",
"list",
"when",
"loading",
"a",
"template",
"the",
"Set",
"will",
"look",
"into",
"the",
"lookup",
"list",
"for",
"the",
"file",
"matching",
"the",
"provided",
"name",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L98-L104
|
143,531 |
CloudyKit/jet
|
template.go
|
AddGopathPath
|
func (s *Set) AddGopathPath(path string) {
if loader, ok := s.loader.(hasAddGopathPath); ok {
loader.AddGopathPath(path)
} else {
panic(fmt.Sprintf("AddGopathPath() not supported on custom loader of type %T", s.loader))
}
}
|
go
|
func (s *Set) AddGopathPath(path string) {
if loader, ok := s.loader.(hasAddGopathPath); ok {
loader.AddGopathPath(path)
} else {
panic(fmt.Sprintf("AddGopathPath() not supported on custom loader of type %T", s.loader))
}
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"AddGopathPath",
"(",
"path",
"string",
")",
"{",
"if",
"loader",
",",
"ok",
":=",
"s",
".",
"loader",
".",
"(",
"hasAddGopathPath",
")",
";",
"ok",
"{",
"loader",
".",
"AddGopathPath",
"(",
"path",
")",
"\n",
"}",
"else",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"loader",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// AddGopathPath add path based on GOPATH env to the lookup list, when loading a template the Set will
// look into the lookup list for the file matching the provided name.
|
[
"AddGopathPath",
"add",
"path",
"based",
"on",
"GOPATH",
"env",
"to",
"the",
"lookup",
"list",
"when",
"loading",
"a",
"template",
"the",
"Set",
"will",
"look",
"into",
"the",
"lookup",
"list",
"for",
"the",
"file",
"matching",
"the",
"provided",
"name",
"."
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L108-L114
|
143,532 |
CloudyKit/jet
|
template.go
|
Parse
|
func (s *Set) Parse(name, content string) (*Template, error) {
sc := *s
sc.developmentMode = true
sc.tmx.RLock()
t, err := sc.parse(name, content)
sc.tmx.RUnlock()
return t, err
}
|
go
|
func (s *Set) Parse(name, content string) (*Template, error) {
sc := *s
sc.developmentMode = true
sc.tmx.RLock()
t, err := sc.parse(name, content)
sc.tmx.RUnlock()
return t, err
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"Parse",
"(",
"name",
",",
"content",
"string",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"sc",
":=",
"*",
"s",
"\n",
"sc",
".",
"developmentMode",
"=",
"true",
"\n\n",
"sc",
".",
"tmx",
".",
"RLock",
"(",
")",
"\n",
"t",
",",
"err",
":=",
"sc",
".",
"parse",
"(",
"name",
",",
"content",
")",
"\n",
"sc",
".",
"tmx",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"t",
",",
"err",
"\n",
"}"
] |
// Parse parses the template, this method will link the template to the set but not the set to
|
[
"Parse",
"parses",
"the",
"template",
"this",
"method",
"will",
"link",
"the",
"template",
"to",
"the",
"set",
"but",
"not",
"the",
"set",
"to"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L168-L177
|
143,533 |
CloudyKit/jet
|
template.go
|
getTemplate
|
func (s *Set) getTemplate(name, sibling string) (template *Template, err error) {
name = path.Clean(name)
if s.developmentMode {
s.tmx.RLock()
defer s.tmx.RUnlock()
if newName, fileName, foundLoaded, foundFile, _ := s.resolveNameSibling(name, sibling); foundFile || foundLoaded {
if foundFile {
template, err = s.loadFromFile(newName, fileName)
} else {
template, _ = s.templates[newName]
}
} else {
err = fmt.Errorf("template %s can't be loaded", name)
}
return
}
//fast path
s.tmx.RLock()
newName, fileName, foundLoaded, foundFile, isRelative := s.resolveNameSibling(name, sibling)
if foundLoaded {
template = s.templates[newName]
s.tmx.RUnlock()
if !isRelative && name != newName {
// creates an alias
s.tmx.Lock()
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
s.tmx.Unlock()
}
return
}
s.tmx.RUnlock()
//not found parses and cache
s.tmx.Lock()
defer s.tmx.Unlock()
newName, fileName, foundLoaded, foundFile, isRelative = s.resolveNameSibling(name, sibling)
if foundLoaded {
template = s.templates[newName]
if !isRelative && name != newName {
// creates an alias
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
}
} else if foundFile {
template, err = s.loadFromFile(newName, fileName)
if !isRelative && name != newName {
// creates an alias
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
}
s.templates[newName] = template
} else {
err = fmt.Errorf("template %s can't be loaded", name)
}
return
}
|
go
|
func (s *Set) getTemplate(name, sibling string) (template *Template, err error) {
name = path.Clean(name)
if s.developmentMode {
s.tmx.RLock()
defer s.tmx.RUnlock()
if newName, fileName, foundLoaded, foundFile, _ := s.resolveNameSibling(name, sibling); foundFile || foundLoaded {
if foundFile {
template, err = s.loadFromFile(newName, fileName)
} else {
template, _ = s.templates[newName]
}
} else {
err = fmt.Errorf("template %s can't be loaded", name)
}
return
}
//fast path
s.tmx.RLock()
newName, fileName, foundLoaded, foundFile, isRelative := s.resolveNameSibling(name, sibling)
if foundLoaded {
template = s.templates[newName]
s.tmx.RUnlock()
if !isRelative && name != newName {
// creates an alias
s.tmx.Lock()
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
s.tmx.Unlock()
}
return
}
s.tmx.RUnlock()
//not found parses and cache
s.tmx.Lock()
defer s.tmx.Unlock()
newName, fileName, foundLoaded, foundFile, isRelative = s.resolveNameSibling(name, sibling)
if foundLoaded {
template = s.templates[newName]
if !isRelative && name != newName {
// creates an alias
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
}
} else if foundFile {
template, err = s.loadFromFile(newName, fileName)
if !isRelative && name != newName {
// creates an alias
if _, found := s.templates[name]; !found {
s.templates[name] = template
}
}
s.templates[newName] = template
} else {
err = fmt.Errorf("template %s can't be loaded", name)
}
return
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"getTemplate",
"(",
"name",
",",
"sibling",
"string",
")",
"(",
"template",
"*",
"Template",
",",
"err",
"error",
")",
"{",
"name",
"=",
"path",
".",
"Clean",
"(",
"name",
")",
"\n\n",
"if",
"s",
".",
"developmentMode",
"{",
"s",
".",
"tmx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"tmx",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"newName",
",",
"fileName",
",",
"foundLoaded",
",",
"foundFile",
",",
"_",
":=",
"s",
".",
"resolveNameSibling",
"(",
"name",
",",
"sibling",
")",
";",
"foundFile",
"||",
"foundLoaded",
"{",
"if",
"foundFile",
"{",
"template",
",",
"err",
"=",
"s",
".",
"loadFromFile",
"(",
"newName",
",",
"fileName",
")",
"\n",
"}",
"else",
"{",
"template",
",",
"_",
"=",
"s",
".",
"templates",
"[",
"newName",
"]",
"\n",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"//fast path",
"s",
".",
"tmx",
".",
"RLock",
"(",
")",
"\n",
"newName",
",",
"fileName",
",",
"foundLoaded",
",",
"foundFile",
",",
"isRelative",
":=",
"s",
".",
"resolveNameSibling",
"(",
"name",
",",
"sibling",
")",
"\n\n",
"if",
"foundLoaded",
"{",
"template",
"=",
"s",
".",
"templates",
"[",
"newName",
"]",
"\n",
"s",
".",
"tmx",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"isRelative",
"&&",
"name",
"!=",
"newName",
"{",
"// creates an alias",
"s",
".",
"tmx",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"found",
":=",
"s",
".",
"templates",
"[",
"name",
"]",
";",
"!",
"found",
"{",
"s",
".",
"templates",
"[",
"name",
"]",
"=",
"template",
"\n",
"}",
"\n",
"s",
".",
"tmx",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"s",
".",
"tmx",
".",
"RUnlock",
"(",
")",
"\n\n",
"//not found parses and cache",
"s",
".",
"tmx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"tmx",
".",
"Unlock",
"(",
")",
"\n\n",
"newName",
",",
"fileName",
",",
"foundLoaded",
",",
"foundFile",
",",
"isRelative",
"=",
"s",
".",
"resolveNameSibling",
"(",
"name",
",",
"sibling",
")",
"\n",
"if",
"foundLoaded",
"{",
"template",
"=",
"s",
".",
"templates",
"[",
"newName",
"]",
"\n",
"if",
"!",
"isRelative",
"&&",
"name",
"!=",
"newName",
"{",
"// creates an alias",
"if",
"_",
",",
"found",
":=",
"s",
".",
"templates",
"[",
"name",
"]",
";",
"!",
"found",
"{",
"s",
".",
"templates",
"[",
"name",
"]",
"=",
"template",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"foundFile",
"{",
"template",
",",
"err",
"=",
"s",
".",
"loadFromFile",
"(",
"newName",
",",
"fileName",
")",
"\n\n",
"if",
"!",
"isRelative",
"&&",
"name",
"!=",
"newName",
"{",
"// creates an alias",
"if",
"_",
",",
"found",
":=",
"s",
".",
"templates",
"[",
"name",
"]",
";",
"!",
"found",
"{",
"s",
".",
"templates",
"[",
"name",
"]",
"=",
"template",
"\n",
"}",
"\n",
"}",
"\n\n",
"s",
".",
"templates",
"[",
"newName",
"]",
"=",
"template",
"\n",
"}",
"else",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// getTemplate gets a template already loaded by name
|
[
"getTemplate",
"gets",
"a",
"template",
"already",
"loaded",
"by",
"name"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L222-L287
|
143,534 |
CloudyKit/jet
|
template.go
|
Execute
|
func (t *Template) Execute(w io.Writer, variables VarMap, data interface{}) error {
return t.ExecuteI18N(nil, w, variables, data)
}
|
go
|
func (t *Template) Execute(w io.Writer, variables VarMap, data interface{}) error {
return t.ExecuteI18N(nil, w, variables, data)
}
|
[
"func",
"(",
"t",
"*",
"Template",
")",
"Execute",
"(",
"w",
"io",
".",
"Writer",
",",
"variables",
"VarMap",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"t",
".",
"ExecuteI18N",
"(",
"nil",
",",
"w",
",",
"variables",
",",
"data",
")",
"\n",
"}"
] |
// Execute executes the template in the w Writer
|
[
"Execute",
"executes",
"the",
"template",
"in",
"the",
"w",
"Writer"
] |
62edd43e4f88c6be452fd5feac77f716f546ebf6
|
https://github.com/CloudyKit/jet/blob/62edd43e4f88c6be452fd5feac77f716f546ebf6/template.go#L382-L384
|
143,535 |
Microsoft/hcsshim
|
internal/wclayer/createlayer.go
|
CreateLayer
|
func CreateLayer(path, parent string) (err error) {
title := "hcsshim::CreateLayer"
fields := logrus.Fields{
"parent": parent,
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = createLayer(&stdDriverInfo, path, parent)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
}
|
go
|
func CreateLayer(path, parent string) (err error) {
title := "hcsshim::CreateLayer"
fields := logrus.Fields{
"parent": parent,
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = createLayer(&stdDriverInfo, path, parent)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
}
|
[
"func",
"CreateLayer",
"(",
"path",
",",
"parent",
"string",
")",
"(",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"parent",
",",
"\"",
"\"",
":",
"path",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"createLayer",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"parent",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CreateLayer creates a new, empty, read-only layer on the filesystem based on
// the parent layer provided.
|
[
"CreateLayer",
"creates",
"a",
"new",
"empty",
"read",
"-",
"only",
"layer",
"on",
"the",
"filesystem",
"based",
"on",
"the",
"parent",
"layer",
"provided",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/createlayer.go#L10-L31
|
143,536 |
Microsoft/hcsshim
|
internal/mergemaps/merge.go
|
MergeJSON
|
func MergeJSON(object interface{}, additionalJSON []byte) (interface{}, error) {
if len(additionalJSON) == 0 {
return object, nil
}
objectJSON, err := json.Marshal(object)
if err != nil {
return nil, err
}
var objectMap, newMap map[string]interface{}
err = json.Unmarshal(objectJSON, &objectMap)
if err != nil {
return nil, err
}
err = json.Unmarshal(additionalJSON, &newMap)
if err != nil {
return nil, err
}
return Merge(newMap, objectMap), nil
}
|
go
|
func MergeJSON(object interface{}, additionalJSON []byte) (interface{}, error) {
if len(additionalJSON) == 0 {
return object, nil
}
objectJSON, err := json.Marshal(object)
if err != nil {
return nil, err
}
var objectMap, newMap map[string]interface{}
err = json.Unmarshal(objectJSON, &objectMap)
if err != nil {
return nil, err
}
err = json.Unmarshal(additionalJSON, &newMap)
if err != nil {
return nil, err
}
return Merge(newMap, objectMap), nil
}
|
[
"func",
"MergeJSON",
"(",
"object",
"interface",
"{",
"}",
",",
"additionalJSON",
"[",
"]",
"byte",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"len",
"(",
"additionalJSON",
")",
"==",
"0",
"{",
"return",
"object",
",",
"nil",
"\n",
"}",
"\n",
"objectJSON",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"object",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"objectMap",
",",
"newMap",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"objectJSON",
",",
"&",
"objectMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"additionalJSON",
",",
"&",
"newMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"Merge",
"(",
"newMap",
",",
"objectMap",
")",
",",
"nil",
"\n",
"}"
] |
// MergeJSON merges the contents of a JSON string into an object representation,
// returning a new object suitable for translating to JSON.
|
[
"MergeJSON",
"merges",
"the",
"contents",
"of",
"a",
"JSON",
"string",
"into",
"an",
"object",
"representation",
"returning",
"a",
"new",
"object",
"suitable",
"for",
"translating",
"to",
"JSON",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/mergemaps/merge.go#L34-L52
|
143,537 |
Microsoft/hcsshim
|
hnsnetwork.go
|
HNSListNetworkRequest
|
func HNSListNetworkRequest(method, path, request string) ([]HNSNetwork, error) {
return hns.HNSListNetworkRequest(method, path, request)
}
|
go
|
func HNSListNetworkRequest(method, path, request string) ([]HNSNetwork, error) {
return hns.HNSListNetworkRequest(method, path, request)
}
|
[
"func",
"HNSListNetworkRequest",
"(",
"method",
",",
"path",
",",
"request",
"string",
")",
"(",
"[",
"]",
"HNSNetwork",
",",
"error",
")",
"{",
"return",
"hns",
".",
"HNSListNetworkRequest",
"(",
"method",
",",
"path",
",",
"request",
")",
"\n",
"}"
] |
// HNSListNetworkRequest makes a HNS call to query the list of available networks
|
[
"HNSListNetworkRequest",
"makes",
"a",
"HNS",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"networks"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hnsnetwork.go#L24-L26
|
143,538 |
Microsoft/hcsshim
|
internal/hcs/errors.go
|
IsTimeout
|
func IsTimeout(err error) bool {
if err, ok := err.(net.Error); ok && err.Timeout() {
return true
}
err = getInnerError(err)
return err == ErrTimeout
}
|
go
|
func IsTimeout(err error) bool {
if err, ok := err.(net.Error); ok && err.Timeout() {
return true
}
err = getInnerError(err)
return err == ErrTimeout
}
|
[
"func",
"IsTimeout",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"net",
".",
"Error",
")",
";",
"ok",
"&&",
"err",
".",
"Timeout",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"err",
"=",
"getInnerError",
"(",
"err",
")",
"\n",
"return",
"err",
"==",
"ErrTimeout",
"\n",
"}"
] |
// IsTimeout returns a boolean indicating whether the error is caused by
// a timeout waiting for the operation to complete.
|
[
"IsTimeout",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"error",
"is",
"caused",
"by",
"a",
"timeout",
"waiting",
"for",
"the",
"operation",
"to",
"complete",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/errors.go#L281-L287
|
143,539 |
Microsoft/hcsshim
|
internal/wclayer/getsharedbaseimages.go
|
GetSharedBaseImages
|
func GetSharedBaseImages() (imageData string, err error) {
title := "hcsshim::GetSharedBaseImages"
logrus.Debug(title)
defer func() {
if err != nil {
logrus.WithError(err).Error(err)
} else {
logrus.WithField("imageData", imageData).Debug(title + " - succeeded")
}
}()
var buffer *uint16
err = getBaseImages(&buffer)
if err != nil {
return "", hcserror.New(err, title+" - failed", "")
}
return interop.ConvertAndFreeCoTaskMemString(buffer), nil
}
|
go
|
func GetSharedBaseImages() (imageData string, err error) {
title := "hcsshim::GetSharedBaseImages"
logrus.Debug(title)
defer func() {
if err != nil {
logrus.WithError(err).Error(err)
} else {
logrus.WithField("imageData", imageData).Debug(title + " - succeeded")
}
}()
var buffer *uint16
err = getBaseImages(&buffer)
if err != nil {
return "", hcserror.New(err, title+" - failed", "")
}
return interop.ConvertAndFreeCoTaskMemString(buffer), nil
}
|
[
"func",
"GetSharedBaseImages",
"(",
")",
"(",
"imageData",
"string",
",",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"logrus",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithField",
"(",
"\"",
"\"",
",",
"imageData",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"buffer",
"*",
"uint16",
"\n",
"err",
"=",
"getBaseImages",
"(",
"&",
"buffer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"interop",
".",
"ConvertAndFreeCoTaskMemString",
"(",
"buffer",
")",
",",
"nil",
"\n",
"}"
] |
// GetSharedBaseImages will enumerate the images stored in the common central
// image store and return descriptive info about those images for the purpose
// of registering them with the graphdriver, graph, and tagstore.
|
[
"GetSharedBaseImages",
"will",
"enumerate",
"the",
"images",
"stored",
"in",
"the",
"common",
"central",
"image",
"store",
"and",
"return",
"descriptive",
"info",
"about",
"those",
"images",
"for",
"the",
"purpose",
"of",
"registering",
"them",
"with",
"the",
"graphdriver",
"graph",
"and",
"tagstore",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/getsharedbaseimages.go#L12-L29
|
143,540 |
Microsoft/hcsshim
|
container.go
|
CreateContainer
|
func CreateContainer(id string, c *ContainerConfig) (Container, error) {
fullConfig, err := mergemaps.MergeJSON(c, createContainerAdditionalJSON)
if err != nil {
return nil, fmt.Errorf("failed to merge additional JSON '%s': %s", createContainerAdditionalJSON, err)
}
system, err := hcs.CreateComputeSystem(id, fullConfig)
if err != nil {
return nil, err
}
return &container{system: system}, err
}
|
go
|
func CreateContainer(id string, c *ContainerConfig) (Container, error) {
fullConfig, err := mergemaps.MergeJSON(c, createContainerAdditionalJSON)
if err != nil {
return nil, fmt.Errorf("failed to merge additional JSON '%s': %s", createContainerAdditionalJSON, err)
}
system, err := hcs.CreateComputeSystem(id, fullConfig)
if err != nil {
return nil, err
}
return &container{system: system}, err
}
|
[
"func",
"CreateContainer",
"(",
"id",
"string",
",",
"c",
"*",
"ContainerConfig",
")",
"(",
"Container",
",",
"error",
")",
"{",
"fullConfig",
",",
"err",
":=",
"mergemaps",
".",
"MergeJSON",
"(",
"c",
",",
"createContainerAdditionalJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"createContainerAdditionalJSON",
",",
"err",
")",
"\n",
"}",
"\n\n",
"system",
",",
"err",
":=",
"hcs",
".",
"CreateComputeSystem",
"(",
"id",
",",
"fullConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"container",
"{",
"system",
":",
"system",
"}",
",",
"err",
"\n",
"}"
] |
// CreateContainer creates a new container with the given configuration but does not start it.
|
[
"CreateContainer",
"creates",
"a",
"new",
"container",
"with",
"the",
"given",
"configuration",
"but",
"does",
"not",
"start",
"it",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L72-L83
|
143,541 |
Microsoft/hcsshim
|
container.go
|
OpenContainer
|
func OpenContainer(id string) (Container, error) {
system, err := hcs.OpenComputeSystem(id)
if err != nil {
return nil, err
}
return &container{system: system}, err
}
|
go
|
func OpenContainer(id string) (Container, error) {
system, err := hcs.OpenComputeSystem(id)
if err != nil {
return nil, err
}
return &container{system: system}, err
}
|
[
"func",
"OpenContainer",
"(",
"id",
"string",
")",
"(",
"Container",
",",
"error",
")",
"{",
"system",
",",
"err",
":=",
"hcs",
".",
"OpenComputeSystem",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"container",
"{",
"system",
":",
"system",
"}",
",",
"err",
"\n",
"}"
] |
// OpenContainer opens an existing container by ID.
|
[
"OpenContainer",
"opens",
"an",
"existing",
"container",
"by",
"ID",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L86-L92
|
143,542 |
Microsoft/hcsshim
|
container.go
|
Wait
|
func (container *container) Wait() error {
err := container.system.Wait()
if err == nil {
err = container.system.ExitError()
}
return convertSystemError(err, container)
}
|
go
|
func (container *container) Wait() error {
err := container.system.Wait()
if err == nil {
err = container.system.ExitError()
}
return convertSystemError(err, container)
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"Wait",
"(",
")",
"error",
"{",
"err",
":=",
"container",
".",
"system",
".",
"Wait",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"container",
".",
"system",
".",
"ExitError",
"(",
")",
"\n",
"}",
"\n",
"return",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}"
] |
// Waits synchronously waits for the container to shutdown or terminate.
|
[
"Waits",
"synchronously",
"waits",
"for",
"the",
"container",
"to",
"shutdown",
"or",
"terminate",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L123-L129
|
143,543 |
Microsoft/hcsshim
|
container.go
|
WaitTimeout
|
func (container *container) WaitTimeout(timeout time.Duration) error {
container.waitOnce.Do(func() {
container.waitCh = make(chan struct{})
go func() {
container.waitErr = container.Wait()
close(container.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ContainerError{Container: container, Err: ErrTimeout, Operation: "hcsshim::ComputeSystem::Wait"}
case <-container.waitCh:
return container.waitErr
}
}
|
go
|
func (container *container) WaitTimeout(timeout time.Duration) error {
container.waitOnce.Do(func() {
container.waitCh = make(chan struct{})
go func() {
container.waitErr = container.Wait()
close(container.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ContainerError{Container: container, Err: ErrTimeout, Operation: "hcsshim::ComputeSystem::Wait"}
case <-container.waitCh:
return container.waitErr
}
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"WaitTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"container",
".",
"waitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"container",
".",
"waitCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"container",
".",
"waitErr",
"=",
"container",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"container",
".",
"waitCh",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
")",
"\n",
"t",
":=",
"time",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"defer",
"t",
".",
"Stop",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"t",
".",
"C",
":",
"return",
"&",
"ContainerError",
"{",
"Container",
":",
"container",
",",
"Err",
":",
"ErrTimeout",
",",
"Operation",
":",
"\"",
"\"",
"}",
"\n",
"case",
"<-",
"container",
".",
"waitCh",
":",
"return",
"container",
".",
"waitErr",
"\n",
"}",
"\n",
"}"
] |
// WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
// returns false if timeout occurs.
|
[
"WaitTimeout",
"synchronously",
"waits",
"for",
"the",
"container",
"to",
"terminate",
"or",
"the",
"duration",
"to",
"elapse",
".",
"It",
"returns",
"false",
"if",
"timeout",
"occurs",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L133-L149
|
143,544 |
Microsoft/hcsshim
|
container.go
|
Statistics
|
func (container *container) Statistics() (Statistics, error) {
properties, err := container.system.Properties(schema1.PropertyTypeStatistics)
if err != nil {
return Statistics{}, convertSystemError(err, container)
}
return properties.Statistics, nil
}
|
go
|
func (container *container) Statistics() (Statistics, error) {
properties, err := container.system.Properties(schema1.PropertyTypeStatistics)
if err != nil {
return Statistics{}, convertSystemError(err, container)
}
return properties.Statistics, nil
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"Statistics",
"(",
")",
"(",
"Statistics",
",",
"error",
")",
"{",
"properties",
",",
"err",
":=",
"container",
".",
"system",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeStatistics",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Statistics",
"{",
"}",
",",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}",
"\n\n",
"return",
"properties",
".",
"Statistics",
",",
"nil",
"\n",
"}"
] |
// Statistics returns statistics for the container. This is a legacy v1 call
|
[
"Statistics",
"returns",
"statistics",
"for",
"the",
"container",
".",
"This",
"is",
"a",
"legacy",
"v1",
"call"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L167-L174
|
143,545 |
Microsoft/hcsshim
|
container.go
|
ProcessList
|
func (container *container) ProcessList() ([]ProcessListItem, error) {
properties, err := container.system.Properties(schema1.PropertyTypeProcessList)
if err != nil {
return nil, convertSystemError(err, container)
}
return properties.ProcessList, nil
}
|
go
|
func (container *container) ProcessList() ([]ProcessListItem, error) {
properties, err := container.system.Properties(schema1.PropertyTypeProcessList)
if err != nil {
return nil, convertSystemError(err, container)
}
return properties.ProcessList, nil
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"ProcessList",
"(",
")",
"(",
"[",
"]",
"ProcessListItem",
",",
"error",
")",
"{",
"properties",
",",
"err",
":=",
"container",
".",
"system",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeProcessList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}",
"\n\n",
"return",
"properties",
".",
"ProcessList",
",",
"nil",
"\n",
"}"
] |
// ProcessList returns an array of ProcessListItems for the container. This is a legacy v1 call
|
[
"ProcessList",
"returns",
"an",
"array",
"of",
"ProcessListItems",
"for",
"the",
"container",
".",
"This",
"is",
"a",
"legacy",
"v1",
"call"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L177-L184
|
143,546 |
Microsoft/hcsshim
|
container.go
|
MappedVirtualDisks
|
func (container *container) MappedVirtualDisks() (map[int]MappedVirtualDiskController, error) {
properties, err := container.system.Properties(schema1.PropertyTypeMappedVirtualDisk)
if err != nil {
return nil, convertSystemError(err, container)
}
return properties.MappedVirtualDiskControllers, nil
}
|
go
|
func (container *container) MappedVirtualDisks() (map[int]MappedVirtualDiskController, error) {
properties, err := container.system.Properties(schema1.PropertyTypeMappedVirtualDisk)
if err != nil {
return nil, convertSystemError(err, container)
}
return properties.MappedVirtualDiskControllers, nil
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"MappedVirtualDisks",
"(",
")",
"(",
"map",
"[",
"int",
"]",
"MappedVirtualDiskController",
",",
"error",
")",
"{",
"properties",
",",
"err",
":=",
"container",
".",
"system",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeMappedVirtualDisk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}",
"\n\n",
"return",
"properties",
".",
"MappedVirtualDiskControllers",
",",
"nil",
"\n",
"}"
] |
// This is a legacy v1 call
|
[
"This",
"is",
"a",
"legacy",
"v1",
"call"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L187-L194
|
143,547 |
Microsoft/hcsshim
|
container.go
|
CreateProcess
|
func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
p, err := container.system.CreateProcess(c)
if err != nil {
return nil, convertSystemError(err, container)
}
return &process{p: p}, nil
}
|
go
|
func (container *container) CreateProcess(c *ProcessConfig) (Process, error) {
p, err := container.system.CreateProcess(c)
if err != nil {
return nil, convertSystemError(err, container)
}
return &process{p: p}, nil
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"CreateProcess",
"(",
"c",
"*",
"ProcessConfig",
")",
"(",
"Process",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"container",
".",
"system",
".",
"CreateProcess",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}",
"\n",
"return",
"&",
"process",
"{",
"p",
":",
"p",
"}",
",",
"nil",
"\n",
"}"
] |
// CreateProcess launches a new process within the container.
|
[
"CreateProcess",
"launches",
"a",
"new",
"process",
"within",
"the",
"container",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L197-L203
|
143,548 |
Microsoft/hcsshim
|
container.go
|
OpenProcess
|
func (container *container) OpenProcess(pid int) (Process, error) {
p, err := container.system.OpenProcess(pid)
if err != nil {
return nil, convertSystemError(err, container)
}
return &process{p: p}, nil
}
|
go
|
func (container *container) OpenProcess(pid int) (Process, error) {
p, err := container.system.OpenProcess(pid)
if err != nil {
return nil, convertSystemError(err, container)
}
return &process{p: p}, nil
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"OpenProcess",
"(",
"pid",
"int",
")",
"(",
"Process",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"container",
".",
"system",
".",
"OpenProcess",
"(",
"pid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"convertSystemError",
"(",
"err",
",",
"container",
")",
"\n",
"}",
"\n",
"return",
"&",
"process",
"{",
"p",
":",
"p",
"}",
",",
"nil",
"\n",
"}"
] |
// OpenProcess gets an interface to an existing process within the container.
|
[
"OpenProcess",
"gets",
"an",
"interface",
"to",
"an",
"existing",
"process",
"within",
"the",
"container",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L206-L212
|
143,549 |
Microsoft/hcsshim
|
container.go
|
Modify
|
func (container *container) Modify(config *ResourceModificationRequestResponse) error {
return convertSystemError(container.system.Modify(config), container)
}
|
go
|
func (container *container) Modify(config *ResourceModificationRequestResponse) error {
return convertSystemError(container.system.Modify(config), container)
}
|
[
"func",
"(",
"container",
"*",
"container",
")",
"Modify",
"(",
"config",
"*",
"ResourceModificationRequestResponse",
")",
"error",
"{",
"return",
"convertSystemError",
"(",
"container",
".",
"system",
".",
"Modify",
"(",
"config",
")",
",",
"container",
")",
"\n",
"}"
] |
// Modify the System
|
[
"Modify",
"the",
"System"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/container.go#L220-L222
|
143,550 |
Microsoft/hcsshim
|
internal/wclayer/nametoguid.go
|
NameToGuid
|
func NameToGuid(name string) (id guid.GUID, err error) {
title := "hcsshim::NameToGuid"
fields := logrus.Fields{
"name": name,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = nameToGuid(name, &id)
if err != nil {
err = hcserror.New(err, title+" - failed", "")
return
}
fields["guid"] = id.String()
return
}
|
go
|
func NameToGuid(name string) (id guid.GUID, err error) {
title := "hcsshim::NameToGuid"
fields := logrus.Fields{
"name": name,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = nameToGuid(name, &id)
if err != nil {
err = hcserror.New(err, title+" - failed", "")
return
}
fields["guid"] = id.String()
return
}
|
[
"func",
"NameToGuid",
"(",
"name",
"string",
")",
"(",
"id",
"guid",
".",
"GUID",
",",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"name",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"nameToGuid",
"(",
"name",
",",
"&",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"id",
".",
"String",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// NameToGuid converts the given string into a GUID using the algorithm in the
// Host Compute Service, ensuring GUIDs generated with the same string are common
// across all clients.
|
[
"NameToGuid",
"converts",
"the",
"given",
"string",
"into",
"a",
"GUID",
"using",
"the",
"algorithm",
"in",
"the",
"Host",
"Compute",
"Service",
"ensuring",
"GUIDs",
"generated",
"with",
"the",
"same",
"string",
"are",
"common",
"across",
"all",
"clients",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/nametoguid.go#L12-L34
|
143,551 |
Microsoft/hcsshim
|
internal/copyfile/copyfile.go
|
CopyFile
|
func CopyFile(srcFile, destFile string, overwrite bool) error {
var bFailIfExists uint32 = 1
if overwrite {
bFailIfExists = 0
}
lpExistingFileName, err := syscall.UTF16PtrFromString(srcFile)
if err != nil {
return err
}
lpNewFileName, err := syscall.UTF16PtrFromString(destFile)
if err != nil {
return err
}
r1, _, err := syscall.Syscall(
procCopyFileW.Addr(),
3,
uintptr(unsafe.Pointer(lpExistingFileName)),
uintptr(unsafe.Pointer(lpNewFileName)),
uintptr(bFailIfExists))
if r1 == 0 {
return fmt.Errorf("failed CopyFileW Win32 call from '%s' to '%s': %s", srcFile, destFile, err)
}
return nil
}
|
go
|
func CopyFile(srcFile, destFile string, overwrite bool) error {
var bFailIfExists uint32 = 1
if overwrite {
bFailIfExists = 0
}
lpExistingFileName, err := syscall.UTF16PtrFromString(srcFile)
if err != nil {
return err
}
lpNewFileName, err := syscall.UTF16PtrFromString(destFile)
if err != nil {
return err
}
r1, _, err := syscall.Syscall(
procCopyFileW.Addr(),
3,
uintptr(unsafe.Pointer(lpExistingFileName)),
uintptr(unsafe.Pointer(lpNewFileName)),
uintptr(bFailIfExists))
if r1 == 0 {
return fmt.Errorf("failed CopyFileW Win32 call from '%s' to '%s': %s", srcFile, destFile, err)
}
return nil
}
|
[
"func",
"CopyFile",
"(",
"srcFile",
",",
"destFile",
"string",
",",
"overwrite",
"bool",
")",
"error",
"{",
"var",
"bFailIfExists",
"uint32",
"=",
"1",
"\n",
"if",
"overwrite",
"{",
"bFailIfExists",
"=",
"0",
"\n",
"}",
"\n\n",
"lpExistingFileName",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"srcFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"lpNewFileName",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"destFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r1",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall",
"(",
"procCopyFileW",
".",
"Addr",
"(",
")",
",",
"3",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"lpExistingFileName",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"lpNewFileName",
")",
")",
",",
"uintptr",
"(",
"bFailIfExists",
")",
")",
"\n",
"if",
"r1",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"srcFile",
",",
"destFile",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CopyFile is a utility for copying a file - used for the LCOW scratch cache.
// Uses CopyFileW win32 API for performance.
|
[
"CopyFile",
"is",
"a",
"utility",
"for",
"copying",
"a",
"file",
"-",
"used",
"for",
"the",
"LCOW",
"scratch",
"cache",
".",
"Uses",
"CopyFileW",
"win32",
"API",
"for",
"performance",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/copyfile/copyfile.go#L16-L40
|
143,552 |
Microsoft/hcsshim
|
internal/wclayer/exportlayer.go
|
NewLayerReader
|
func NewLayerReader(path string, parentLayerPaths []string) (LayerReader, error) {
exportPath, err := ioutil.TempDir("", "hcs")
if err != nil {
return nil, err
}
err = ExportLayer(path, exportPath, parentLayerPaths)
if err != nil {
os.RemoveAll(exportPath)
return nil, err
}
return &legacyLayerReaderWrapper{newLegacyLayerReader(exportPath)}, nil
}
|
go
|
func NewLayerReader(path string, parentLayerPaths []string) (LayerReader, error) {
exportPath, err := ioutil.TempDir("", "hcs")
if err != nil {
return nil, err
}
err = ExportLayer(path, exportPath, parentLayerPaths)
if err != nil {
os.RemoveAll(exportPath)
return nil, err
}
return &legacyLayerReaderWrapper{newLegacyLayerReader(exportPath)}, nil
}
|
[
"func",
"NewLayerReader",
"(",
"path",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"(",
"LayerReader",
",",
"error",
")",
"{",
"exportPath",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"ExportLayer",
"(",
"path",
",",
"exportPath",
",",
"parentLayerPaths",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"os",
".",
"RemoveAll",
"(",
"exportPath",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"legacyLayerReaderWrapper",
"{",
"newLegacyLayerReader",
"(",
"exportPath",
")",
"}",
",",
"nil",
"\n",
"}"
] |
// NewLayerReader returns a new layer reader for reading the contents of an on-disk layer.
// The caller must have taken the SeBackupPrivilege privilege
// to call this and any methods on the resulting LayerReader.
|
[
"NewLayerReader",
"returns",
"a",
"new",
"layer",
"reader",
"for",
"reading",
"the",
"contents",
"of",
"an",
"on",
"-",
"disk",
"layer",
".",
"The",
"caller",
"must",
"have",
"taken",
"the",
"SeBackupPrivilege",
"privilege",
"to",
"call",
"this",
"and",
"any",
"methods",
"on",
"the",
"resulting",
"LayerReader",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/exportlayer.go#L55-L66
|
143,553 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/exec_hcs.go
|
waitForContainerExit
|
func (he *hcsExec) waitForContainerExit() {
cexit := make(chan struct{})
go func() {
he.c.Wait()
close(cexit)
}()
select {
case <-cexit:
// Container exited first. We need to force the process into the exited
// state and cleanup any resources
he.sl.Lock()
switch he.state {
case shimExecStateCreated:
he.exitFromCreatedL(1)
case shimExecStateRunning:
// Kill the process to unblock `he.waitForExit`.
he.p.Kill()
}
he.sl.Unlock()
case <-he.processDone:
// Process exited first. This is the normal case do nothing because
// `he.waitForExit` will release any waiters.
}
}
|
go
|
func (he *hcsExec) waitForContainerExit() {
cexit := make(chan struct{})
go func() {
he.c.Wait()
close(cexit)
}()
select {
case <-cexit:
// Container exited first. We need to force the process into the exited
// state and cleanup any resources
he.sl.Lock()
switch he.state {
case shimExecStateCreated:
he.exitFromCreatedL(1)
case shimExecStateRunning:
// Kill the process to unblock `he.waitForExit`.
he.p.Kill()
}
he.sl.Unlock()
case <-he.processDone:
// Process exited first. This is the normal case do nothing because
// `he.waitForExit` will release any waiters.
}
}
|
[
"func",
"(",
"he",
"*",
"hcsExec",
")",
"waitForContainerExit",
"(",
")",
"{",
"cexit",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"he",
".",
"c",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"cexit",
")",
"\n",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"cexit",
":",
"// Container exited first. We need to force the process into the exited",
"// state and cleanup any resources",
"he",
".",
"sl",
".",
"Lock",
"(",
")",
"\n",
"switch",
"he",
".",
"state",
"{",
"case",
"shimExecStateCreated",
":",
"he",
".",
"exitFromCreatedL",
"(",
"1",
")",
"\n",
"case",
"shimExecStateRunning",
":",
"// Kill the process to unblock `he.waitForExit`.",
"he",
".",
"p",
".",
"Kill",
"(",
")",
"\n",
"}",
"\n",
"he",
".",
"sl",
".",
"Unlock",
"(",
")",
"\n",
"case",
"<-",
"he",
".",
"processDone",
":",
"// Process exited first. This is the normal case do nothing because",
"// `he.waitForExit` will release any waiters.",
"}",
"\n",
"}"
] |
// waitForContainerExit waits for `he.c` to exit. Depending on the exec's state
// will forcibly transition this exec to the exited state and unblock any
// waiters.
//
// This MUST be called via a goroutine at exec create.
|
[
"waitForContainerExit",
"waits",
"for",
"he",
".",
"c",
"to",
"exit",
".",
"Depending",
"on",
"the",
"exec",
"s",
"state",
"will",
"forcibly",
"transition",
"this",
"exec",
"to",
"the",
"exited",
"state",
"and",
"unblock",
"any",
"waiters",
".",
"This",
"MUST",
"be",
"called",
"via",
"a",
"goroutine",
"at",
"exec",
"create",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/exec_hcs.go#L633-L656
|
143,554 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/exec_hcs.go
|
escapeArgs
|
func escapeArgs(args []string) string {
escapedArgs := make([]string, len(args))
for i, a := range args {
escapedArgs[i] = windows.EscapeArg(a)
}
return strings.Join(escapedArgs, " ")
}
|
go
|
func escapeArgs(args []string) string {
escapedArgs := make([]string, len(args))
for i, a := range args {
escapedArgs[i] = windows.EscapeArg(a)
}
return strings.Join(escapedArgs, " ")
}
|
[
"func",
"escapeArgs",
"(",
"args",
"[",
"]",
"string",
")",
"string",
"{",
"escapedArgs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"a",
":=",
"range",
"args",
"{",
"escapedArgs",
"[",
"i",
"]",
"=",
"windows",
".",
"EscapeArg",
"(",
"a",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"escapedArgs",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// escapeArgs makes a Windows-style escaped command line from a set of arguments
|
[
"escapeArgs",
"makes",
"a",
"Windows",
"-",
"style",
"escaped",
"command",
"line",
"from",
"a",
"set",
"of",
"arguments"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/exec_hcs.go#L659-L665
|
143,555 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/serve.go
|
createEvent
|
func createEvent(event string) (windows.Handle, error) {
ev, _ := windows.UTF16PtrFromString(event)
sd, err := winio.SddlToSecurityDescriptor("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
if err != nil {
return 0, errors.Wrapf(err, "failed to get security descriptor for event '%s'", event)
}
var sa windows.SecurityAttributes
sa.Length = uint32(unsafe.Sizeof(sa))
sa.InheritHandle = 1
sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0]))
h, err := windows.CreateEvent(&sa, 0, 0, ev)
if h == 0 || err != nil {
return 0, errors.Wrapf(err, "failed to create event '%s'", event)
}
return h, nil
}
|
go
|
func createEvent(event string) (windows.Handle, error) {
ev, _ := windows.UTF16PtrFromString(event)
sd, err := winio.SddlToSecurityDescriptor("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
if err != nil {
return 0, errors.Wrapf(err, "failed to get security descriptor for event '%s'", event)
}
var sa windows.SecurityAttributes
sa.Length = uint32(unsafe.Sizeof(sa))
sa.InheritHandle = 1
sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0]))
h, err := windows.CreateEvent(&sa, 0, 0, ev)
if h == 0 || err != nil {
return 0, errors.Wrapf(err, "failed to create event '%s'", event)
}
return h, nil
}
|
[
"func",
"createEvent",
"(",
"event",
"string",
")",
"(",
"windows",
".",
"Handle",
",",
"error",
")",
"{",
"ev",
",",
"_",
":=",
"windows",
".",
"UTF16PtrFromString",
"(",
"event",
")",
"\n",
"sd",
",",
"err",
":=",
"winio",
".",
"SddlToSecurityDescriptor",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"event",
")",
"\n",
"}",
"\n",
"var",
"sa",
"windows",
".",
"SecurityAttributes",
"\n",
"sa",
".",
"Length",
"=",
"uint32",
"(",
"unsafe",
".",
"Sizeof",
"(",
"sa",
")",
")",
"\n",
"sa",
".",
"InheritHandle",
"=",
"1",
"\n",
"sa",
".",
"SecurityDescriptor",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"sd",
"[",
"0",
"]",
")",
")",
"\n",
"h",
",",
"err",
":=",
"windows",
".",
"CreateEvent",
"(",
"&",
"sa",
",",
"0",
",",
"0",
",",
"ev",
")",
"\n",
"if",
"h",
"==",
"0",
"||",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"event",
")",
"\n",
"}",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
] |
// createEvent creates a Windows event ACL'd to builtin administrator
// and local system. Can use docker-signal to signal the event.
|
[
"createEvent",
"creates",
"a",
"Windows",
"event",
"ACL",
"d",
"to",
"builtin",
"administrator",
"and",
"local",
"system",
".",
"Can",
"use",
"docker",
"-",
"signal",
"to",
"signal",
"the",
"event",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/serve.go#L167-L182
|
143,556 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/serve.go
|
setupDebuggerEvent
|
func setupDebuggerEvent() {
if os.Getenv("CONTAINERD_SHIM_RUNHCS_V1_WAIT_DEBUGGER") == "" {
return
}
event := "Global\\debugger-" + fmt.Sprint(os.Getpid())
handle, err := createEvent(event)
if err != nil {
return
}
logrus.Infof("Halting until %s is signalled", event)
windows.WaitForSingleObject(handle, windows.INFINITE)
return
}
|
go
|
func setupDebuggerEvent() {
if os.Getenv("CONTAINERD_SHIM_RUNHCS_V1_WAIT_DEBUGGER") == "" {
return
}
event := "Global\\debugger-" + fmt.Sprint(os.Getpid())
handle, err := createEvent(event)
if err != nil {
return
}
logrus.Infof("Halting until %s is signalled", event)
windows.WaitForSingleObject(handle, windows.INFINITE)
return
}
|
[
"func",
"setupDebuggerEvent",
"(",
")",
"{",
"if",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"event",
":=",
"\"",
"\\\\",
"\"",
"+",
"fmt",
".",
"Sprint",
"(",
"os",
".",
"Getpid",
"(",
")",
")",
"\n",
"handle",
",",
"err",
":=",
"createEvent",
"(",
"event",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"event",
")",
"\n",
"windows",
".",
"WaitForSingleObject",
"(",
"handle",
",",
"windows",
".",
"INFINITE",
")",
"\n",
"return",
"\n",
"}"
] |
// setupDebuggerEvent listens for an event to allow a debugger such as delve
// to attach for advanced debugging. It's called when handling a ContainerCreate
|
[
"setupDebuggerEvent",
"listens",
"for",
"an",
"event",
"to",
"allow",
"a",
"debugger",
"such",
"as",
"delve",
"to",
"attach",
"for",
"advanced",
"debugging",
".",
"It",
"s",
"called",
"when",
"handling",
"a",
"ContainerCreate"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/serve.go#L186-L198
|
143,557 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/serve.go
|
setupDumpStacks
|
func setupDumpStacks() {
event := "Global\\stackdump-" + fmt.Sprint(os.Getpid())
handle, err := createEvent(event)
if err != nil {
return
}
go func() {
for {
windows.WaitForSingleObject(handle, windows.INFINITE)
dumpStacks(true)
}
}()
return
}
|
go
|
func setupDumpStacks() {
event := "Global\\stackdump-" + fmt.Sprint(os.Getpid())
handle, err := createEvent(event)
if err != nil {
return
}
go func() {
for {
windows.WaitForSingleObject(handle, windows.INFINITE)
dumpStacks(true)
}
}()
return
}
|
[
"func",
"setupDumpStacks",
"(",
")",
"{",
"event",
":=",
"\"",
"\\\\",
"\"",
"+",
"fmt",
".",
"Sprint",
"(",
"os",
".",
"Getpid",
"(",
")",
")",
"\n",
"handle",
",",
"err",
":=",
"createEvent",
"(",
"event",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"windows",
".",
"WaitForSingleObject",
"(",
"handle",
",",
"windows",
".",
"INFINITE",
")",
"\n",
"dumpStacks",
"(",
"true",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// setupDumpStacks listens for an event which when signalled dumps the
// stacks from this process to the log output.
|
[
"setupDumpStacks",
"listens",
"for",
"an",
"event",
"which",
"when",
"signalled",
"dumps",
"the",
"stacks",
"from",
"this",
"process",
"to",
"the",
"log",
"output",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/serve.go#L202-L215
|
143,558 |
Microsoft/hcsshim
|
internal/runhcs/vm.go
|
IssueVMRequest
|
func IssueVMRequest(pipepath string, req *VMRequest) error {
pipe, err := winio.DialPipe(pipepath, nil)
if err != nil {
return err
}
defer pipe.Close()
if err := json.NewEncoder(pipe).Encode(req); err != nil {
return err
}
if err := GetErrorFromPipe(pipe, nil); err != nil {
return err
}
return nil
}
|
go
|
func IssueVMRequest(pipepath string, req *VMRequest) error {
pipe, err := winio.DialPipe(pipepath, nil)
if err != nil {
return err
}
defer pipe.Close()
if err := json.NewEncoder(pipe).Encode(req); err != nil {
return err
}
if err := GetErrorFromPipe(pipe, nil); err != nil {
return err
}
return nil
}
|
[
"func",
"IssueVMRequest",
"(",
"pipepath",
"string",
",",
"req",
"*",
"VMRequest",
")",
"error",
"{",
"pipe",
",",
"err",
":=",
"winio",
".",
"DialPipe",
"(",
"pipepath",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"pipe",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"pipe",
")",
".",
"Encode",
"(",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"GetErrorFromPipe",
"(",
"pipe",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// IssueVMRequest issues a request to a shim at the given pipe.
|
[
"IssueVMRequest",
"issues",
"a",
"request",
"to",
"a",
"shim",
"at",
"the",
"given",
"pipe",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/runhcs/vm.go#L30-L43
|
143,559 |
Microsoft/hcsshim
|
internal/copywithtimeout/copywithtimeout.go
|
Copy
|
func Copy(dst io.Writer, src io.Reader, size int64, context string, timeout time.Duration) (int64, error) {
logrus.WithFields(logrus.Fields{
"stdval": context,
"size": size,
"timeout": timeout,
}).Debug("hcsshim::copywithtimeout - Begin")
type resultType struct {
err error
bytes int64
}
done := make(chan resultType, 1)
go func() {
result := resultType{}
if logrus.GetLevel() < logrus.DebugLevel || logDataByteCount == 0 {
result.bytes, result.err = io.Copy(dst, src)
} else {
// In advanced debug mode where we log (hexdump format) what is copied
// up to the number of bytes defined by environment variable
// HCSSHIM_LOG_DATA_BYTE_COUNT
var buf bytes.Buffer
tee := io.TeeReader(src, &buf)
result.bytes, result.err = io.Copy(dst, tee)
if result.err == nil {
size := result.bytes
if size > logDataByteCount {
size = logDataByteCount
}
if size > 0 {
bytes := make([]byte, size)
if _, err := buf.Read(bytes); err == nil {
logrus.Debugf("hcsshim::copyWithTimeout - Read bytes\n%s", hex.Dump(bytes))
}
}
}
}
done <- result
}()
var result resultType
timedout := time.After(timeout)
select {
case <-timedout:
return 0, fmt.Errorf("hcsshim::copyWithTimeout: timed out (%s)", context)
case result = <-done:
if result.err != nil && result.err != io.EOF {
// See https://github.com/golang/go/blob/f3f29d1dea525f48995c1693c609f5e67c046893/src/os/exec/exec_windows.go for a clue as to why we are doing this :)
if se, ok := result.err.(syscall.Errno); ok {
const (
errNoData = syscall.Errno(232)
errBrokenPipe = syscall.Errno(109)
)
if se == errNoData || se == errBrokenPipe {
logrus.WithFields(logrus.Fields{
"stdval": context,
logrus.ErrorKey: se,
}).Debug("hcsshim::copywithtimeout - End")
return result.bytes, nil
}
}
return 0, fmt.Errorf("hcsshim::copyWithTimeout: error reading: '%s' after %d bytes (%s)", result.err, result.bytes, context)
}
}
logrus.WithFields(logrus.Fields{
"stdval": context,
"copied-bytes": result.bytes,
}).Debug("hcsshim::copywithtimeout - Completed Successfully")
return result.bytes, nil
}
|
go
|
func Copy(dst io.Writer, src io.Reader, size int64, context string, timeout time.Duration) (int64, error) {
logrus.WithFields(logrus.Fields{
"stdval": context,
"size": size,
"timeout": timeout,
}).Debug("hcsshim::copywithtimeout - Begin")
type resultType struct {
err error
bytes int64
}
done := make(chan resultType, 1)
go func() {
result := resultType{}
if logrus.GetLevel() < logrus.DebugLevel || logDataByteCount == 0 {
result.bytes, result.err = io.Copy(dst, src)
} else {
// In advanced debug mode where we log (hexdump format) what is copied
// up to the number of bytes defined by environment variable
// HCSSHIM_LOG_DATA_BYTE_COUNT
var buf bytes.Buffer
tee := io.TeeReader(src, &buf)
result.bytes, result.err = io.Copy(dst, tee)
if result.err == nil {
size := result.bytes
if size > logDataByteCount {
size = logDataByteCount
}
if size > 0 {
bytes := make([]byte, size)
if _, err := buf.Read(bytes); err == nil {
logrus.Debugf("hcsshim::copyWithTimeout - Read bytes\n%s", hex.Dump(bytes))
}
}
}
}
done <- result
}()
var result resultType
timedout := time.After(timeout)
select {
case <-timedout:
return 0, fmt.Errorf("hcsshim::copyWithTimeout: timed out (%s)", context)
case result = <-done:
if result.err != nil && result.err != io.EOF {
// See https://github.com/golang/go/blob/f3f29d1dea525f48995c1693c609f5e67c046893/src/os/exec/exec_windows.go for a clue as to why we are doing this :)
if se, ok := result.err.(syscall.Errno); ok {
const (
errNoData = syscall.Errno(232)
errBrokenPipe = syscall.Errno(109)
)
if se == errNoData || se == errBrokenPipe {
logrus.WithFields(logrus.Fields{
"stdval": context,
logrus.ErrorKey: se,
}).Debug("hcsshim::copywithtimeout - End")
return result.bytes, nil
}
}
return 0, fmt.Errorf("hcsshim::copyWithTimeout: error reading: '%s' after %d bytes (%s)", result.err, result.bytes, context)
}
}
logrus.WithFields(logrus.Fields{
"stdval": context,
"copied-bytes": result.bytes,
}).Debug("hcsshim::copywithtimeout - Completed Successfully")
return result.bytes, nil
}
|
[
"func",
"Copy",
"(",
"dst",
"io",
".",
"Writer",
",",
"src",
"io",
".",
"Reader",
",",
"size",
"int64",
",",
"context",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"int64",
",",
"error",
")",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"size",
",",
"\"",
"\"",
":",
"timeout",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"type",
"resultType",
"struct",
"{",
"err",
"error",
"\n",
"bytes",
"int64",
"\n",
"}",
"\n\n",
"done",
":=",
"make",
"(",
"chan",
"resultType",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"result",
":=",
"resultType",
"{",
"}",
"\n",
"if",
"logrus",
".",
"GetLevel",
"(",
")",
"<",
"logrus",
".",
"DebugLevel",
"||",
"logDataByteCount",
"==",
"0",
"{",
"result",
".",
"bytes",
",",
"result",
".",
"err",
"=",
"io",
".",
"Copy",
"(",
"dst",
",",
"src",
")",
"\n",
"}",
"else",
"{",
"// In advanced debug mode where we log (hexdump format) what is copied",
"// up to the number of bytes defined by environment variable",
"// HCSSHIM_LOG_DATA_BYTE_COUNT",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"tee",
":=",
"io",
".",
"TeeReader",
"(",
"src",
",",
"&",
"buf",
")",
"\n",
"result",
".",
"bytes",
",",
"result",
".",
"err",
"=",
"io",
".",
"Copy",
"(",
"dst",
",",
"tee",
")",
"\n",
"if",
"result",
".",
"err",
"==",
"nil",
"{",
"size",
":=",
"result",
".",
"bytes",
"\n",
"if",
"size",
">",
"logDataByteCount",
"{",
"size",
"=",
"logDataByteCount",
"\n",
"}",
"\n",
"if",
"size",
">",
"0",
"{",
"bytes",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"buf",
".",
"Read",
"(",
"bytes",
")",
";",
"err",
"==",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"hex",
".",
"Dump",
"(",
"bytes",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"done",
"<-",
"result",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"result",
"resultType",
"\n",
"timedout",
":=",
"time",
".",
"After",
"(",
"timeout",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"timedout",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"context",
")",
"\n",
"case",
"result",
"=",
"<-",
"done",
":",
"if",
"result",
".",
"err",
"!=",
"nil",
"&&",
"result",
".",
"err",
"!=",
"io",
".",
"EOF",
"{",
"// See https://github.com/golang/go/blob/f3f29d1dea525f48995c1693c609f5e67c046893/src/os/exec/exec_windows.go for a clue as to why we are doing this :)",
"if",
"se",
",",
"ok",
":=",
"result",
".",
"err",
".",
"(",
"syscall",
".",
"Errno",
")",
";",
"ok",
"{",
"const",
"(",
"errNoData",
"=",
"syscall",
".",
"Errno",
"(",
"232",
")",
"\n",
"errBrokenPipe",
"=",
"syscall",
".",
"Errno",
"(",
"109",
")",
"\n",
")",
"\n",
"if",
"se",
"==",
"errNoData",
"||",
"se",
"==",
"errBrokenPipe",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"logrus",
".",
"ErrorKey",
":",
"se",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"result",
".",
"bytes",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"result",
".",
"err",
",",
"result",
".",
"bytes",
",",
"context",
")",
"\n",
"}",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"result",
".",
"bytes",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"result",
".",
"bytes",
",",
"nil",
"\n",
"}"
] |
// Copy is a wrapper for io.Copy using a timeout duration
|
[
"Copy",
"is",
"a",
"wrapper",
"for",
"io",
".",
"Copy",
"using",
"a",
"timeout",
"duration"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/copywithtimeout/copywithtimeout.go#L33-L103
|
143,560 |
Microsoft/hcsshim
|
internal/uvm/vsmb.go
|
findVSMBShare
|
func (uvm *UtilityVM) findVSMBShare(hostPath string) (*vsmbShare, error) {
share, ok := uvm.vsmbShares[hostPath]
if !ok {
return nil, ErrNotAttached
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"name": share.name,
"refCount": share.refCount,
}).Debug("uvm::findVSMBShare")
return share, nil
}
|
go
|
func (uvm *UtilityVM) findVSMBShare(hostPath string) (*vsmbShare, error) {
share, ok := uvm.vsmbShares[hostPath]
if !ok {
return nil, ErrNotAttached
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"name": share.name,
"refCount": share.refCount,
}).Debug("uvm::findVSMBShare")
return share, nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"findVSMBShare",
"(",
"hostPath",
"string",
")",
"(",
"*",
"vsmbShare",
",",
"error",
")",
"{",
"share",
",",
"ok",
":=",
"uvm",
".",
"vsmbShares",
"[",
"hostPath",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrNotAttached",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"\"",
"\"",
":",
"share",
".",
"name",
",",
"\"",
"\"",
":",
"share",
".",
"refCount",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"share",
",",
"nil",
"\n",
"}"
] |
// findVSMBShare finds a share by `hostPath`. If not found returns `ErrNotAttached`.
|
[
"findVSMBShare",
"finds",
"a",
"share",
"by",
"hostPath",
".",
"If",
"not",
"found",
"returns",
"ErrNotAttached",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vsmb.go#L14-L26
|
143,561 |
Microsoft/hcsshim
|
internal/uvm/vsmb.go
|
AddVSMB
|
func (uvm *UtilityVM) AddVSMB(hostPath string, guestRequest interface{}, options *hcsschema.VirtualSmbShareOptions) (err error) {
op := "uvm::AddVSMB"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debugf(op+" - GuestRequest: %+v, Options: %+v - Begin Operation", guestRequest, options)
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "windows" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err == ErrNotAttached {
uvm.vsmbCounter++
shareName := "s" + strconv.FormatUint(uvm.vsmbCounter, 16)
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Add,
Settings: hcsschema.VirtualSmbShare{
Name: shareName,
Options: options,
Path: hostPath,
},
ResourcePath: "VirtualMachine/Devices/VirtualSmb/Shares",
}
if err := uvm.Modify(modification); err != nil {
return err
}
share = &vsmbShare{
name: shareName,
guestRequest: guestRequest,
}
uvm.vsmbShares[hostPath] = share
}
share.refCount++
return nil
}
|
go
|
func (uvm *UtilityVM) AddVSMB(hostPath string, guestRequest interface{}, options *hcsschema.VirtualSmbShareOptions) (err error) {
op := "uvm::AddVSMB"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debugf(op+" - GuestRequest: %+v, Options: %+v - Begin Operation", guestRequest, options)
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "windows" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err == ErrNotAttached {
uvm.vsmbCounter++
shareName := "s" + strconv.FormatUint(uvm.vsmbCounter, 16)
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Add,
Settings: hcsschema.VirtualSmbShare{
Name: shareName,
Options: options,
Path: hostPath,
},
ResourcePath: "VirtualMachine/Devices/VirtualSmb/Shares",
}
if err := uvm.Modify(modification); err != nil {
return err
}
share = &vsmbShare{
name: shareName,
guestRequest: guestRequest,
}
uvm.vsmbShares[hostPath] = share
}
share.refCount++
return nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"AddVSMB",
"(",
"hostPath",
"string",
",",
"guestRequest",
"interface",
"{",
"}",
",",
"options",
"*",
"hcsschema",
".",
"VirtualSmbShareOptions",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debugf",
"(",
"op",
"+",
"\"",
"\"",
",",
"guestRequest",
",",
"options",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"operatingSystem",
"!=",
"\"",
"\"",
"{",
"return",
"errNotSupported",
"\n",
"}",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"share",
",",
"err",
":=",
"uvm",
".",
"findVSMBShare",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"==",
"ErrNotAttached",
"{",
"uvm",
".",
"vsmbCounter",
"++",
"\n",
"shareName",
":=",
"\"",
"\"",
"+",
"strconv",
".",
"FormatUint",
"(",
"uvm",
".",
"vsmbCounter",
",",
"16",
")",
"\n\n",
"modification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Add",
",",
"Settings",
":",
"hcsschema",
".",
"VirtualSmbShare",
"{",
"Name",
":",
"shareName",
",",
"Options",
":",
"options",
",",
"Path",
":",
"hostPath",
",",
"}",
",",
"ResourcePath",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"modification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"share",
"=",
"&",
"vsmbShare",
"{",
"name",
":",
"shareName",
",",
"guestRequest",
":",
"guestRequest",
",",
"}",
"\n",
"uvm",
".",
"vsmbShares",
"[",
"hostPath",
"]",
"=",
"share",
"\n",
"}",
"\n",
"share",
".",
"refCount",
"++",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddVSMB adds a VSMB share to a Windows utility VM. Each VSMB share is ref-counted and
// only added if it isn't already. This is used for read-only layers, mapped directories
// to a container, and for mapped pipes.
|
[
"AddVSMB",
"adds",
"a",
"VSMB",
"share",
"to",
"a",
"Windows",
"utility",
"VM",
".",
"Each",
"VSMB",
"share",
"is",
"ref",
"-",
"counted",
"and",
"only",
"added",
"if",
"it",
"isn",
"t",
"already",
".",
"This",
"is",
"used",
"for",
"read",
"-",
"only",
"layers",
"mapped",
"directories",
"to",
"a",
"container",
"and",
"for",
"mapped",
"pipes",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vsmb.go#L35-L83
|
143,562 |
Microsoft/hcsshim
|
internal/uvm/vsmb.go
|
RemoveVSMB
|
func (uvm *UtilityVM) RemoveVSMB(hostPath string) (err error) {
op := "uvm::RemoveVSMB"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "windows" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err != nil {
return fmt.Errorf("%s is not present as a VSMB share in %s, cannot remove", hostPath, uvm.id)
}
share.refCount--
if share.refCount > 0 {
return nil
}
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
Settings: hcsschema.VirtualSmbShare{Name: share.name},
ResourcePath: "VirtualMachine/Devices/VirtualSmb/Shares",
}
if err := uvm.Modify(modification); err != nil {
return fmt.Errorf("failed to remove vsmb share %s from %s: %+v: %s", hostPath, uvm.id, modification, err)
}
delete(uvm.vsmbShares, hostPath)
return nil
}
|
go
|
func (uvm *UtilityVM) RemoveVSMB(hostPath string) (err error) {
op := "uvm::RemoveVSMB"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "windows" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err != nil {
return fmt.Errorf("%s is not present as a VSMB share in %s, cannot remove", hostPath, uvm.id)
}
share.refCount--
if share.refCount > 0 {
return nil
}
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
Settings: hcsschema.VirtualSmbShare{Name: share.name},
ResourcePath: "VirtualMachine/Devices/VirtualSmb/Shares",
}
if err := uvm.Modify(modification); err != nil {
return fmt.Errorf("failed to remove vsmb share %s from %s: %+v: %s", hostPath, uvm.id, modification, err)
}
delete(uvm.vsmbShares, hostPath)
return nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveVSMB",
"(",
"hostPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"operatingSystem",
"!=",
"\"",
"\"",
"{",
"return",
"errNotSupported",
"\n",
"}",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"share",
",",
"err",
":=",
"uvm",
".",
"findVSMBShare",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
")",
"\n",
"}",
"\n\n",
"share",
".",
"refCount",
"--",
"\n",
"if",
"share",
".",
"refCount",
">",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"modification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"hcsschema",
".",
"VirtualSmbShare",
"{",
"Name",
":",
"share",
".",
"name",
"}",
",",
"ResourcePath",
":",
"\"",
"\"",
",",
"}",
"\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"modification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
",",
"modification",
",",
"err",
")",
"\n",
"}",
"\n\n",
"delete",
"(",
"uvm",
".",
"vsmbShares",
",",
"hostPath",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RemoveVSMB removes a VSMB share from a utility VM. Each VSMB share is ref-counted
// and only actually removed when the ref-count drops to zero.
|
[
"RemoveVSMB",
"removes",
"a",
"VSMB",
"share",
"from",
"a",
"utility",
"VM",
".",
"Each",
"VSMB",
"share",
"is",
"ref",
"-",
"counted",
"and",
"only",
"actually",
"removed",
"when",
"the",
"ref",
"-",
"count",
"drops",
"to",
"zero",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vsmb.go#L87-L130
|
143,563 |
Microsoft/hcsshim
|
internal/uvm/vsmb.go
|
GetVSMBUvmPath
|
func (uvm *UtilityVM) GetVSMBUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetVSMBUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if hostPath == "" {
return "", fmt.Errorf("no hostPath passed to GetVSMBUvmPath")
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err != nil {
return "", err
}
path := share.GuestPath()
return path, nil
}
|
go
|
func (uvm *UtilityVM) GetVSMBUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetVSMBUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if hostPath == "" {
return "", fmt.Errorf("no hostPath passed to GetVSMBUvmPath")
}
uvm.m.Lock()
defer uvm.m.Unlock()
share, err := uvm.findVSMBShare(hostPath)
if err != nil {
return "", err
}
path := share.GuestPath()
return path, nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"GetVSMBUvmPath",
"(",
"hostPath",
"string",
")",
"(",
"_",
"string",
",",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"hostPath",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"share",
",",
"err",
":=",
"uvm",
".",
"findVSMBShare",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"path",
":=",
"share",
".",
"GuestPath",
"(",
")",
"\n",
"return",
"path",
",",
"nil",
"\n",
"}"
] |
// GetVSMBUvmPath returns the guest path of a VSMB mount.
|
[
"GetVSMBUvmPath",
"returns",
"the",
"guest",
"path",
"of",
"a",
"VSMB",
"mount",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vsmb.go#L133-L160
|
143,564 |
Microsoft/hcsshim
|
internal/wclayer/layerexists.go
|
LayerExists
|
func LayerExists(path string) (_ bool, err error) {
title := "hcsshim::LayerExists"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Call the procedure itself.
var exists uint32
err = layerExists(&stdDriverInfo, path, &exists)
if err != nil {
return false, hcserror.New(err, title+" - failed", "")
}
fields["layer-exists"] = exists != 0
return exists != 0, nil
}
|
go
|
func LayerExists(path string) (_ bool, err error) {
title := "hcsshim::LayerExists"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Call the procedure itself.
var exists uint32
err = layerExists(&stdDriverInfo, path, &exists)
if err != nil {
return false, hcserror.New(err, title+" - failed", "")
}
fields["layer-exists"] = exists != 0
return exists != 0, nil
}
|
[
"func",
"LayerExists",
"(",
"path",
"string",
")",
"(",
"_",
"bool",
",",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"path",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// Call the procedure itself.",
"var",
"exists",
"uint32",
"\n",
"err",
"=",
"layerExists",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"&",
"exists",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"exists",
"!=",
"0",
"\n",
"return",
"exists",
"!=",
"0",
",",
"nil",
"\n",
"}"
] |
// LayerExists will return true if a layer with the given id exists and is known
// to the system.
|
[
"LayerExists",
"will",
"return",
"true",
"if",
"a",
"layer",
"with",
"the",
"given",
"id",
"exists",
"and",
"is",
"known",
"to",
"the",
"system",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/layerexists.go#L10-L33
|
143,565 |
Microsoft/hcsshim
|
internal/wclayer/getlayermountpath.go
|
GetLayerMountPath
|
func GetLayerMountPath(path string) (_ string, err error) {
title := "hcsshim::GetLayerMountPath"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
var mountPathLength uintptr
mountPathLength = 0
// Call the procedure itself.
logrus.WithFields(fields).Debug("Calling proc (1)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
if err != nil {
return "", hcserror.New(err, title+" - failed", "(first call)")
}
// Allocate a mount path of the returned length.
if mountPathLength == 0 {
return "", nil
}
mountPathp := make([]uint16, mountPathLength)
mountPathp[0] = 0
// Call the procedure again
logrus.WithFields(fields).Debug("Calling proc (2)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
if err != nil {
return "", hcserror.New(err, title+" - failed", "(second call)")
}
mountPath := syscall.UTF16ToString(mountPathp[0:])
fields["mountPath"] = mountPath
return mountPath, nil
}
|
go
|
func GetLayerMountPath(path string) (_ string, err error) {
title := "hcsshim::GetLayerMountPath"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
var mountPathLength uintptr
mountPathLength = 0
// Call the procedure itself.
logrus.WithFields(fields).Debug("Calling proc (1)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
if err != nil {
return "", hcserror.New(err, title+" - failed", "(first call)")
}
// Allocate a mount path of the returned length.
if mountPathLength == 0 {
return "", nil
}
mountPathp := make([]uint16, mountPathLength)
mountPathp[0] = 0
// Call the procedure again
logrus.WithFields(fields).Debug("Calling proc (2)")
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
if err != nil {
return "", hcserror.New(err, title+" - failed", "(second call)")
}
mountPath := syscall.UTF16ToString(mountPathp[0:])
fields["mountPath"] = mountPath
return mountPath, nil
}
|
[
"func",
"GetLayerMountPath",
"(",
"path",
"string",
")",
"(",
"_",
"string",
",",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"path",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"mountPathLength",
"uintptr",
"\n",
"mountPathLength",
"=",
"0",
"\n\n",
"// Call the procedure itself.",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"getLayerMountPath",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"&",
"mountPathLength",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Allocate a mount path of the returned length.",
"if",
"mountPathLength",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"mountPathp",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"mountPathLength",
")",
"\n",
"mountPathp",
"[",
"0",
"]",
"=",
"0",
"\n\n",
"// Call the procedure again",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"getLayerMountPath",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"&",
"mountPathLength",
",",
"&",
"mountPathp",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"mountPath",
":=",
"syscall",
".",
"UTF16ToString",
"(",
"mountPathp",
"[",
"0",
":",
"]",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"mountPath",
"\n",
"return",
"mountPath",
",",
"nil",
"\n",
"}"
] |
// GetLayerMountPath will look for a mounted layer with the given path and return
// the path at which that layer can be accessed. This path may be a volume path
// if the layer is a mounted read-write layer, otherwise it is expected to be the
// folder path at which the layer is stored.
|
[
"GetLayerMountPath",
"will",
"look",
"for",
"a",
"mounted",
"layer",
"with",
"the",
"given",
"path",
"and",
"return",
"the",
"path",
"at",
"which",
"that",
"layer",
"can",
"be",
"accessed",
".",
"This",
"path",
"may",
"be",
"a",
"volume",
"path",
"if",
"the",
"layer",
"is",
"a",
"mounted",
"read",
"-",
"write",
"layer",
"otherwise",
"it",
"is",
"expected",
"to",
"be",
"the",
"folder",
"path",
"at",
"which",
"the",
"layer",
"is",
"stored",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/getlayermountpath.go#L14-L56
|
143,566 |
Microsoft/hcsshim
|
hnsendpoint.go
|
HotAttachEndpoint
|
func HotAttachEndpoint(containerID string, endpointID string) error {
endpoint, err := GetHNSEndpointByID(endpointID)
isAttached, err := endpoint.IsAttached(containerID)
if isAttached {
return err
}
return modifyNetworkEndpoint(containerID, endpointID, Add)
}
|
go
|
func HotAttachEndpoint(containerID string, endpointID string) error {
endpoint, err := GetHNSEndpointByID(endpointID)
isAttached, err := endpoint.IsAttached(containerID)
if isAttached {
return err
}
return modifyNetworkEndpoint(containerID, endpointID, Add)
}
|
[
"func",
"HotAttachEndpoint",
"(",
"containerID",
"string",
",",
"endpointID",
"string",
")",
"error",
"{",
"endpoint",
",",
"err",
":=",
"GetHNSEndpointByID",
"(",
"endpointID",
")",
"\n",
"isAttached",
",",
"err",
":=",
"endpoint",
".",
"IsAttached",
"(",
"containerID",
")",
"\n",
"if",
"isAttached",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"modifyNetworkEndpoint",
"(",
"containerID",
",",
"endpointID",
",",
"Add",
")",
"\n",
"}"
] |
// HotAttachEndpoint makes a HCS Call to attach the endpoint to the container
|
[
"HotAttachEndpoint",
"makes",
"a",
"HCS",
"Call",
"to",
"attach",
"the",
"endpoint",
"to",
"the",
"container"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hnsendpoint.go#L41-L48
|
143,567 |
Microsoft/hcsshim
|
hnsendpoint.go
|
HotDetachEndpoint
|
func HotDetachEndpoint(containerID string, endpointID string) error {
endpoint, err := GetHNSEndpointByID(endpointID)
isAttached, err := endpoint.IsAttached(containerID)
if !isAttached {
return err
}
return modifyNetworkEndpoint(containerID, endpointID, Remove)
}
|
go
|
func HotDetachEndpoint(containerID string, endpointID string) error {
endpoint, err := GetHNSEndpointByID(endpointID)
isAttached, err := endpoint.IsAttached(containerID)
if !isAttached {
return err
}
return modifyNetworkEndpoint(containerID, endpointID, Remove)
}
|
[
"func",
"HotDetachEndpoint",
"(",
"containerID",
"string",
",",
"endpointID",
"string",
")",
"error",
"{",
"endpoint",
",",
"err",
":=",
"GetHNSEndpointByID",
"(",
"endpointID",
")",
"\n",
"isAttached",
",",
"err",
":=",
"endpoint",
".",
"IsAttached",
"(",
"containerID",
")",
"\n",
"if",
"!",
"isAttached",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"modifyNetworkEndpoint",
"(",
"containerID",
",",
"endpointID",
",",
"Remove",
")",
"\n",
"}"
] |
// HotDetachEndpoint makes a HCS Call to detach the endpoint from the container
|
[
"HotDetachEndpoint",
"makes",
"a",
"HCS",
"Call",
"to",
"detach",
"the",
"endpoint",
"from",
"the",
"container"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hnsendpoint.go#L51-L58
|
143,568 |
Microsoft/hcsshim
|
hnsendpoint.go
|
modifyContainer
|
func modifyContainer(id string, request *ResourceModificationRequestResponse) error {
container, err := OpenContainer(id)
if err != nil {
if IsNotExist(err) {
return ErrComputeSystemDoesNotExist
}
return getInnerError(err)
}
defer container.Close()
err = container.Modify(request)
if err != nil {
if IsNotSupported(err) {
return ErrPlatformNotSupported
}
return getInnerError(err)
}
return nil
}
|
go
|
func modifyContainer(id string, request *ResourceModificationRequestResponse) error {
container, err := OpenContainer(id)
if err != nil {
if IsNotExist(err) {
return ErrComputeSystemDoesNotExist
}
return getInnerError(err)
}
defer container.Close()
err = container.Modify(request)
if err != nil {
if IsNotSupported(err) {
return ErrPlatformNotSupported
}
return getInnerError(err)
}
return nil
}
|
[
"func",
"modifyContainer",
"(",
"id",
"string",
",",
"request",
"*",
"ResourceModificationRequestResponse",
")",
"error",
"{",
"container",
",",
"err",
":=",
"OpenContainer",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"ErrComputeSystemDoesNotExist",
"\n",
"}",
"\n",
"return",
"getInnerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"container",
".",
"Close",
"(",
")",
"\n",
"err",
"=",
"container",
".",
"Modify",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"IsNotSupported",
"(",
"err",
")",
"{",
"return",
"ErrPlatformNotSupported",
"\n",
"}",
"\n",
"return",
"getInnerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// ModifyContainer corresponding to the container id, by sending a request
|
[
"ModifyContainer",
"corresponding",
"to",
"the",
"container",
"id",
"by",
"sending",
"a",
"request"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hnsendpoint.go#L61-L79
|
143,569 |
Microsoft/hcsshim
|
internal/ospath/join.go
|
Join
|
func Join(os string, elem ...string) string {
if os == "windows" {
return filepath.Join(elem...)
}
return path.Join(elem...)
}
|
go
|
func Join(os string, elem ...string) string {
if os == "windows" {
return filepath.Join(elem...)
}
return path.Join(elem...)
}
|
[
"func",
"Join",
"(",
"os",
"string",
",",
"elem",
"...",
"string",
")",
"string",
"{",
"if",
"os",
"==",
"\"",
"\"",
"{",
"return",
"filepath",
".",
"Join",
"(",
"elem",
"...",
")",
"\n",
"}",
"\n",
"return",
"path",
".",
"Join",
"(",
"elem",
"...",
")",
"\n",
"}"
] |
// Join joins paths using the target OS's path separator.
|
[
"Join",
"joins",
"paths",
"using",
"the",
"target",
"OS",
"s",
"path",
"separator",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/ospath/join.go#L9-L14
|
143,570 |
Microsoft/hcsshim
|
internal/hns/hnspolicylist.go
|
HNSListPolicyListRequest
|
func HNSListPolicyListRequest() ([]PolicyList, error) {
var plist []PolicyList
err := hnsCall("GET", "/policylists/", "", &plist)
if err != nil {
return nil, err
}
return plist, nil
}
|
go
|
func HNSListPolicyListRequest() ([]PolicyList, error) {
var plist []PolicyList
err := hnsCall("GET", "/policylists/", "", &plist)
if err != nil {
return nil, err
}
return plist, nil
}
|
[
"func",
"HNSListPolicyListRequest",
"(",
")",
"(",
"[",
"]",
"PolicyList",
",",
"error",
")",
"{",
"var",
"plist",
"[",
"]",
"PolicyList",
"\n",
"err",
":=",
"hnsCall",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"plist",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"plist",
",",
"nil",
"\n",
"}"
] |
// HNSListPolicyListRequest gets all the policy list
|
[
"HNSListPolicyListRequest",
"gets",
"all",
"the",
"policy",
"list"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L53-L61
|
143,571 |
Microsoft/hcsshim
|
internal/hns/hnspolicylist.go
|
Create
|
func (policylist *PolicyList) Create() (*PolicyList, error) {
operation := "Create"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s", policylist.ID)
jsonString, err := json.Marshal(policylist)
if err != nil {
return nil, err
}
return PolicyListRequest("POST", "", string(jsonString))
}
|
go
|
func (policylist *PolicyList) Create() (*PolicyList, error) {
operation := "Create"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s", policylist.ID)
jsonString, err := json.Marshal(policylist)
if err != nil {
return nil, err
}
return PolicyListRequest("POST", "", string(jsonString))
}
|
[
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"Create",
"(",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
")",
"\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"policylist",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"PolicyListRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"string",
"(",
"jsonString",
")",
")",
"\n",
"}"
] |
// Create PolicyList by sending PolicyListRequest to HNS.
|
[
"Create",
"PolicyList",
"by",
"sending",
"PolicyListRequest",
"to",
"HNS",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L80-L89
|
143,572 |
Microsoft/hcsshim
|
internal/hns/hnspolicylist.go
|
Delete
|
func (policylist *PolicyList) Delete() (*PolicyList, error) {
operation := "Delete"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s", policylist.ID)
return PolicyListRequest("DELETE", policylist.ID, "")
}
|
go
|
func (policylist *PolicyList) Delete() (*PolicyList, error) {
operation := "Delete"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s", policylist.ID)
return PolicyListRequest("DELETE", policylist.ID, "")
}
|
[
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"Delete",
"(",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
")",
"\n\n",
"return",
"PolicyListRequest",
"(",
"\"",
"\"",
",",
"policylist",
".",
"ID",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// Delete deletes PolicyList
|
[
"Delete",
"deletes",
"PolicyList"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L92-L98
|
143,573 |
Microsoft/hcsshim
|
internal/hns/hnspolicylist.go
|
AddEndpoint
|
func (policylist *PolicyList) AddEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "AddEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
policylist.EndpointReferences = append(policylist.EndpointReferences, "/endpoints/"+endpoint.Id)
return policylist.Create()
}
|
go
|
func (policylist *PolicyList) AddEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "AddEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
policylist.EndpointReferences = append(policylist.EndpointReferences, "/endpoints/"+endpoint.Id)
return policylist.Create()
}
|
[
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"AddEndpoint",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"_",
",",
"err",
":=",
"policylist",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add Endpoint to the Existing List",
"policylist",
".",
"EndpointReferences",
"=",
"append",
"(",
"policylist",
".",
"EndpointReferences",
",",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
")",
"\n\n",
"return",
"policylist",
".",
"Create",
"(",
")",
"\n",
"}"
] |
// AddEndpoint add an endpoint to a Policy List
|
[
"AddEndpoint",
"add",
"an",
"endpoint",
"to",
"a",
"Policy",
"List"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L101-L115
|
143,574 |
Microsoft/hcsshim
|
internal/hns/hnspolicylist.go
|
RemoveEndpoint
|
func (policylist *PolicyList) RemoveEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "RemoveEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
elementToRemove := "/endpoints/" + endpoint.Id
var references []string
for _, endpointReference := range policylist.EndpointReferences {
if endpointReference == elementToRemove {
continue
}
references = append(references, endpointReference)
}
policylist.EndpointReferences = references
return policylist.Create()
}
|
go
|
func (policylist *PolicyList) RemoveEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "RemoveEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
elementToRemove := "/endpoints/" + endpoint.Id
var references []string
for _, endpointReference := range policylist.EndpointReferences {
if endpointReference == elementToRemove {
continue
}
references = append(references, endpointReference)
}
policylist.EndpointReferences = references
return policylist.Create()
}
|
[
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"RemoveEndpoint",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"_",
",",
"err",
":=",
"policylist",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"elementToRemove",
":=",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
"\n\n",
"var",
"references",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"endpointReference",
":=",
"range",
"policylist",
".",
"EndpointReferences",
"{",
"if",
"endpointReference",
"==",
"elementToRemove",
"{",
"continue",
"\n",
"}",
"\n",
"references",
"=",
"append",
"(",
"references",
",",
"endpointReference",
")",
"\n",
"}",
"\n",
"policylist",
".",
"EndpointReferences",
"=",
"references",
"\n",
"return",
"policylist",
".",
"Create",
"(",
")",
"\n",
"}"
] |
// RemoveEndpoint removes an endpoint from the Policy List
|
[
"RemoveEndpoint",
"removes",
"an",
"endpoint",
"from",
"the",
"Policy",
"List"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L118-L140
|
143,575 |
Microsoft/hcsshim
|
internal/hcs/process.go
|
Signal
|
func (process *Process) Signal(options interface{}) (_ bool, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Signal"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
optionsb, err := json.Marshal(options)
if err != nil {
return false, err
}
optionsStr := string(optionsb)
var resultp *uint16
syscallWatcher(process.logctx, func() {
err = hcsSignalProcess(process.handle, optionsStr, &resultp)
})
events := processHcsResult(resultp)
delivered, err := process.processSignalResult(err)
if err != nil {
err = makeProcessError(process, operation, err, events)
}
return delivered, err
}
|
go
|
func (process *Process) Signal(options interface{}) (_ bool, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Signal"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
optionsb, err := json.Marshal(options)
if err != nil {
return false, err
}
optionsStr := string(optionsb)
var resultp *uint16
syscallWatcher(process.logctx, func() {
err = hcsSignalProcess(process.handle, optionsStr, &resultp)
})
events := processHcsResult(resultp)
delivered, err := process.processSignalResult(err)
if err != nil {
err = makeProcessError(process, operation, err, events)
}
return delivered, err
}
|
[
"func",
"(",
"process",
"*",
"Process",
")",
"Signal",
"(",
"options",
"interface",
"{",
"}",
")",
"(",
"_",
"bool",
",",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"false",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"optionsb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"optionsStr",
":=",
"string",
"(",
"optionsb",
")",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"process",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsSignalProcess",
"(",
"process",
".",
"handle",
",",
"optionsStr",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"delivered",
",",
"err",
":=",
"process",
".",
"processSignalResult",
"(",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n",
"return",
"delivered",
",",
"err",
"\n",
"}"
] |
// Signal signals the process with `options`.
//
// For LCOW `guestrequest.SignalProcessOptionsLCOW`.
//
// For WCOW `guestrequest.SignalProcessOptionsWCOW`.
|
[
"Signal",
"signals",
"the",
"process",
"with",
"options",
".",
"For",
"LCOW",
"guestrequest",
".",
"SignalProcessOptionsLCOW",
".",
"For",
"WCOW",
"guestrequest",
".",
"SignalProcessOptionsWCOW",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L139-L168
|
143,576 |
Microsoft/hcsshim
|
internal/hcs/process.go
|
StdioLegacy
|
func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Stdio"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
var (
processInfo hcsProcessInformation
resultp *uint16
)
err = hcsGetProcessInfo(process.handle, &processInfo, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, events)
}
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, nil)
}
return pipes[0], pipes[1], pipes[2], nil
}
|
go
|
func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Stdio"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
var (
processInfo hcsProcessInformation
resultp *uint16
)
err = hcsGetProcessInfo(process.handle, &processInfo, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, events)
}
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, nil)
}
return pipes[0], pipes[1], pipes[2], nil
}
|
[
"func",
"(",
"process",
"*",
"Process",
")",
"StdioLegacy",
"(",
")",
"(",
"_",
"io",
".",
"WriteCloser",
",",
"_",
"io",
".",
"ReadCloser",
",",
"_",
"io",
".",
"ReadCloser",
",",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"var",
"(",
"processInfo",
"hcsProcessInformation",
"\n",
"resultp",
"*",
"uint16",
"\n",
")",
"\n",
"err",
"=",
"hcsGetProcessInfo",
"(",
"process",
".",
"handle",
",",
"&",
"processInfo",
",",
"&",
"resultp",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"pipes",
",",
"err",
":=",
"makeOpenFiles",
"(",
"[",
"]",
"syscall",
".",
"Handle",
"{",
"processInfo",
".",
"StdInput",
",",
"processInfo",
".",
"StdOutput",
",",
"processInfo",
".",
"StdError",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"return",
"pipes",
"[",
"0",
"]",
",",
"pipes",
"[",
"1",
"]",
",",
"pipes",
"[",
"2",
"]",
",",
"nil",
"\n",
"}"
] |
// StdioLegacy returns the stdin, stdout, and stderr pipes, respectively. Closing
// these pipes does not close the underlying pipes; it should be possible to
// call this multiple times to get multiple interfaces.
|
[
"StdioLegacy",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"Closing",
"these",
"pipes",
"does",
"not",
"close",
"the",
"underlying",
"pipes",
";",
"it",
"should",
"be",
"possible",
"to",
"call",
"this",
"multiple",
"times",
"to",
"get",
"multiple",
"interfaces",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L327-L355
|
143,577 |
Microsoft/hcsshim
|
internal/hcs/process.go
|
Stdio
|
func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
return process.stdin, process.stdout, process.stderr
}
|
go
|
func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
return process.stdin, process.stdout, process.stderr
}
|
[
"func",
"(",
"process",
"*",
"Process",
")",
"Stdio",
"(",
")",
"(",
"stdin",
"io",
".",
"Writer",
",",
"stdout",
",",
"stderr",
"io",
".",
"Reader",
")",
"{",
"return",
"process",
".",
"stdin",
",",
"process",
".",
"stdout",
",",
"process",
".",
"stderr",
"\n",
"}"
] |
// Stdio returns the stdin, stdout, and stderr pipes, respectively.
// To close them, close the process handle.
|
[
"Stdio",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"To",
"close",
"them",
"close",
"the",
"process",
"handle",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L359-L361
|
143,578 |
Microsoft/hcsshim
|
internal/hcs/process.go
|
CloseStdin
|
func (process *Process) CloseStdin() (err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::CloseStdin"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
modifyRequest := processModifyRequest{
Operation: modifyCloseHandle,
CloseHandle: &closeHandle{
Handle: stdIn,
},
}
modifyRequestb, err := json.Marshal(modifyRequest)
if err != nil {
return err
}
modifyRequestStr := string(modifyRequestb)
var resultp *uint16
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
events := processHcsResult(resultp)
if err != nil {
return makeProcessError(process, operation, err, events)
}
if process.stdin != nil {
process.stdin.Close()
}
return nil
}
|
go
|
func (process *Process) CloseStdin() (err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::CloseStdin"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
modifyRequest := processModifyRequest{
Operation: modifyCloseHandle,
CloseHandle: &closeHandle{
Handle: stdIn,
},
}
modifyRequestb, err := json.Marshal(modifyRequest)
if err != nil {
return err
}
modifyRequestStr := string(modifyRequestb)
var resultp *uint16
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
events := processHcsResult(resultp)
if err != nil {
return makeProcessError(process, operation, err, events)
}
if process.stdin != nil {
process.stdin.Close()
}
return nil
}
|
[
"func",
"(",
"process",
"*",
"Process",
")",
"CloseStdin",
"(",
")",
"(",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"modifyRequest",
":=",
"processModifyRequest",
"{",
"Operation",
":",
"modifyCloseHandle",
",",
"CloseHandle",
":",
"&",
"closeHandle",
"{",
"Handle",
":",
"stdIn",
",",
"}",
",",
"}",
"\n\n",
"modifyRequestb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"modifyRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"modifyRequestStr",
":=",
"string",
"(",
"modifyRequestb",
")",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"err",
"=",
"hcsModifyProcess",
"(",
"process",
".",
"handle",
",",
"modifyRequestStr",
",",
"&",
"resultp",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"if",
"process",
".",
"stdin",
"!=",
"nil",
"{",
"process",
".",
"stdin",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CloseStdin closes the write side of the stdin pipe so that the process is
// notified on the read side that there is no more data in stdin.
|
[
"CloseStdin",
"closes",
"the",
"write",
"side",
"of",
"the",
"stdin",
"pipe",
"so",
"that",
"the",
"process",
"is",
"notified",
"on",
"the",
"read",
"side",
"that",
"there",
"is",
"no",
"more",
"data",
"in",
"stdin",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L365-L402
|
143,579 |
Microsoft/hcsshim
|
internal/hcs/process.go
|
Close
|
func (process *Process) Close() (err error) {
process.handleLock.Lock()
defer process.handleLock.Unlock()
operation := "hcsshim::Process::Close"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
// Don't double free this
if process.handle == 0 {
return nil
}
if process.stdin != nil {
process.stdin.Close()
}
if process.stdout != nil {
process.stdout.Close()
}
if process.stderr != nil {
process.stderr.Close()
}
if err = process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, err, nil)
}
if err = hcsCloseProcess(process.handle); err != nil {
return makeProcessError(process, operation, err, nil)
}
process.handle = 0
process.closedWaitOnce.Do(func() {
process.waitError = ErrAlreadyClosed
close(process.waitBlock)
})
return nil
}
|
go
|
func (process *Process) Close() (err error) {
process.handleLock.Lock()
defer process.handleLock.Unlock()
operation := "hcsshim::Process::Close"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
// Don't double free this
if process.handle == 0 {
return nil
}
if process.stdin != nil {
process.stdin.Close()
}
if process.stdout != nil {
process.stdout.Close()
}
if process.stderr != nil {
process.stderr.Close()
}
if err = process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, err, nil)
}
if err = hcsCloseProcess(process.handle); err != nil {
return makeProcessError(process, operation, err, nil)
}
process.handle = 0
process.closedWaitOnce.Do(func() {
process.waitError = ErrAlreadyClosed
close(process.waitBlock)
})
return nil
}
|
[
"func",
"(",
"process",
"*",
"Process",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"Unlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"// Don't double free this",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"process",
".",
"stdin",
"!=",
"nil",
"{",
"process",
".",
"stdin",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"process",
".",
"stdout",
"!=",
"nil",
"{",
"process",
".",
"stdout",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"process",
".",
"stderr",
"!=",
"nil",
"{",
"process",
".",
"stderr",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"process",
".",
"unregisterCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"hcsCloseProcess",
"(",
"process",
".",
"handle",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"process",
".",
"handle",
"=",
"0",
"\n",
"process",
".",
"closedWaitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"process",
".",
"waitError",
"=",
"ErrAlreadyClosed",
"\n",
"close",
"(",
"process",
".",
"waitBlock",
")",
"\n",
"}",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Close cleans up any state associated with the process but does not kill
// or wait on it.
|
[
"Close",
"cleans",
"up",
"any",
"state",
"associated",
"with",
"the",
"process",
"but",
"does",
"not",
"kill",
"or",
"wait",
"on",
"it",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L406-L444
|
143,580 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
ListEndpoints
|
func ListEndpoints() ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
return endpoints, nil
}
|
go
|
func ListEndpoints() ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
return endpoints, nil
}
|
[
"func",
"ListEndpoints",
"(",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"endpoints",
",",
"nil",
"\n",
"}"
] |
// ListEndpoints makes a call to list all available endpoints.
|
[
"ListEndpoints",
"makes",
"a",
"call",
"to",
"list",
"all",
"available",
"endpoints",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L221-L228
|
143,581 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
ListEndpointsQuery
|
func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
endpoints, err := enumerateEndpoints(string(queryJson))
if err != nil {
return nil, err
}
return endpoints, nil
}
|
go
|
func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
endpoints, err := enumerateEndpoints(string(queryJson))
if err != nil {
return nil, err
}
return endpoints, nil
}
|
[
"func",
"ListEndpointsQuery",
"(",
"query",
"HostComputeQuery",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"queryJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"endpoints",
",",
"err",
":=",
"enumerateEndpoints",
"(",
"string",
"(",
"queryJson",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"endpoints",
",",
"nil",
"\n",
"}"
] |
// ListEndpointsQuery makes a call to query the list of available endpoints.
|
[
"ListEndpointsQuery",
"makes",
"a",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"endpoints",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L231-L242
|
143,582 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
ListEndpointsOfNetwork
|
func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
mapA := map[string]string{"VirtualNetwork": networkId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
return ListEndpointsQuery(hcnQuery)
}
|
go
|
func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
mapA := map[string]string{"VirtualNetwork": networkId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
return ListEndpointsQuery(hcnQuery)
}
|
[
"func",
"ListEndpointsOfNetwork",
"(",
"networkId",
"string",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"networkId",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"return",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"}"
] |
// ListEndpointsOfNetwork queries the list of endpoints on a network.
|
[
"ListEndpointsOfNetwork",
"queries",
"the",
"list",
"of",
"endpoints",
"on",
"a",
"network",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L245-L256
|
143,583 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
GetEndpointByID
|
func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": endpointId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointID: endpointId}
}
return &endpoints[0], err
}
|
go
|
func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": endpointId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointID: endpointId}
}
return &endpoints[0], err
}
|
[
"func",
"GetEndpointByID",
"(",
"endpointId",
"string",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"endpointId",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"endpoints",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"EndpointNotFoundError",
"{",
"EndpointID",
":",
"endpointId",
"}",
"\n",
"}",
"\n",
"return",
"&",
"endpoints",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] |
// GetEndpointByID returns an endpoint specified by Id
|
[
"GetEndpointByID",
"returns",
"an",
"endpoint",
"specified",
"by",
"Id"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L259-L276
|
143,584 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
GetEndpointByName
|
func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": endpointName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointName: endpointName}
}
return &endpoints[0], err
}
|
go
|
func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": endpointName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointName: endpointName}
}
return &endpoints[0], err
}
|
[
"func",
"GetEndpointByName",
"(",
"endpointName",
"string",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"endpointName",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"endpoints",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"EndpointNotFoundError",
"{",
"EndpointName",
":",
"endpointName",
"}",
"\n",
"}",
"\n",
"return",
"&",
"endpoints",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] |
// GetEndpointByName returns an endpoint specified by Name
|
[
"GetEndpointByName",
"returns",
"an",
"endpoint",
"specified",
"by",
"Name"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L279-L296
|
143,585 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
Create
|
func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
if endpoint.HostComputeNamespace != "" {
return nil, errors.New("endpoint create error, endpoint json HostComputeNamespace is read only and should not be set")
}
jsonString, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return endpoint, nil
}
|
go
|
func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
if endpoint.HostComputeNamespace != "" {
return nil, errors.New("endpoint create error, endpoint json HostComputeNamespace is read only and should not be set")
}
jsonString, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return endpoint, nil
}
|
[
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"Create",
"(",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"if",
"endpoint",
".",
"HostComputeNamespace",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"jsonString",
")",
"\n",
"endpoint",
",",
"hcnErr",
":=",
"createEndpoint",
"(",
"endpoint",
".",
"HostComputeNetwork",
",",
"string",
"(",
"jsonString",
")",
")",
"\n",
"if",
"hcnErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"hcnErr",
"\n",
"}",
"\n",
"return",
"endpoint",
",",
"nil",
"\n",
"}"
] |
// Create Endpoint.
|
[
"Create",
"Endpoint",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L299-L317
|
143,586 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
Delete
|
func (endpoint *HostComputeEndpoint) Delete() error {
logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
if err := deleteEndpoint(endpoint.Id); err != nil {
return err
}
return nil
}
|
go
|
func (endpoint *HostComputeEndpoint) Delete() error {
logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
if err := deleteEndpoint(endpoint.Id); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"Delete",
"(",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"if",
"err",
":=",
"deleteEndpoint",
"(",
"endpoint",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Delete Endpoint.
|
[
"Delete",
"Endpoint",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L320-L327
|
143,587 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
NamespaceAttach
|
func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
return AddNamespaceEndpoint(namespaceId, endpoint.Id)
}
|
go
|
func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
return AddNamespaceEndpoint(namespaceId, endpoint.Id)
}
|
[
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"NamespaceAttach",
"(",
"namespaceId",
"string",
")",
"error",
"{",
"return",
"AddNamespaceEndpoint",
"(",
"namespaceId",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}"
] |
// NamespaceAttach modifies a Namespace to add an endpoint.
|
[
"NamespaceAttach",
"modifies",
"a",
"Namespace",
"to",
"add",
"an",
"endpoint",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L363-L365
|
143,588 |
Microsoft/hcsshim
|
hcn/hcnendpoint.go
|
NamespaceDetach
|
func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
}
|
go
|
func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
}
|
[
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"NamespaceDetach",
"(",
"namespaceId",
"string",
")",
"error",
"{",
"return",
"RemoveNamespaceEndpoint",
"(",
"namespaceId",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}"
] |
// NamespaceDetach modifies a Namespace to remove an endpoint.
|
[
"NamespaceDetach",
"modifies",
"a",
"Namespace",
"to",
"remove",
"an",
"endpoint",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L368-L370
|
143,589 |
Microsoft/hcsshim
|
internal/wcow/scratch.go
|
CreateUVMScratch
|
func CreateUVMScratch(imagePath, destDirectory, vmID string) error {
sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
logrus.Debugf("uvm::CreateUVMScratch %s from %s", targetScratch, sourceScratch)
if err := copyfile.CopyFile(sourceScratch, targetScratch, true); err != nil {
return err
}
if err := wclayer.GrantVmAccess(vmID, targetScratch); err != nil {
os.Remove(targetScratch)
return err
}
return nil
}
|
go
|
func CreateUVMScratch(imagePath, destDirectory, vmID string) error {
sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
logrus.Debugf("uvm::CreateUVMScratch %s from %s", targetScratch, sourceScratch)
if err := copyfile.CopyFile(sourceScratch, targetScratch, true); err != nil {
return err
}
if err := wclayer.GrantVmAccess(vmID, targetScratch); err != nil {
os.Remove(targetScratch)
return err
}
return nil
}
|
[
"func",
"CreateUVMScratch",
"(",
"imagePath",
",",
"destDirectory",
",",
"vmID",
"string",
")",
"error",
"{",
"sourceScratch",
":=",
"filepath",
".",
"Join",
"(",
"imagePath",
",",
"`UtilityVM\\SystemTemplate.vhdx`",
")",
"\n",
"targetScratch",
":=",
"filepath",
".",
"Join",
"(",
"destDirectory",
",",
"\"",
"\"",
")",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"targetScratch",
",",
"sourceScratch",
")",
"\n",
"if",
"err",
":=",
"copyfile",
".",
"CopyFile",
"(",
"sourceScratch",
",",
"targetScratch",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"wclayer",
".",
"GrantVmAccess",
"(",
"vmID",
",",
"targetScratch",
")",
";",
"err",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"targetScratch",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CreateUVMScratch is a helper to create a scratch for a Windows utility VM
// with permissions to the specified VM ID in a specified directory
|
[
"CreateUVMScratch",
"is",
"a",
"helper",
"to",
"create",
"a",
"scratch",
"for",
"a",
"Windows",
"utility",
"VM",
"with",
"permissions",
"to",
"the",
"specified",
"VM",
"ID",
"in",
"a",
"specified",
"directory"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wcow/scratch.go#L14-L26
|
143,590 |
Microsoft/hcsshim
|
cmd/containerd-shim-runhcs-v1/task_hcs.go
|
newHcsTask
|
func newHcsTask(
ctx context.Context,
events publisher,
parent *uvm.UtilityVM,
ownsParent bool,
req *task.CreateTaskRequest,
s *specs.Spec) (shimTask, error) {
logrus.WithFields(logrus.Fields{
"tid": req.ID,
"ownsParent": ownsParent,
}).Debug("newHcsTask")
owner := filepath.Base(os.Args[0])
io, err := newNpipeIO(ctx, req.ID, req.ID, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
if err != nil {
return nil, err
}
var netNS string
if s.Windows != nil &&
s.Windows.Network != nil {
netNS = s.Windows.Network.NetworkNamespace
}
opts := hcsoci.CreateOptions{
ID: req.ID,
Owner: owner,
Spec: s,
HostingSystem: parent,
NetworkNamespace: netNS,
}
system, resources, err := hcsoci.CreateContainer(&opts)
if err != nil {
return nil, err
}
ht := &hcsTask{
events: events,
id: req.ID,
isWCOW: oci.IsWCOW(s),
c: system,
cr: resources,
ownsHost: ownsParent,
host: parent,
closed: make(chan struct{}),
}
ht.init = newHcsExec(
ctx,
events,
req.ID,
parent,
system,
req.ID,
req.Bundle,
ht.isWCOW,
s.Process,
io)
if parent != nil {
// We have a parent UVM. Listen for its exit and forcibly close this
// task. This is not expected but in the event of a UVM crash we need to
// handle this case.
go ht.waitForHostExit()
}
// In the normal case the `Signal` call from the caller killed this task's
// init process.
go func() {
// Wait for our init process to exit.
ht.init.Wait(context.Background())
// Release all container resources for this task.
ht.close()
}()
// Publish the created event
ht.events(
runtime.TaskCreateEventTopic,
&eventstypes.TaskCreate{
ContainerID: req.ID,
Bundle: req.Bundle,
Rootfs: req.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
Terminal: req.Terminal,
},
Checkpoint: "",
Pid: uint32(ht.init.Pid()),
})
return ht, nil
}
|
go
|
func newHcsTask(
ctx context.Context,
events publisher,
parent *uvm.UtilityVM,
ownsParent bool,
req *task.CreateTaskRequest,
s *specs.Spec) (shimTask, error) {
logrus.WithFields(logrus.Fields{
"tid": req.ID,
"ownsParent": ownsParent,
}).Debug("newHcsTask")
owner := filepath.Base(os.Args[0])
io, err := newNpipeIO(ctx, req.ID, req.ID, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
if err != nil {
return nil, err
}
var netNS string
if s.Windows != nil &&
s.Windows.Network != nil {
netNS = s.Windows.Network.NetworkNamespace
}
opts := hcsoci.CreateOptions{
ID: req.ID,
Owner: owner,
Spec: s,
HostingSystem: parent,
NetworkNamespace: netNS,
}
system, resources, err := hcsoci.CreateContainer(&opts)
if err != nil {
return nil, err
}
ht := &hcsTask{
events: events,
id: req.ID,
isWCOW: oci.IsWCOW(s),
c: system,
cr: resources,
ownsHost: ownsParent,
host: parent,
closed: make(chan struct{}),
}
ht.init = newHcsExec(
ctx,
events,
req.ID,
parent,
system,
req.ID,
req.Bundle,
ht.isWCOW,
s.Process,
io)
if parent != nil {
// We have a parent UVM. Listen for its exit and forcibly close this
// task. This is not expected but in the event of a UVM crash we need to
// handle this case.
go ht.waitForHostExit()
}
// In the normal case the `Signal` call from the caller killed this task's
// init process.
go func() {
// Wait for our init process to exit.
ht.init.Wait(context.Background())
// Release all container resources for this task.
ht.close()
}()
// Publish the created event
ht.events(
runtime.TaskCreateEventTopic,
&eventstypes.TaskCreate{
ContainerID: req.ID,
Bundle: req.Bundle,
Rootfs: req.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
Terminal: req.Terminal,
},
Checkpoint: "",
Pid: uint32(ht.init.Pid()),
})
return ht, nil
}
|
[
"func",
"newHcsTask",
"(",
"ctx",
"context",
".",
"Context",
",",
"events",
"publisher",
",",
"parent",
"*",
"uvm",
".",
"UtilityVM",
",",
"ownsParent",
"bool",
",",
"req",
"*",
"task",
".",
"CreateTaskRequest",
",",
"s",
"*",
"specs",
".",
"Spec",
")",
"(",
"shimTask",
",",
"error",
")",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"req",
".",
"ID",
",",
"\"",
"\"",
":",
"ownsParent",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"owner",
":=",
"filepath",
".",
"Base",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n\n",
"io",
",",
"err",
":=",
"newNpipeIO",
"(",
"ctx",
",",
"req",
".",
"ID",
",",
"req",
".",
"ID",
",",
"req",
".",
"Stdin",
",",
"req",
".",
"Stdout",
",",
"req",
".",
"Stderr",
",",
"req",
".",
"Terminal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"netNS",
"string",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Network",
"!=",
"nil",
"{",
"netNS",
"=",
"s",
".",
"Windows",
".",
"Network",
".",
"NetworkNamespace",
"\n",
"}",
"\n",
"opts",
":=",
"hcsoci",
".",
"CreateOptions",
"{",
"ID",
":",
"req",
".",
"ID",
",",
"Owner",
":",
"owner",
",",
"Spec",
":",
"s",
",",
"HostingSystem",
":",
"parent",
",",
"NetworkNamespace",
":",
"netNS",
",",
"}",
"\n",
"system",
",",
"resources",
",",
"err",
":=",
"hcsoci",
".",
"CreateContainer",
"(",
"&",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ht",
":=",
"&",
"hcsTask",
"{",
"events",
":",
"events",
",",
"id",
":",
"req",
".",
"ID",
",",
"isWCOW",
":",
"oci",
".",
"IsWCOW",
"(",
"s",
")",
",",
"c",
":",
"system",
",",
"cr",
":",
"resources",
",",
"ownsHost",
":",
"ownsParent",
",",
"host",
":",
"parent",
",",
"closed",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"ht",
".",
"init",
"=",
"newHcsExec",
"(",
"ctx",
",",
"events",
",",
"req",
".",
"ID",
",",
"parent",
",",
"system",
",",
"req",
".",
"ID",
",",
"req",
".",
"Bundle",
",",
"ht",
".",
"isWCOW",
",",
"s",
".",
"Process",
",",
"io",
")",
"\n\n",
"if",
"parent",
"!=",
"nil",
"{",
"// We have a parent UVM. Listen for its exit and forcibly close this",
"// task. This is not expected but in the event of a UVM crash we need to",
"// handle this case.",
"go",
"ht",
".",
"waitForHostExit",
"(",
")",
"\n",
"}",
"\n",
"// In the normal case the `Signal` call from the caller killed this task's",
"// init process.",
"go",
"func",
"(",
")",
"{",
"// Wait for our init process to exit.",
"ht",
".",
"init",
".",
"Wait",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"// Release all container resources for this task.",
"ht",
".",
"close",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// Publish the created event",
"ht",
".",
"events",
"(",
"runtime",
".",
"TaskCreateEventTopic",
",",
"&",
"eventstypes",
".",
"TaskCreate",
"{",
"ContainerID",
":",
"req",
".",
"ID",
",",
"Bundle",
":",
"req",
".",
"Bundle",
",",
"Rootfs",
":",
"req",
".",
"Rootfs",
",",
"IO",
":",
"&",
"eventstypes",
".",
"TaskIO",
"{",
"Stdin",
":",
"req",
".",
"Stdin",
",",
"Stdout",
":",
"req",
".",
"Stdout",
",",
"Stderr",
":",
"req",
".",
"Stderr",
",",
"Terminal",
":",
"req",
".",
"Terminal",
",",
"}",
",",
"Checkpoint",
":",
"\"",
"\"",
",",
"Pid",
":",
"uint32",
"(",
"ht",
".",
"init",
".",
"Pid",
"(",
")",
")",
",",
"}",
")",
"\n",
"return",
"ht",
",",
"nil",
"\n",
"}"
] |
// newHcsTask creates a container within `parent` and its init exec process in
// the `shimExecCreated` state and returns the task that tracks its lifetime.
//
// If `parent == nil` the container is created on the host.
|
[
"newHcsTask",
"creates",
"a",
"container",
"within",
"parent",
"and",
"its",
"init",
"exec",
"process",
"in",
"the",
"shimExecCreated",
"state",
"and",
"returns",
"the",
"task",
"that",
"tracks",
"its",
"lifetime",
".",
"If",
"parent",
"==",
"nil",
"the",
"container",
"is",
"created",
"on",
"the",
"host",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/task_hcs.go#L107-L197
|
143,591 |
Microsoft/hcsshim
|
internal/uvm/capabilities.go
|
SignalProcessSupported
|
func (uvm *UtilityVM) SignalProcessSupported() bool {
if props, err := uvm.hcsSystem.Properties(schema1.PropertyTypeGuestConnection); err == nil {
return props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported
}
return false
}
|
go
|
func (uvm *UtilityVM) SignalProcessSupported() bool {
if props, err := uvm.hcsSystem.Properties(schema1.PropertyTypeGuestConnection); err == nil {
return props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported
}
return false
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"SignalProcessSupported",
"(",
")",
"bool",
"{",
"if",
"props",
",",
"err",
":=",
"uvm",
".",
"hcsSystem",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeGuestConnection",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"props",
".",
"GuestConnectionInfo",
".",
"GuestDefinedCapabilities",
".",
"SignalProcessSupported",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// SignalProcessSupported returns `true` if the guest supports the capability to
// signal a process.
//
// This support was added RS5+ guests.
|
[
"SignalProcessSupported",
"returns",
"true",
"if",
"the",
"guest",
"supports",
"the",
"capability",
"to",
"signal",
"a",
"process",
".",
"This",
"support",
"was",
"added",
"RS5",
"+",
"guests",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/capabilities.go#L9-L14
|
143,592 |
Microsoft/hcsshim
|
internal/uvm/scsi.go
|
allocateSCSI
|
func (uvm *UtilityVM) allocateSCSI(hostPath string, uvmPath string, isLayer bool) (int, int32, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == "" {
uvm.scsiLocations[controller][lun].hostPath = hostPath
uvm.scsiLocations[controller][lun].uvmPath = uvmPath
uvm.scsiLocations[controller][lun].isLayer = isLayer
if isLayer {
uvm.scsiLocations[controller][lun].refCount = 1
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"isLayer": isLayer,
"refCount": uvm.scsiLocations[controller][lun].refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::allocateSCSI")
return controller, int32(lun), nil
}
}
}
return -1, -1, ErrNoAvailableLocation
}
|
go
|
func (uvm *UtilityVM) allocateSCSI(hostPath string, uvmPath string, isLayer bool) (int, int32, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == "" {
uvm.scsiLocations[controller][lun].hostPath = hostPath
uvm.scsiLocations[controller][lun].uvmPath = uvmPath
uvm.scsiLocations[controller][lun].isLayer = isLayer
if isLayer {
uvm.scsiLocations[controller][lun].refCount = 1
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"isLayer": isLayer,
"refCount": uvm.scsiLocations[controller][lun].refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::allocateSCSI")
return controller, int32(lun), nil
}
}
}
return -1, -1, ErrNoAvailableLocation
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"allocateSCSI",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"isLayer",
"bool",
")",
"(",
"int",
",",
"int32",
",",
"error",
")",
"{",
"for",
"controller",
",",
"luns",
":=",
"range",
"uvm",
".",
"scsiLocations",
"{",
"for",
"lun",
",",
"si",
":=",
"range",
"luns",
"{",
"if",
"si",
".",
"hostPath",
"==",
"\"",
"\"",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"hostPath",
"=",
"hostPath",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"uvmPath",
"=",
"uvmPath",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"isLayer",
"=",
"isLayer",
"\n",
"if",
"isLayer",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
"=",
"1",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"\"",
"\"",
":",
"uvmPath",
",",
"\"",
"\"",
":",
"isLayer",
",",
"\"",
"\"",
":",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
",",
"\"",
"\"",
":",
"controller",
",",
"\"",
"\"",
":",
"int32",
"(",
"lun",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"controller",
",",
"int32",
"(",
"lun",
")",
",",
"nil",
"\n\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"-",
"1",
",",
"ErrNoAvailableLocation",
"\n",
"}"
] |
// allocateSCSI finds the next available slot on the
// SCSI controllers associated with a utility VM to use.
// Lock must be held when calling this function
|
[
"allocateSCSI",
"finds",
"the",
"next",
"available",
"slot",
"on",
"the",
"SCSI",
"controllers",
"associated",
"with",
"a",
"utility",
"VM",
"to",
"use",
".",
"Lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function"
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L26-L51
|
143,593 |
Microsoft/hcsshim
|
internal/uvm/scsi.go
|
findSCSIAttachment
|
func (uvm *UtilityVM) findSCSIAttachment(findThisHostPath string) (int, int32, string, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": si.uvmPath,
"isLayer": si.isLayer,
"refCount": si.refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::findSCSIAttachment")
return controller, int32(lun), si.uvmPath, nil
}
}
}
return -1, -1, "", ErrNotAttached
}
|
go
|
func (uvm *UtilityVM) findSCSIAttachment(findThisHostPath string) (int, int32, string, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": si.uvmPath,
"isLayer": si.isLayer,
"refCount": si.refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::findSCSIAttachment")
return controller, int32(lun), si.uvmPath, nil
}
}
}
return -1, -1, "", ErrNotAttached
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"findSCSIAttachment",
"(",
"findThisHostPath",
"string",
")",
"(",
"int",
",",
"int32",
",",
"string",
",",
"error",
")",
"{",
"for",
"controller",
",",
"luns",
":=",
"range",
"uvm",
".",
"scsiLocations",
"{",
"for",
"lun",
",",
"si",
":=",
"range",
"luns",
"{",
"if",
"si",
".",
"hostPath",
"==",
"findThisHostPath",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"findThisHostPath",
",",
"\"",
"\"",
":",
"si",
".",
"uvmPath",
",",
"\"",
"\"",
":",
"si",
".",
"isLayer",
",",
"\"",
"\"",
":",
"si",
".",
"refCount",
",",
"\"",
"\"",
":",
"controller",
",",
"\"",
"\"",
":",
"int32",
"(",
"lun",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"controller",
",",
"int32",
"(",
"lun",
")",
",",
"si",
".",
"uvmPath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"-",
"1",
",",
"\"",
"\"",
",",
"ErrNotAttached",
"\n",
"}"
] |
// Lock must be held when calling this function.
|
[
"Lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L72-L90
|
143,594 |
Microsoft/hcsshim
|
internal/uvm/scsi.go
|
RemoveSCSI
|
func (uvm *UtilityVM) RemoveSCSI(hostPath string) (err error) {
op := "uvm::RemoveSCSI"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if uvm.scsiControllerCount == 0 {
return ErrNoSCSIControllers
}
// Make sure is actually attached
controller, lun, uvmPath, err := uvm.findSCSIAttachment(hostPath)
if err != nil {
return err
}
if uvm.scsiLocations[controller][lun].isLayer {
uvm.scsiLocations[controller][lun].refCount--
if uvm.scsiLocations[controller][lun].refCount > 0 {
return nil
}
}
if err := uvm.removeSCSI(hostPath, uvmPath, controller, lun); err != nil {
return fmt.Errorf("failed to remove SCSI disk %s from container %s: %s", hostPath, uvm.id, err)
}
return nil
}
|
go
|
func (uvm *UtilityVM) RemoveSCSI(hostPath string) (err error) {
op := "uvm::RemoveSCSI"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if uvm.scsiControllerCount == 0 {
return ErrNoSCSIControllers
}
// Make sure is actually attached
controller, lun, uvmPath, err := uvm.findSCSIAttachment(hostPath)
if err != nil {
return err
}
if uvm.scsiLocations[controller][lun].isLayer {
uvm.scsiLocations[controller][lun].refCount--
if uvm.scsiLocations[controller][lun].refCount > 0 {
return nil
}
}
if err := uvm.removeSCSI(hostPath, uvmPath, controller, lun); err != nil {
return fmt.Errorf("failed to remove SCSI disk %s from container %s: %s", hostPath, uvm.id, err)
}
return nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveSCSI",
"(",
"hostPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"scsiControllerCount",
"==",
"0",
"{",
"return",
"ErrNoSCSIControllers",
"\n",
"}",
"\n\n",
"// Make sure is actually attached",
"controller",
",",
"lun",
",",
"uvmPath",
",",
"err",
":=",
"uvm",
".",
"findSCSIAttachment",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"isLayer",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
"--",
"\n",
"if",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
">",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"removeSCSI",
"(",
"hostPath",
",",
"uvmPath",
",",
"controller",
",",
"lun",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
",",
"err",
")",
"\n\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RemoveSCSI removes a SCSI disk from a utility VM. As an external API, it
// is "safe". Internal use can call removeSCSI.
|
[
"RemoveSCSI",
"removes",
"a",
"SCSI",
"disk",
"from",
"a",
"utility",
"VM",
".",
"As",
"an",
"external",
"API",
"it",
"is",
"safe",
".",
"Internal",
"use",
"can",
"call",
"removeSCSI",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L295-L336
|
143,595 |
Microsoft/hcsshim
|
internal/uvm/scsi.go
|
removeSCSI
|
func (uvm *UtilityVM) removeSCSI(hostPath string, uvmPath string, controller int, lun int32) error {
scsiModification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Scsi/%d/Attachments/%d", controller, lun),
}
// Include the GuestRequest so that the GCS ejects the disk cleanly if the
// disk was attached/mounted
//
// Note: We always send a guest eject even if there is no UVM path in lcow
// so that we synchronize the guest state. This seems to always avoid SCSI
// related errors if this index quickly reused by another container.
if uvm.operatingSystem == "windows" && uvmPath != "" {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.WCOWMappedVirtualDisk{
ContainerPath: uvmPath,
Lun: lun,
},
}
} else {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVirtualDisk{
MountPath: uvmPath, // May be blank in attach-only
Lun: uint8(lun),
Controller: uint8(controller),
},
}
}
if err := uvm.Modify(scsiModification); err != nil {
return err
}
uvm.scsiLocations[controller][lun] = scsiInfo{}
return nil
}
|
go
|
func (uvm *UtilityVM) removeSCSI(hostPath string, uvmPath string, controller int, lun int32) error {
scsiModification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Scsi/%d/Attachments/%d", controller, lun),
}
// Include the GuestRequest so that the GCS ejects the disk cleanly if the
// disk was attached/mounted
//
// Note: We always send a guest eject even if there is no UVM path in lcow
// so that we synchronize the guest state. This seems to always avoid SCSI
// related errors if this index quickly reused by another container.
if uvm.operatingSystem == "windows" && uvmPath != "" {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.WCOWMappedVirtualDisk{
ContainerPath: uvmPath,
Lun: lun,
},
}
} else {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVirtualDisk{
MountPath: uvmPath, // May be blank in attach-only
Lun: uint8(lun),
Controller: uint8(controller),
},
}
}
if err := uvm.Modify(scsiModification); err != nil {
return err
}
uvm.scsiLocations[controller][lun] = scsiInfo{}
return nil
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"removeSCSI",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"controller",
"int",
",",
"lun",
"int32",
")",
"error",
"{",
"scsiModification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"ResourcePath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"controller",
",",
"lun",
")",
",",
"}",
"\n\n",
"// Include the GuestRequest so that the GCS ejects the disk cleanly if the",
"// disk was attached/mounted",
"//",
"// Note: We always send a guest eject even if there is no UVM path in lcow",
"// so that we synchronize the guest state. This seems to always avoid SCSI",
"// related errors if this index quickly reused by another container.",
"if",
"uvm",
".",
"operatingSystem",
"==",
"\"",
"\"",
"&&",
"uvmPath",
"!=",
"\"",
"\"",
"{",
"scsiModification",
".",
"GuestRequest",
"=",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedVirtualDisk",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"WCOWMappedVirtualDisk",
"{",
"ContainerPath",
":",
"uvmPath",
",",
"Lun",
":",
"lun",
",",
"}",
",",
"}",
"\n",
"}",
"else",
"{",
"scsiModification",
".",
"GuestRequest",
"=",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedVirtualDisk",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"LCOWMappedVirtualDisk",
"{",
"MountPath",
":",
"uvmPath",
",",
"// May be blank in attach-only",
"Lun",
":",
"uint8",
"(",
"lun",
")",
",",
"Controller",
":",
"uint8",
"(",
"controller",
")",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"scsiModification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
"=",
"scsiInfo",
"{",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// removeSCSI is the internally callable "unsafe" version of RemoveSCSI. The mutex
// MUST be held when calling this function.
|
[
"removeSCSI",
"is",
"the",
"internally",
"callable",
"unsafe",
"version",
"of",
"RemoveSCSI",
".",
"The",
"mutex",
"MUST",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L340-L378
|
143,596 |
Microsoft/hcsshim
|
internal/uvm/scsi.go
|
GetScsiUvmPath
|
func (uvm *UtilityVM) GetScsiUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetScsiUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
_, _, uvmPath, err := uvm.findSCSIAttachment(hostPath)
return uvmPath, err
}
|
go
|
func (uvm *UtilityVM) GetScsiUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetScsiUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
_, _, uvmPath, err := uvm.findSCSIAttachment(hostPath)
return uvmPath, err
}
|
[
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"GetScsiUvmPath",
"(",
"hostPath",
"string",
")",
"(",
"_",
"string",
",",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"_",
",",
"uvmPath",
",",
"err",
":=",
"uvm",
".",
"findSCSIAttachment",
"(",
"hostPath",
")",
"\n",
"return",
"uvmPath",
",",
"err",
"\n",
"}"
] |
// GetScsiUvmPath returns the guest mounted path of a SCSI drive.
//
// If `hostPath` is not mounted returns `ErrNotAttached`.
|
[
"GetScsiUvmPath",
"returns",
"the",
"guest",
"mounted",
"path",
"of",
"a",
"SCSI",
"drive",
".",
"If",
"hostPath",
"is",
"not",
"mounted",
"returns",
"ErrNotAttached",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L383-L404
|
143,597 |
Microsoft/hcsshim
|
process.go
|
WaitTimeout
|
func (process *process) WaitTimeout(timeout time.Duration) error {
process.waitOnce.Do(func() {
process.waitCh = make(chan struct{})
go func() {
process.waitErr = process.Wait()
close(process.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ProcessError{Process: process, Err: ErrTimeout, Operation: "hcsshim::Process::Wait"}
case <-process.waitCh:
return process.waitErr
}
}
|
go
|
func (process *process) WaitTimeout(timeout time.Duration) error {
process.waitOnce.Do(func() {
process.waitCh = make(chan struct{})
go func() {
process.waitErr = process.Wait()
close(process.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ProcessError{Process: process, Err: ErrTimeout, Operation: "hcsshim::Process::Wait"}
case <-process.waitCh:
return process.waitErr
}
}
|
[
"func",
"(",
"process",
"*",
"process",
")",
"WaitTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"process",
".",
"waitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"process",
".",
"waitCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"process",
".",
"waitErr",
"=",
"process",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"process",
".",
"waitCh",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
")",
"\n",
"t",
":=",
"time",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"defer",
"t",
".",
"Stop",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"t",
".",
"C",
":",
"return",
"&",
"ProcessError",
"{",
"Process",
":",
"process",
",",
"Err",
":",
"ErrTimeout",
",",
"Operation",
":",
"\"",
"\"",
"}",
"\n",
"case",
"<-",
"process",
".",
"waitCh",
":",
"return",
"process",
".",
"waitErr",
"\n",
"}",
"\n",
"}"
] |
// WaitTimeout waits for the process to exit or the duration to elapse. It returns
// false if timeout occurs.
|
[
"WaitTimeout",
"waits",
"for",
"the",
"process",
"to",
"exit",
"or",
"the",
"duration",
"to",
"elapse",
".",
"It",
"returns",
"false",
"if",
"timeout",
"occurs",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/process.go#L43-L59
|
143,598 |
Microsoft/hcsshim
|
process.go
|
Stdio
|
func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
stdin, stdout, stderr, err := process.p.StdioLegacy()
if err != nil {
err = convertProcessError(err, process)
}
return stdin, stdout, stderr, err
}
|
go
|
func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
stdin, stdout, stderr, err := process.p.StdioLegacy()
if err != nil {
err = convertProcessError(err, process)
}
return stdin, stdout, stderr, err
}
|
[
"func",
"(",
"process",
"*",
"process",
")",
"Stdio",
"(",
")",
"(",
"io",
".",
"WriteCloser",
",",
"io",
".",
"ReadCloser",
",",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"stdin",
",",
"stdout",
",",
"stderr",
",",
"err",
":=",
"process",
".",
"p",
".",
"StdioLegacy",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"convertProcessError",
"(",
"err",
",",
"process",
")",
"\n",
"}",
"\n",
"return",
"stdin",
",",
"stdout",
",",
"stderr",
",",
"err",
"\n",
"}"
] |
// Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
// these pipes does not close the underlying pipes; it should be possible to
// call this multiple times to get multiple interfaces.
|
[
"Stdio",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"Closing",
"these",
"pipes",
"does",
"not",
"close",
"the",
"underlying",
"pipes",
";",
"it",
"should",
"be",
"possible",
"to",
"call",
"this",
"multiple",
"times",
"to",
"get",
"multiple",
"interfaces",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/process.go#L79-L85
|
143,599 |
Microsoft/hcsshim
|
ext4/tar2ext4/tar2ext4.go
|
InlineData
|
func InlineData(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.InlineData)
}
|
go
|
func InlineData(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.InlineData)
}
|
[
"func",
"InlineData",
"(",
"p",
"*",
"params",
")",
"{",
"p",
".",
"ext4opts",
"=",
"append",
"(",
"p",
".",
"ext4opts",
",",
"compactext4",
".",
"InlineData",
")",
"\n",
"}"
] |
// InlineData instructs the converter to write small files into the inode
// structures directly. This creates smaller images but currently is not
// compatible with DAX.
|
[
"InlineData",
"instructs",
"the",
"converter",
"to",
"write",
"small",
"files",
"into",
"the",
"inode",
"structures",
"directly",
".",
"This",
"creates",
"smaller",
"images",
"but",
"currently",
"is",
"not",
"compatible",
"with",
"DAX",
"."
] |
5a7443890943600c562e1f2390ab3fef8c56a45f
|
https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/tar2ext4/tar2ext4.go#L38-L40
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.