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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
containers/storage | drivers/driver.go | isDriverNotSupported | func isDriverNotSupported(err error) bool {
cause := errors.Cause(err)
return cause == ErrNotSupported || cause == ErrPrerequisites || cause == ErrIncompatibleFS
} | go | func isDriverNotSupported(err error) bool {
cause := errors.Cause(err)
return cause == ErrNotSupported || cause == ErrPrerequisites || cause == ErrIncompatibleFS
} | [
"func",
"isDriverNotSupported",
"(",
"err",
"error",
")",
"bool",
"{",
"cause",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"return",
"cause",
"==",
"ErrNotSupported",
"||",
"cause",
"==",
"ErrPrerequisites",
"||",
"cause",
"==",
"ErrIncompatibleFS",
... | // isDriverNotSupported returns true if the error initializing
// the graph driver is a non-supported error. | [
"isDriverNotSupported",
"returns",
"true",
"if",
"the",
"error",
"initializing",
"the",
"graph",
"driver",
"is",
"a",
"non",
"-",
"supported",
"error",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/driver.go#L302-L305 | train |
containers/storage | drivers/driver.go | scanPriorDrivers | func scanPriorDrivers(root string) map[string]bool {
driversMap := make(map[string]bool)
for driver := range drivers {
p := filepath.Join(root, driver)
if _, err := os.Stat(p); err == nil && driver != "vfs" {
driversMap[driver] = true
}
}
return driversMap
} | go | func scanPriorDrivers(root string) map[string]bool {
driversMap := make(map[string]bool)
for driver := range drivers {
p := filepath.Join(root, driver)
if _, err := os.Stat(p); err == nil && driver != "vfs" {
driversMap[driver] = true
}
}
return driversMap
} | [
"func",
"scanPriorDrivers",
"(",
"root",
"string",
")",
"map",
"[",
"string",
"]",
"bool",
"{",
"driversMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\n",
"for",
"driver",
":=",
"range",
"drivers",
"{",
"p",
":=",
"filepath",
".",... | // scanPriorDrivers returns an un-ordered scan of directories of prior storage drivers | [
"scanPriorDrivers",
"returns",
"an",
"un",
"-",
"ordered",
"scan",
"of",
"directories",
"of",
"prior",
"storage",
"drivers"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/driver.go#L308-L318 | train |
containers/storage | lockfile_unix.go | openLock | func openLock(path string, ro bool) (int, error) {
if ro {
return unix.Open(path, os.O_RDONLY, 0)
}
return unix.Open(path, os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
} | go | func openLock(path string, ro bool) (int, error) {
if ro {
return unix.Open(path, os.O_RDONLY, 0)
}
return unix.Open(path, os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
} | [
"func",
"openLock",
"(",
"path",
"string",
",",
"ro",
"bool",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"ro",
"{",
"return",
"unix",
".",
"Open",
"(",
"path",
",",
"os",
".",
"O_RDONLY",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"unix",
".... | // openLock opens the file at path and returns the corresponding file
// descriptor. Note that the path is opened read-only when ro is set. If ro
// is unset, openLock will open the path read-write and create the file if
// necessary. | [
"openLock",
"opens",
"the",
"file",
"at",
"path",
"and",
"returns",
"the",
"corresponding",
"file",
"descriptor",
".",
"Note",
"that",
"the",
"path",
"is",
"opened",
"read",
"-",
"only",
"when",
"ro",
"is",
"set",
".",
"If",
"ro",
"is",
"unset",
"openLoc... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_unix.go#L34-L39 | train |
containers/storage | lockfile_unix.go | Unlock | func (l *lockfile) Unlock() {
lk := unix.Flock_t{
Type: unix.F_UNLCK,
Whence: int16(os.SEEK_SET),
Start: 0,
Len: 0,
Pid: int32(os.Getpid()),
}
l.stateMutex.Lock()
if l.locked == false {
// Panic when unlocking an unlocked lock. That's a violation
// of the lock semantics and will reveal such... | go | func (l *lockfile) Unlock() {
lk := unix.Flock_t{
Type: unix.F_UNLCK,
Whence: int16(os.SEEK_SET),
Start: 0,
Len: 0,
Pid: int32(os.Getpid()),
}
l.stateMutex.Lock()
if l.locked == false {
// Panic when unlocking an unlocked lock. That's a violation
// of the lock semantics and will reveal such... | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"Unlock",
"(",
")",
"{",
"lk",
":=",
"unix",
".",
"Flock_t",
"{",
"Type",
":",
"unix",
".",
"F_UNLCK",
",",
"Whence",
":",
"int16",
"(",
"os",
".",
"SEEK_SET",
")",
",",
"Start",
":",
"0",
",",
"Len",
":"... | // Unlock unlocks the lockfile. | [
"Unlock",
"unlocks",
"the",
"lockfile",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_unix.go#L132-L170 | train |
containers/storage | lockfile_unix.go | Locked | func (l *lockfile) Locked() bool {
l.stateMutex.Lock()
defer l.stateMutex.Unlock()
return l.locked && (l.locktype == unix.F_WRLCK)
} | go | func (l *lockfile) Locked() bool {
l.stateMutex.Lock()
defer l.stateMutex.Unlock()
return l.locked && (l.locktype == unix.F_WRLCK)
} | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"Locked",
"(",
")",
"bool",
"{",
"l",
".",
"stateMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"stateMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"l",
".",
"locked",
"&&",
"(",
"l",
".",
"lo... | // Locked checks if lockfile is locked for writing by a thread in this process. | [
"Locked",
"checks",
"if",
"lockfile",
"is",
"locked",
"for",
"writing",
"by",
"a",
"thread",
"in",
"this",
"process",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_unix.go#L173-L177 | train |
containers/storage | lockfile_unix.go | Touch | func (l *lockfile) Touch() error {
l.stateMutex.Lock()
if !l.locked || (l.locktype != unix.F_WRLCK) {
panic("attempted to update last-writer in lockfile without the write lock")
}
l.stateMutex.Unlock()
l.lw = stringid.GenerateRandomID()
id := []byte(l.lw)
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err ... | go | func (l *lockfile) Touch() error {
l.stateMutex.Lock()
if !l.locked || (l.locktype != unix.F_WRLCK) {
panic("attempted to update last-writer in lockfile without the write lock")
}
l.stateMutex.Unlock()
l.lw = stringid.GenerateRandomID()
id := []byte(l.lw)
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err ... | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"Touch",
"(",
")",
"error",
"{",
"l",
".",
"stateMutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"!",
"l",
".",
"locked",
"||",
"(",
"l",
".",
"locktype",
"!=",
"unix",
".",
"F_WRLCK",
")",
"{",
"panic",
"(",
... | // Touch updates the lock file with the UID of the user. | [
"Touch",
"updates",
"the",
"lock",
"file",
"with",
"the",
"UID",
"of",
"the",
"user",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_unix.go#L180-L204 | train |
containers/storage | lockfile_unix.go | Modified | func (l *lockfile) Modified() (bool, error) {
id := []byte(l.lw)
l.stateMutex.Lock()
if !l.locked {
panic("attempted to check last-writer in lockfile without locking it first")
}
l.stateMutex.Unlock()
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return true, err
}
n, err := unix.Read(int(... | go | func (l *lockfile) Modified() (bool, error) {
id := []byte(l.lw)
l.stateMutex.Lock()
if !l.locked {
panic("attempted to check last-writer in lockfile without locking it first")
}
l.stateMutex.Unlock()
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return true, err
}
n, err := unix.Read(int(... | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"Modified",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"id",
":=",
"[",
"]",
"byte",
"(",
"l",
".",
"lw",
")",
"\n",
"l",
".",
"stateMutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"!",
"l",
".",
"lock... | // Modified indicates if the lockfile has been updated since the last time it
// was loaded. | [
"Modified",
"indicates",
"if",
"the",
"lockfile",
"has",
"been",
"updated",
"since",
"the",
"last",
"time",
"it",
"was",
"loaded",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_unix.go#L208-L229 | train |
containers/storage | pkg/idtools/parser.go | ParseIDMap | func ParseIDMap(mapSpec []string, mapSetting string) (idmap []IDMap, err error) {
stdErr := fmt.Errorf("error initializing ID mappings: %s setting is malformed", mapSetting)
for _, idMapSpec := range mapSpec {
idSpec := strings.Fields(strings.Map(nonDigitsToWhitespace, idMapSpec))
if len(idSpec)%3 != 0 {
retur... | go | func ParseIDMap(mapSpec []string, mapSetting string) (idmap []IDMap, err error) {
stdErr := fmt.Errorf("error initializing ID mappings: %s setting is malformed", mapSetting)
for _, idMapSpec := range mapSpec {
idSpec := strings.Fields(strings.Map(nonDigitsToWhitespace, idMapSpec))
if len(idSpec)%3 != 0 {
retur... | [
"func",
"ParseIDMap",
"(",
"mapSpec",
"[",
"]",
"string",
",",
"mapSetting",
"string",
")",
"(",
"idmap",
"[",
"]",
"IDMap",
",",
"err",
"error",
")",
"{",
"stdErr",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"mapSetting",
")",
"\n",
"for",
... | // ParseIDMap parses idmap triples from string. | [
"ParseIDMap",
"parses",
"idmap",
"triples",
"from",
"string",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/idtools/parser.go#L35-L63 | train |
containers/storage | pkg/system/meminfo_solaris.go | getTotalMem | func getTotalMem() int64 {
pagesize := C.sysconf(C._SC_PAGESIZE)
npages := C.sysconf(C._SC_PHYS_PAGES)
return int64(pagesize * npages)
} | go | func getTotalMem() int64 {
pagesize := C.sysconf(C._SC_PAGESIZE)
npages := C.sysconf(C._SC_PHYS_PAGES)
return int64(pagesize * npages)
} | [
"func",
"getTotalMem",
"(",
")",
"int64",
"{",
"pagesize",
":=",
"C",
".",
"sysconf",
"(",
"C",
".",
"_SC_PAGESIZE",
")",
"\n",
"npages",
":=",
"C",
".",
"sysconf",
"(",
"C",
".",
"_SC_PHYS_PAGES",
")",
"\n",
"return",
"int64",
"(",
"pagesize",
"*",
... | // Get the system memory info using sysconf same as prtconf | [
"Get",
"the",
"system",
"memory",
"info",
"using",
"sysconf",
"same",
"as",
"prtconf"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/system/meminfo_solaris.go#L70-L74 | train |
containers/storage | pkg/pools/pools.go | newBufioReaderPoolWithSize | func newBufioReaderPoolWithSize(size int) *BufioReaderPool {
pool := &sync.Pool{
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
}
return &BufioReaderPool{pool: pool}
} | go | func newBufioReaderPoolWithSize(size int) *BufioReaderPool {
pool := &sync.Pool{
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
}
return &BufioReaderPool{pool: pool}
} | [
"func",
"newBufioReaderPoolWithSize",
"(",
"size",
"int",
")",
"*",
"BufioReaderPool",
"{",
"pool",
":=",
"&",
"sync",
".",
"Pool",
"{",
"New",
":",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"bufio",
".",
"NewReaderSize",
"(",
"nil",
",",
... | // newBufioReaderPoolWithSize is unexported because new pools should be
// added here to be shared where required. | [
"newBufioReaderPoolWithSize",
"is",
"unexported",
"because",
"new",
"pools",
"should",
"be",
"added",
"here",
"to",
"be",
"shared",
"where",
"required",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/pools/pools.go#L41-L46 | train |
containers/storage | pkg/pools/pools.go | Copy | func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
buf := BufioReader32KPool.Get(src)
written, err = io.Copy(dst, buf)
BufioReader32KPool.Put(buf)
return
} | go | func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
buf := BufioReader32KPool.Get(src)
written, err = io.Copy(dst, buf)
BufioReader32KPool.Put(buf)
return
} | [
"func",
"Copy",
"(",
"dst",
"io",
".",
"Writer",
",",
"src",
"io",
".",
"Reader",
")",
"(",
"written",
"int64",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"BufioReader32KPool",
".",
"Get",
"(",
"src",
")",
"\n",
"written",
",",
"err",
"=",
"io",
... | // Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy. | [
"Copy",
"is",
"a",
"convenience",
"wrapper",
"which",
"uses",
"a",
"buffer",
"to",
"avoid",
"allocation",
"in",
"io",
".",
"Copy",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/pools/pools.go#L62-L67 | train |
containers/storage | drivers/quota/projectquota.go | setProjectID | func setProjectID(targetPath string, projectID uint32) error {
dir, err := openDir(targetPath)
if err != nil {
return err
}
defer closeDir(dir)
var fsx C.struct_fsxattr
_, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSGETXATTR,
uintptr(unsafe.Pointer(&fsx)))
if errno != 0 {
return fmt... | go | func setProjectID(targetPath string, projectID uint32) error {
dir, err := openDir(targetPath)
if err != nil {
return err
}
defer closeDir(dir)
var fsx C.struct_fsxattr
_, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSGETXATTR,
uintptr(unsafe.Pointer(&fsx)))
if errno != 0 {
return fmt... | [
"func",
"setProjectID",
"(",
"targetPath",
"string",
",",
"projectID",
"uint32",
")",
"error",
"{",
"dir",
",",
"err",
":=",
"openDir",
"(",
"targetPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"closeDir",
... | // setProjectID - set the project id of path on xfs | [
"setProjectID",
"-",
"set",
"the",
"project",
"id",
"of",
"path",
"on",
"xfs"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/quota/projectquota.go#L244-L266 | train |
containers/storage | drivers/quota/projectquota.go | findNextProjectID | func (q *Control) findNextProjectID(home string) error {
files, err := ioutil.ReadDir(home)
if err != nil {
return fmt.Errorf("read directory failed : %s", home)
}
for _, file := range files {
if !file.IsDir() {
continue
}
path := filepath.Join(home, file.Name())
projid, err := getProjectID(path)
if ... | go | func (q *Control) findNextProjectID(home string) error {
files, err := ioutil.ReadDir(home)
if err != nil {
return fmt.Errorf("read directory failed : %s", home)
}
for _, file := range files {
if !file.IsDir() {
continue
}
path := filepath.Join(home, file.Name())
projid, err := getProjectID(path)
if ... | [
"func",
"(",
"q",
"*",
"Control",
")",
"findNextProjectID",
"(",
"home",
"string",
")",
"error",
"{",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"home",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"... | // findNextProjectID - find the next project id to be used for containers
// by scanning driver home directory to find used project ids | [
"findNextProjectID",
"-",
"find",
"the",
"next",
"project",
"id",
"to",
"be",
"used",
"for",
"containers",
"by",
"scanning",
"driver",
"home",
"directory",
"to",
"find",
"used",
"project",
"ids"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/quota/projectquota.go#L270-L293 | train |
containers/storage | drivers/template.go | NaiveCreateFromTemplate | func NaiveCreateFromTemplate(d TemplateDriver, id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *CreateOpts, readWrite bool) error {
var err error
if readWrite {
err = d.CreateReadWrite(id, parent, opts)
} else {
err = d.Create(id, parent, opt... | go | func NaiveCreateFromTemplate(d TemplateDriver, id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *CreateOpts, readWrite bool) error {
var err error
if readWrite {
err = d.CreateReadWrite(id, parent, opts)
} else {
err = d.Create(id, parent, opt... | [
"func",
"NaiveCreateFromTemplate",
"(",
"d",
"TemplateDriver",
",",
"id",
",",
"template",
"string",
",",
"templateIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"parent",
"string",
",",
"parentIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"opts",
"... | // CreateFromTemplate creates a layer with the same contents and parent as
// another layer. Internally, it may even depend on that other layer
// continuing to exist, as if it were actually a child of the child layer. | [
"CreateFromTemplate",
"creates",
"a",
"layer",
"with",
"the",
"same",
"contents",
"and",
"parent",
"as",
"another",
"layer",
".",
"Internally",
"it",
"may",
"even",
"depend",
"on",
"that",
"other",
"layer",
"continuing",
"to",
"exist",
"as",
"if",
"it",
"wer... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/template.go#L21-L45 | train |
containers/storage | pkg/stringutils/stringutils.go | GenerateRandomASCIIString | func GenerateRandomASCIIString(n int) string {
chars := "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
res := make([]byte, n)
for i := 0; i < n; i++ {
res[i] = chars[rand.Intn(len(chars))]
}
return string(res)
} | go | func GenerateRandomASCIIString(n int) string {
chars := "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
res := make([]byte, n)
for i := 0; i < n; i++ {
res[i] = chars[rand.Intn(len(chars))]
}
return string(res)
} | [
"func",
"GenerateRandomASCIIString",
"(",
"n",
"int",
")",
"string",
"{",
"chars",
":=",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\\\\",
"\\\"",
"\"",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"for",
"i",
":=",
"0",
... | // GenerateRandomASCIIString generates an ASCII random string with length n. | [
"GenerateRandomASCIIString",
"generates",
"an",
"ASCII",
"random",
"string",
"with",
"length",
"n",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/stringutils/stringutils.go#L22-L31 | train |
containers/storage | pkg/stringutils/stringutils.go | Truncate | func Truncate(s string, maxlen int) string {
r := []rune(s)
if len(r) <= maxlen {
return s
}
return string(r[:maxlen])
} | go | func Truncate(s string, maxlen int) string {
r := []rune(s)
if len(r) <= maxlen {
return s
}
return string(r[:maxlen])
} | [
"func",
"Truncate",
"(",
"s",
"string",
",",
"maxlen",
"int",
")",
"string",
"{",
"r",
":=",
"[",
"]",
"rune",
"(",
"s",
")",
"\n",
"if",
"len",
"(",
"r",
")",
"<=",
"maxlen",
"{",
"return",
"s",
"\n",
"}",
"\n",
"return",
"string",
"(",
"r",
... | // Truncate truncates a string to maxlen. | [
"Truncate",
"truncates",
"a",
"string",
"to",
"maxlen",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/stringutils/stringutils.go#L47-L53 | train |
containers/storage | pkg/stringutils/stringutils.go | InSlice | func InSlice(slice []string, s string) bool {
for _, ss := range slice {
if strings.ToLower(s) == strings.ToLower(ss) {
return true
}
}
return false
} | go | func InSlice(slice []string, s string) bool {
for _, ss := range slice {
if strings.ToLower(s) == strings.ToLower(ss) {
return true
}
}
return false
} | [
"func",
"InSlice",
"(",
"slice",
"[",
"]",
"string",
",",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"ss",
":=",
"range",
"slice",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"s",
")",
"==",
"strings",
".",
"ToLower",
"(",
"ss",
")",
"{",
... | // InSlice tests whether a string is contained in a slice of strings or not.
// Comparison is case insensitive | [
"InSlice",
"tests",
"whether",
"a",
"string",
"is",
"contained",
"in",
"a",
"slice",
"of",
"strings",
"or",
"not",
".",
"Comparison",
"is",
"case",
"insensitive"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/stringutils/stringutils.go#L57-L64 | train |
containers/storage | pkg/stringutils/stringutils.go | ShellQuoteArguments | func ShellQuoteArguments(args []string) string {
var buf bytes.Buffer
for i, arg := range args {
if i != 0 {
buf.WriteByte(' ')
}
quote(arg, &buf)
}
return buf.String()
} | go | func ShellQuoteArguments(args []string) string {
var buf bytes.Buffer
for i, arg := range args {
if i != 0 {
buf.WriteByte(' ')
}
quote(arg, &buf)
}
return buf.String()
} | [
"func",
"ShellQuoteArguments",
"(",
"args",
"[",
"]",
"string",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"i",
"!=",
"0",
"{",
"buf",
".",
"WriteByte",
"(",
"' '",
")",... | // ShellQuoteArguments takes a list of strings and escapes them so they will be
// handled right when passed as arguments to a program via a shell | [
"ShellQuoteArguments",
"takes",
"a",
"list",
"of",
"strings",
"and",
"escapes",
"them",
"so",
"they",
"will",
"be",
"handled",
"right",
"when",
"passed",
"as",
"arguments",
"to",
"a",
"program",
"via",
"a",
"shell"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/stringutils/stringutils.go#L90-L99 | train |
containers/storage | pkg/system/exitcode.go | ProcessExitCode | func ProcessExitCode(err error) (exitCode int) {
if err != nil {
var exiterr error
if exitCode, exiterr = GetExitCode(err); exiterr != nil {
// TODO: Fix this so we check the error's text.
// we've failed to retrieve exit code, so we set it to 127
exitCode = 127
}
}
return
} | go | func ProcessExitCode(err error) (exitCode int) {
if err != nil {
var exiterr error
if exitCode, exiterr = GetExitCode(err); exiterr != nil {
// TODO: Fix this so we check the error's text.
// we've failed to retrieve exit code, so we set it to 127
exitCode = 127
}
}
return
} | [
"func",
"ProcessExitCode",
"(",
"err",
"error",
")",
"(",
"exitCode",
"int",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"var",
"exiterr",
"error",
"\n",
"if",
"exitCode",
",",
"exiterr",
"=",
"GetExitCode",
"(",
"err",
")",
";",
"exiterr",
"!=",
"nil",
... | // ProcessExitCode process the specified error and returns the exit status code
// if the error was of type exec.ExitError, returns nothing otherwise. | [
"ProcessExitCode",
"process",
"the",
"specified",
"error",
"and",
"returns",
"the",
"exit",
"status",
"code",
"if",
"the",
"error",
"was",
"of",
"type",
"exec",
".",
"ExitError",
"returns",
"nothing",
"otherwise",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/system/exitcode.go#L23-L33 | train |
containers/storage | drivers/vfs/driver.go | Create | func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
return d.create(id, parent, opts, true)
} | go | func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
return d.create(id, parent, opts, true)
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Create",
"(",
"id",
",",
"parent",
"string",
",",
"opts",
"*",
"graphdriver",
".",
"CreateOpts",
")",
"error",
"{",
"return",
"d",
".",
"create",
"(",
"id",
",",
"parent",
",",
"opts",
",",
"true",
")",
"\n",
... | // Create prepares the filesystem for the VFS driver and copies the directory for the given id under the parent. | [
"Create",
"prepares",
"the",
"filesystem",
"for",
"the",
"VFS",
"driver",
"and",
"copies",
"the",
"directory",
"for",
"the",
"given",
"id",
"under",
"the",
"parent",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/vfs/driver.go#L117-L119 | train |
containers/storage | drivers/vfs/driver.go | AdditionalImageStores | func (d *Driver) AdditionalImageStores() []string {
if len(d.homes) > 1 {
return d.homes[1:]
}
return nil
} | go | func (d *Driver) AdditionalImageStores() []string {
if len(d.homes) > 1 {
return d.homes[1:]
}
return nil
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"AdditionalImageStores",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"d",
".",
"homes",
")",
">",
"1",
"{",
"return",
"d",
".",
"homes",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
... | // AdditionalImageStores returns additional image stores supported by the driver | [
"AdditionalImageStores",
"returns",
"additional",
"image",
"stores",
"supported",
"by",
"the",
"driver"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/vfs/driver.go#L221-L226 | train |
containers/storage | images.go | recomputeDigests | func (image *Image) recomputeDigests() error {
validDigests := make([]digest.Digest, 0, len(image.BigDataDigests)+1)
digests := make(map[digest.Digest]struct{})
if image.Digest != "" {
if err := image.Digest.Validate(); err != nil {
return errors.Wrapf(err, "error validating image digest %q", string(image.Diges... | go | func (image *Image) recomputeDigests() error {
validDigests := make([]digest.Digest, 0, len(image.BigDataDigests)+1)
digests := make(map[digest.Digest]struct{})
if image.Digest != "" {
if err := image.Digest.Validate(); err != nil {
return errors.Wrapf(err, "error validating image digest %q", string(image.Diges... | [
"func",
"(",
"image",
"*",
"Image",
")",
"recomputeDigests",
"(",
")",
"error",
"{",
"validDigests",
":=",
"make",
"(",
"[",
"]",
"digest",
".",
"Digest",
",",
"0",
",",
"len",
"(",
"image",
".",
"BigDataDigests",
")",
"+",
"1",
")",
"\n",
"digests",... | // recomputeDigests takes a fixed digest and a name-to-digest map and builds a
// list of the unique values that would identify the image. | [
"recomputeDigests",
"takes",
"a",
"fixed",
"digest",
"and",
"a",
"name",
"-",
"to",
"-",
"digest",
"map",
"and",
"builds",
"a",
"list",
"of",
"the",
"unique",
"values",
"that",
"would",
"identify",
"the",
"image",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/images.go#L207-L235 | train |
containers/storage | drivers/windows/windows.go | InitFilter | func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
logrus.Debugf("WindowsGraphDriver InitFilter at %s", home)
for _, option := range options {
if strings.HasPrefix(option, "windows.mountopt=") {
return nil, fmt.Errorf("windows driver does not support m... | go | func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
logrus.Debugf("WindowsGraphDriver InitFilter at %s", home)
for _, option := range options {
if strings.HasPrefix(option, "windows.mountopt=") {
return nil, fmt.Errorf("windows driver does not support m... | [
"func",
"InitFilter",
"(",
"home",
"string",
",",
"options",
"[",
"]",
"string",
",",
"uidMaps",
",",
"gidMaps",
"[",
"]",
"idtools",
".",
"IDMap",
")",
"(",
"graphdriver",
".",
"Driver",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\... | // InitFilter returns a new Windows storage filter driver. | [
"InitFilter",
"returns",
"a",
"new",
"Windows",
"storage",
"filter",
"driver",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L86-L118 | train |
containers/storage | drivers/windows/windows.go | Put | func (d *Driver) Put(id string) error {
panicIfUsedByLcow()
logrus.Debugf("WindowsGraphDriver Put() id %s", id)
rID, err := d.resolveID(id)
if err != nil {
return err
}
if count := d.ctr.Decrement(rID); count > 0 {
return nil
}
d.cacheMu.Lock()
_, exists := d.cache[rID]
delete(d.cache, rID)
d.cacheMu.Un... | go | func (d *Driver) Put(id string) error {
panicIfUsedByLcow()
logrus.Debugf("WindowsGraphDriver Put() id %s", id)
rID, err := d.resolveID(id)
if err != nil {
return err
}
if count := d.ctr.Decrement(rID); count > 0 {
return nil
}
d.cacheMu.Lock()
_, exists := d.cache[rID]
delete(d.cache, rID)
d.cacheMu.Un... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Put",
"(",
"id",
"string",
")",
"error",
"{",
"panicIfUsedByLcow",
"(",
")",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n\n",
"rID",
",",
"err",
":=",
"d",
".",
"resolveID",
"(",
"id",... | // Put adds a new layer to the driver. | [
"Put",
"adds",
"a",
"new",
"layer",
"to",
"the",
"driver",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L432-L457 | train |
containers/storage | drivers/windows/windows.go | Diff | func (d *Driver) Diff(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) (_ io.ReadCloser, err error) {
panicIfUsedByLcow()
rID, err := d.resolveID(id)
if err != nil {
return
}
layerChain, err := d.getLayerChain(rID)
if err != nil {
return
}
//... | go | func (d *Driver) Diff(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) (_ io.ReadCloser, err error) {
panicIfUsedByLcow()
rID, err := d.resolveID(id)
if err != nil {
return
}
layerChain, err := d.getLayerChain(rID)
if err != nil {
return
}
//... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Diff",
"(",
"id",
"string",
",",
"idMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"parent",
"string",
",",
"parentMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"mountLabel",
"string",
")",
"(",
"_",
"io",
... | // Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
// The layer should be mounted when calling this function | [
"Diff",
"produces",
"an",
"archive",
"of",
"the",
"changes",
"between",
"the",
"specified",
"layer",
"and",
"its",
"parent",
"layer",
"which",
"may",
"be",
".",
"The",
"layer",
"should",
"be",
"mounted",
"when",
"calling",
"this",
"function"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L491-L523 | train |
containers/storage | drivers/windows/windows.go | ApplyDiff | func (d *Driver) ApplyDiff(id string, idMappings *idtools.IDMappings, parent, mountLabel string, diff io.Reader) (int64, error) {
panicIfUsedByLcow()
var layerChain []string
if parent != "" {
rPId, err := d.resolveID(parent)
if err != nil {
return 0, err
}
parentChain, err := d.getLayerChain(rPId)
if er... | go | func (d *Driver) ApplyDiff(id string, idMappings *idtools.IDMappings, parent, mountLabel string, diff io.Reader) (int64, error) {
panicIfUsedByLcow()
var layerChain []string
if parent != "" {
rPId, err := d.resolveID(parent)
if err != nil {
return 0, err
}
parentChain, err := d.getLayerChain(rPId)
if er... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"ApplyDiff",
"(",
"id",
"string",
",",
"idMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"parent",
",",
"mountLabel",
"string",
",",
"diff",
"io",
".",
"Reader",
")",
"(",
"int64",
",",
"error",
")",
"{",
"pa... | // ApplyDiff extracts the changeset from the given diff into the
// layer with the specified id and parent, returning the size of the
// new layer in bytes.
// The layer should not be mounted when calling this function | [
"ApplyDiff",
"extracts",
"the",
"changeset",
"from",
"the",
"given",
"diff",
"into",
"the",
"layer",
"with",
"the",
"specified",
"id",
"and",
"parent",
"returning",
"the",
"size",
"of",
"the",
"new",
"layer",
"in",
"bytes",
".",
"The",
"layer",
"should",
"... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L584-L614 | train |
containers/storage | drivers/windows/windows.go | Metadata | func (d *Driver) Metadata(id string) (map[string]string, error) {
panicIfUsedByLcow()
m := make(map[string]string)
m["dir"] = d.dir(id)
return m, nil
} | go | func (d *Driver) Metadata(id string) (map[string]string, error) {
panicIfUsedByLcow()
m := make(map[string]string)
m["dir"] = d.dir(id)
return m, nil
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Metadata",
"(",
"id",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"panicIfUsedByLcow",
"(",
")",
"\n",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"... | // Metadata returns custom driver information. | [
"Metadata",
"returns",
"custom",
"driver",
"information",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L641-L646 | train |
containers/storage | drivers/windows/windows.go | UpdateLayerIDMap | func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
return fmt.Errorf("windows doesn't support changing ID mappings")
} | go | func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
return fmt.Errorf("windows doesn't support changing ID mappings")
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"UpdateLayerIDMap",
"(",
"id",
"string",
",",
"toContainer",
",",
"toHost",
"*",
"idtools",
".",
"IDMappings",
",",
"mountLabel",
"string",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"... | // UpdateLayerIDMap changes ownerships in the layer's filesystem tree from
// matching those in toContainer to matching those in toHost. | [
"UpdateLayerIDMap",
"changes",
"ownerships",
"in",
"the",
"layer",
"s",
"filesystem",
"tree",
"from",
"matching",
"those",
"in",
"toContainer",
"to",
"matching",
"those",
"in",
"toHost",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/windows/windows.go#L961-L963 | train |
containers/storage | drivers/devmapper/deviceset.go | cleanupDeletedDevices | func (devices *DeviceSet) cleanupDeletedDevices() error {
devices.Lock()
// If there are no deleted devices, there is nothing to do.
if devices.nrDeletedDevices == 0 {
devices.Unlock()
return nil
}
var deletedDevices []*devInfo
for _, info := range devices.Devices {
if !info.Deleted {
continue
}
l... | go | func (devices *DeviceSet) cleanupDeletedDevices() error {
devices.Lock()
// If there are no deleted devices, there is nothing to do.
if devices.nrDeletedDevices == 0 {
devices.Unlock()
return nil
}
var deletedDevices []*devInfo
for _, info := range devices.Devices {
if !info.Deleted {
continue
}
l... | [
"func",
"(",
"devices",
"*",
"DeviceSet",
")",
"cleanupDeletedDevices",
"(",
")",
"error",
"{",
"devices",
".",
"Lock",
"(",
")",
"\n\n",
"// If there are no deleted devices, there is nothing to do.",
"if",
"devices",
".",
"nrDeletedDevices",
"==",
"0",
"{",
"device... | // Cleanup deleted devices. It assumes that all the devices have been
// loaded in the hash table. | [
"Cleanup",
"deleted",
"devices",
".",
"It",
"assumes",
"that",
"all",
"the",
"devices",
"have",
"been",
"loaded",
"in",
"the",
"hash",
"table",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/devmapper/deviceset.go#L658-L689 | train |
containers/storage | drivers/devmapper/deviceset.go | thinPoolExists | func (devices *DeviceSet) thinPoolExists(thinPoolDevice string) (bool, error) {
logrus.Debugf("devmapper: Checking for existence of the pool %s", thinPoolDevice)
info, err := devicemapper.GetInfo(thinPoolDevice)
if err != nil {
return false, fmt.Errorf("devmapper: GetInfo() on device %s failed: %v", thinPoolDevic... | go | func (devices *DeviceSet) thinPoolExists(thinPoolDevice string) (bool, error) {
logrus.Debugf("devmapper: Checking for existence of the pool %s", thinPoolDevice)
info, err := devicemapper.GetInfo(thinPoolDevice)
if err != nil {
return false, fmt.Errorf("devmapper: GetInfo() on device %s failed: %v", thinPoolDevic... | [
"func",
"(",
"devices",
"*",
"DeviceSet",
")",
"thinPoolExists",
"(",
"thinPoolDevice",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"thinPoolDevice",
")",
"\n\n",
"info",
",",
"err",
":=",
"devicemap... | // Returns if thin pool device exists or not. If device exists, also makes
// sure it is a thin pool device and not some other type of device. | [
"Returns",
"if",
"thin",
"pool",
"device",
"exists",
"or",
"not",
".",
"If",
"device",
"exists",
"also",
"makes",
"sure",
"it",
"is",
"a",
"thin",
"pool",
"device",
"and",
"not",
"some",
"other",
"type",
"of",
"device",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/devmapper/deviceset.go#L1094-L1117 | train |
containers/storage | drivers/devmapper/deviceset.go | getDeviceMajorMinor | func getDeviceMajorMinor(file *os.File) (uint64, uint64, error) {
var stat unix.Stat_t
err := unix.Stat(file.Name(), &stat)
if err != nil {
return 0, 0, err
}
dev := stat.Rdev
majorNum := major(dev)
minorNum := minor(dev)
logrus.Debugf("devmapper: Major:Minor for device: %s is:%v:%v", file.Name(), majorNum,... | go | func getDeviceMajorMinor(file *os.File) (uint64, uint64, error) {
var stat unix.Stat_t
err := unix.Stat(file.Name(), &stat)
if err != nil {
return 0, 0, err
}
dev := stat.Rdev
majorNum := major(dev)
minorNum := minor(dev)
logrus.Debugf("devmapper: Major:Minor for device: %s is:%v:%v", file.Name(), majorNum,... | [
"func",
"getDeviceMajorMinor",
"(",
"file",
"*",
"os",
".",
"File",
")",
"(",
"uint64",
",",
"uint64",
",",
"error",
")",
"{",
"var",
"stat",
"unix",
".",
"Stat_t",
"\n",
"err",
":=",
"unix",
".",
"Stat",
"(",
"file",
".",
"Name",
"(",
")",
",",
... | // Determine the major and minor number of loopback device | [
"Determine",
"the",
"major",
"and",
"minor",
"number",
"of",
"loopback",
"device"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/devmapper/deviceset.go#L1534-L1547 | train |
containers/storage | drivers/devmapper/deviceset.go | issueDiscard | func (devices *DeviceSet) issueDiscard(info *devInfo) error {
logrus.Debugf("devmapper: issueDiscard START(device: %s).", info.Hash)
defer logrus.Debugf("devmapper: issueDiscard END(device: %s).", info.Hash)
// This is a workaround for the kernel not discarding block so
// on the thin pool when we remove a thinp de... | go | func (devices *DeviceSet) issueDiscard(info *devInfo) error {
logrus.Debugf("devmapper: issueDiscard START(device: %s).", info.Hash)
defer logrus.Debugf("devmapper: issueDiscard END(device: %s).", info.Hash)
// This is a workaround for the kernel not discarding block so
// on the thin pool when we remove a thinp de... | [
"func",
"(",
"devices",
"*",
"DeviceSet",
")",
"issueDiscard",
"(",
"info",
"*",
"devInfo",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"info",
".",
"Hash",
")",
"\n",
"defer",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"i... | // Issue discard only if device open count is zero. | [
"Issue",
"discard",
"only",
"if",
"device",
"open",
"count",
"is",
"zero",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/devmapper/deviceset.go#L2044-L2070 | train |
containers/storage | store.go | GetDigestLock | func (s *store) GetDigestLock(d digest.Digest) (Locker, error) {
return GetLockfile(filepath.Join(s.digestLockRoot, d.String()))
} | go | func (s *store) GetDigestLock(d digest.Digest) (Locker, error) {
return GetLockfile(filepath.Join(s.digestLockRoot, d.String()))
} | [
"func",
"(",
"s",
"*",
"store",
")",
"GetDigestLock",
"(",
"d",
"digest",
".",
"Digest",
")",
"(",
"Locker",
",",
"error",
")",
"{",
"return",
"GetLockfile",
"(",
"filepath",
".",
"Join",
"(",
"s",
".",
"digestLockRoot",
",",
"d",
".",
"String",
"(",... | // GetDigestLock returns a digest-specific Locker. | [
"GetDigestLock",
"returns",
"a",
"digest",
"-",
"specific",
"Locker",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L715-L717 | train |
containers/storage | store.go | LayerStore | func (s *store) LayerStore() (LayerStore, error) {
s.graphLock.Lock()
defer s.graphLock.Unlock()
if s.graphLock.TouchedSince(s.lastLoaded) {
s.graphDriver = nil
s.layerStore = nil
s.lastLoaded = time.Now()
}
if s.layerStore != nil {
return s.layerStore, nil
}
driver, err := s.getGraphDriver()
if err != ... | go | func (s *store) LayerStore() (LayerStore, error) {
s.graphLock.Lock()
defer s.graphLock.Unlock()
if s.graphLock.TouchedSince(s.lastLoaded) {
s.graphDriver = nil
s.layerStore = nil
s.lastLoaded = time.Now()
}
if s.layerStore != nil {
return s.layerStore, nil
}
driver, err := s.getGraphDriver()
if err != ... | [
"func",
"(",
"s",
"*",
"store",
")",
"LayerStore",
"(",
")",
"(",
"LayerStore",
",",
"error",
")",
"{",
"s",
".",
"graphLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"graphLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"s",
".",
"graphLock"... | // LayerStore obtains and returns a handle to the writeable layer store object
// used by the Store. Accessing this store directly will bypass locking and
// synchronization, so it is not a part of the exported Store interface. | [
"LayerStore",
"obtains",
"and",
"returns",
"a",
"handle",
"to",
"the",
"writeable",
"layer",
"store",
"object",
"used",
"by",
"the",
"Store",
".",
"Accessing",
"this",
"store",
"directly",
"will",
"bypass",
"locking",
"and",
"synchronization",
"so",
"it",
"is"... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L752-L782 | train |
containers/storage | store.go | ImageStore | func (s *store) ImageStore() (ImageStore, error) {
if s.imageStore != nil {
return s.imageStore, nil
}
return nil, ErrLoadError
} | go | func (s *store) ImageStore() (ImageStore, error) {
if s.imageStore != nil {
return s.imageStore, nil
}
return nil, ErrLoadError
} | [
"func",
"(",
"s",
"*",
"store",
")",
"ImageStore",
"(",
")",
"(",
"ImageStore",
",",
"error",
")",
"{",
"if",
"s",
".",
"imageStore",
"!=",
"nil",
"{",
"return",
"s",
".",
"imageStore",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrLoadErr... | // ImageStore obtains and returns a handle to the writable image store object
// used by the Store. Accessing this store directly will bypass locking and
// synchronization, so it is not a part of the exported Store interface. | [
"ImageStore",
"obtains",
"and",
"returns",
"a",
"handle",
"to",
"the",
"writable",
"image",
"store",
"object",
"used",
"by",
"the",
"Store",
".",
"Accessing",
"this",
"store",
"directly",
"will",
"bypass",
"locking",
"and",
"synchronization",
"so",
"it",
"is",... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L816-L821 | train |
containers/storage | store.go | ContainerStore | func (s *store) ContainerStore() (ContainerStore, error) {
if s.containerStore != nil {
return s.containerStore, nil
}
return nil, ErrLoadError
} | go | func (s *store) ContainerStore() (ContainerStore, error) {
if s.containerStore != nil {
return s.containerStore, nil
}
return nil, ErrLoadError
} | [
"func",
"(",
"s",
"*",
"store",
")",
"ContainerStore",
"(",
")",
"(",
"ContainerStore",
",",
"error",
")",
"{",
"if",
"s",
".",
"containerStore",
"!=",
"nil",
"{",
"return",
"s",
".",
"containerStore",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",... | // ContainerStore obtains and returns a handle to the container store object
// used by the Store. Accessing this store directly will bypass locking and
// synchronization, so it is not a part of the exported Store interface. | [
"ContainerStore",
"obtains",
"and",
"returns",
"a",
"handle",
"to",
"the",
"container",
"store",
"object",
"used",
"by",
"the",
"Store",
".",
"Accessing",
"this",
"store",
"directly",
"will",
"bypass",
"locking",
"and",
"synchronization",
"so",
"it",
"is",
"no... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L849-L854 | train |
containers/storage | store.go | makeBigDataBaseName | func makeBigDataBaseName(key string) string {
reader := strings.NewReader(key)
for reader.Len() > 0 {
ch, size, err := reader.ReadRune()
if err != nil || size != 1 {
break
}
if ch != '.' && !(ch >= '0' && ch <= '9') && !(ch >= 'a' && ch <= 'z') {
break
}
}
if reader.Len() > 0 {
return "=" + base64... | go | func makeBigDataBaseName(key string) string {
reader := strings.NewReader(key)
for reader.Len() > 0 {
ch, size, err := reader.ReadRune()
if err != nil || size != 1 {
break
}
if ch != '.' && !(ch >= '0' && ch <= '9') && !(ch >= 'a' && ch <= 'z') {
break
}
}
if reader.Len() > 0 {
return "=" + base64... | [
"func",
"makeBigDataBaseName",
"(",
"key",
"string",
")",
"string",
"{",
"reader",
":=",
"strings",
".",
"NewReader",
"(",
"key",
")",
"\n",
"for",
"reader",
".",
"Len",
"(",
")",
">",
"0",
"{",
"ch",
",",
"size",
",",
"err",
":=",
"reader",
".",
"... | // Convert a BigData key name into an acceptable file name. | [
"Convert",
"a",
"BigData",
"key",
"name",
"into",
"an",
"acceptable",
"file",
"name",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L3167-L3182 | train |
containers/storage | store.go | DefaultConfigFile | func DefaultConfigFile(rootless bool) (string, error) {
if rootless {
home, err := homeDir()
if err != nil {
return "", errors.Wrapf(err, "cannot determine users homedir")
}
return filepath.Join(home, ".config/containers/storage.conf"), nil
}
return defaultConfigFile, nil
} | go | func DefaultConfigFile(rootless bool) (string, error) {
if rootless {
home, err := homeDir()
if err != nil {
return "", errors.Wrapf(err, "cannot determine users homedir")
}
return filepath.Join(home, ".config/containers/storage.conf"), nil
}
return defaultConfigFile, nil
} | [
"func",
"DefaultConfigFile",
"(",
"rootless",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"rootless",
"{",
"home",
",",
"err",
":=",
"homeDir",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"... | // DefaultConfigFile returns the path to the storage config file used | [
"DefaultConfigFile",
"returns",
"the",
"path",
"to",
"the",
"storage",
"config",
"file",
"used"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/store.go#L3243-L3252 | train |
containers/storage | pkg/archive/changes_linux.go | walkchunk | func walkchunk(path string, fi os.FileInfo, dir string, root *FileInfo) error {
if fi == nil {
return nil
}
parent := root.LookUp(filepath.Dir(path))
if parent == nil {
return fmt.Errorf("walkchunk: Unexpectedly no parent for %s", path)
}
info := &FileInfo{
name: filepath.Base(path),
children: mak... | go | func walkchunk(path string, fi os.FileInfo, dir string, root *FileInfo) error {
if fi == nil {
return nil
}
parent := root.LookUp(filepath.Dir(path))
if parent == nil {
return fmt.Errorf("walkchunk: Unexpectedly no parent for %s", path)
}
info := &FileInfo{
name: filepath.Base(path),
children: mak... | [
"func",
"walkchunk",
"(",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
",",
"dir",
"string",
",",
"root",
"*",
"FileInfo",
")",
"error",
"{",
"if",
"fi",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"parent",
":=",
"root",
".",
"LookU... | // Given a FileInfo, its path info, and a reference to the root of the tree
// being constructed, register this file with the tree. | [
"Given",
"a",
"FileInfo",
"its",
"path",
"info",
"and",
"a",
"reference",
"to",
"the",
"root",
"of",
"the",
"tree",
"being",
"constructed",
"register",
"this",
"file",
"with",
"the",
"tree",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/changes_linux.go#L66-L89 | train |
containers/storage | pkg/archive/diff.go | ApplyLayer | func ApplyLayer(dest string, layer io.Reader) (int64, error) {
return applyLayerHandler(dest, layer, &TarOptions{}, true)
} | go | func ApplyLayer(dest string, layer io.Reader) (int64, error) {
return applyLayerHandler(dest, layer, &TarOptions{}, true)
} | [
"func",
"ApplyLayer",
"(",
"dest",
"string",
",",
"layer",
"io",
".",
"Reader",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"applyLayerHandler",
"(",
"dest",
",",
"layer",
",",
"&",
"TarOptions",
"{",
"}",
",",
"true",
")",
"\n",
"}"
] | // ApplyLayer parses a diff in the standard layer format from `layer`,
// and applies it to the directory `dest`. The stream `layer` can be
// compressed or uncompressed.
// Returns the size in bytes of the contents of the layer. | [
"ApplyLayer",
"parses",
"a",
"diff",
"in",
"the",
"standard",
"layer",
"format",
"from",
"layer",
"and",
"applies",
"it",
"to",
"the",
"directory",
"dest",
".",
"The",
"stream",
"layer",
"can",
"be",
"compressed",
"or",
"uncompressed",
".",
"Returns",
"the",... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/diff.go#L226-L228 | train |
containers/storage | pkg/archive/diff.go | applyLayerHandler | func applyLayerHandler(dest string, layer io.Reader, options *TarOptions, decompress bool) (int64, error) {
dest = filepath.Clean(dest)
// We need to be able to set any perms
oldmask, err := system.Umask(0)
if err != nil {
return 0, err
}
defer system.Umask(oldmask) // ignore err, ErrNotSupportedPlatform
if ... | go | func applyLayerHandler(dest string, layer io.Reader, options *TarOptions, decompress bool) (int64, error) {
dest = filepath.Clean(dest)
// We need to be able to set any perms
oldmask, err := system.Umask(0)
if err != nil {
return 0, err
}
defer system.Umask(oldmask) // ignore err, ErrNotSupportedPlatform
if ... | [
"func",
"applyLayerHandler",
"(",
"dest",
"string",
",",
"layer",
"io",
".",
"Reader",
",",
"options",
"*",
"TarOptions",
",",
"decompress",
"bool",
")",
"(",
"int64",
",",
"error",
")",
"{",
"dest",
"=",
"filepath",
".",
"Clean",
"(",
"dest",
")",
"\n... | // do the bulk load of ApplyLayer, but allow for not calling DecompressStream | [
"do",
"the",
"bulk",
"load",
"of",
"ApplyLayer",
"but",
"allow",
"for",
"not",
"calling",
"DecompressStream"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/diff.go#L239-L256 | train |
containers/storage | drivers/chown.go | ChownPathByMaps | func ChownPathByMaps(path string, toContainer, toHost *idtools.IDMappings) error {
if toContainer == nil {
toContainer = &idtools.IDMappings{}
}
if toHost == nil {
toHost = &idtools.IDMappings{}
}
config, err := json.Marshal([4][]idtools.IDMap{toContainer.UIDs(), toContainer.GIDs(), toHost.UIDs(), toHost.GIDs... | go | func ChownPathByMaps(path string, toContainer, toHost *idtools.IDMappings) error {
if toContainer == nil {
toContainer = &idtools.IDMappings{}
}
if toHost == nil {
toHost = &idtools.IDMappings{}
}
config, err := json.Marshal([4][]idtools.IDMap{toContainer.UIDs(), toContainer.GIDs(), toHost.UIDs(), toHost.GIDs... | [
"func",
"ChownPathByMaps",
"(",
"path",
"string",
",",
"toContainer",
",",
"toHost",
"*",
"idtools",
".",
"IDMappings",
")",
"error",
"{",
"if",
"toContainer",
"==",
"nil",
"{",
"toContainer",
"=",
"&",
"idtools",
".",
"IDMappings",
"{",
"}",
"\n",
"}",
... | // ChownPathByMaps walks the filesystem tree, changing the ownership
// information using the toContainer and toHost mappings, using them to replace
// on-disk owner UIDs and GIDs which are "host" values in the first map with
// UIDs and GIDs for "host" values from the second map which correspond to the
// same "contai... | [
"ChownPathByMaps",
"walks",
"the",
"filesystem",
"tree",
"changing",
"the",
"ownership",
"information",
"using",
"the",
"toContainer",
"and",
"toHost",
"mappings",
"using",
"them",
"to",
"replace",
"on",
"-",
"disk",
"owner",
"UIDs",
"and",
"GIDs",
"which",
"are... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/chown.go#L72-L98 | train |
containers/storage | drivers/chown.go | UpdateLayerIDMap | func (n *naiveLayerIDMapUpdater) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
driver := n.ProtoDriver
options := MountOpts{
MountLabel: mountLabel,
}
layerFs, err := driver.Get(id, options)
if err != nil {
return err
}
defer func() {
driver.Put(id)
}()
... | go | func (n *naiveLayerIDMapUpdater) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
driver := n.ProtoDriver
options := MountOpts{
MountLabel: mountLabel,
}
layerFs, err := driver.Get(id, options)
if err != nil {
return err
}
defer func() {
driver.Put(id)
}()
... | [
"func",
"(",
"n",
"*",
"naiveLayerIDMapUpdater",
")",
"UpdateLayerIDMap",
"(",
"id",
"string",
",",
"toContainer",
",",
"toHost",
"*",
"idtools",
".",
"IDMappings",
",",
"mountLabel",
"string",
")",
"error",
"{",
"driver",
":=",
"n",
".",
"ProtoDriver",
"\n"... | // UpdateLayerIDMap walks the layer's filesystem tree, changing the ownership
// information using the toContainer and toHost mappings, using them to replace
// on-disk owner UIDs and GIDs which are "host" values in the first map with
// UIDs and GIDs for "host" values from the second map which correspond to the
// sam... | [
"UpdateLayerIDMap",
"walks",
"the",
"layer",
"s",
"filesystem",
"tree",
"changing",
"the",
"ownership",
"information",
"using",
"the",
"toContainer",
"and",
"toHost",
"mappings",
"using",
"them",
"to",
"replace",
"on",
"-",
"disk",
"owner",
"UIDs",
"and",
"GIDs"... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/chown.go#L115-L129 | train |
containers/storage | drivers/copy/copy_unsupported.go | DirCopy | func DirCopy(srcDir, dstDir string, _ Mode, _ bool) error {
return chrootarchive.NewArchiver(nil).CopyWithTar(srcDir, dstDir)
} | go | func DirCopy(srcDir, dstDir string, _ Mode, _ bool) error {
return chrootarchive.NewArchiver(nil).CopyWithTar(srcDir, dstDir)
} | [
"func",
"DirCopy",
"(",
"srcDir",
",",
"dstDir",
"string",
",",
"_",
"Mode",
",",
"_",
"bool",
")",
"error",
"{",
"return",
"chrootarchive",
".",
"NewArchiver",
"(",
"nil",
")",
".",
"CopyWithTar",
"(",
"srcDir",
",",
"dstDir",
")",
"\n",
"}"
] | // DirCopy copies or hardlinks the contents of one directory to another,
// properly handling soft links | [
"DirCopy",
"copies",
"or",
"hardlinks",
"the",
"contents",
"of",
"one",
"directory",
"to",
"another",
"properly",
"handling",
"soft",
"links"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/copy/copy_unsupported.go#L17-L19 | train |
containers/storage | drivers/driver_solaris.go | Mounted | func Mounted(fsType FsMagic, mountPath string) (bool, error) {
cs := C.CString(filepath.Dir(mountPath))
defer C.free(unsafe.Pointer(cs))
buf := C.getstatfs(cs)
defer C.free(unsafe.Pointer(buf))
// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 1... | go | func Mounted(fsType FsMagic, mountPath string) (bool, error) {
cs := C.CString(filepath.Dir(mountPath))
defer C.free(unsafe.Pointer(cs))
buf := C.getstatfs(cs)
defer C.free(unsafe.Pointer(buf))
// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 1... | [
"func",
"Mounted",
"(",
"fsType",
"FsMagic",
",",
"mountPath",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"filepath",
".",
"Dir",
"(",
"mountPath",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsa... | // Mounted checks if the given path is mounted as the fs type
//Solaris supports only ZFS for now | [
"Mounted",
"checks",
"if",
"the",
"given",
"path",
"is",
"mounted",
"as",
"the",
"fs",
"type",
"Solaris",
"supports",
"only",
"ZFS",
"for",
"now"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/driver_solaris.go#L81-L96 | train |
containers/storage | lockfile_linux.go | TouchedSince | func (l *lockfile) TouchedSince(when time.Time) bool {
st := unix.Stat_t{}
err := unix.Fstat(int(l.fd), &st)
if err != nil {
return true
}
touched := time.Unix(st.Mtim.Unix())
return when.Before(touched)
} | go | func (l *lockfile) TouchedSince(when time.Time) bool {
st := unix.Stat_t{}
err := unix.Fstat(int(l.fd), &st)
if err != nil {
return true
}
touched := time.Unix(st.Mtim.Unix())
return when.Before(touched)
} | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"TouchedSince",
"(",
"when",
"time",
".",
"Time",
")",
"bool",
"{",
"st",
":=",
"unix",
".",
"Stat_t",
"{",
"}",
"\n",
"err",
":=",
"unix",
".",
"Fstat",
"(",
"int",
"(",
"l",
".",
"fd",
")",
",",
"&",
... | // TouchedSince indicates if the lock file has been touched since the specified time | [
"TouchedSince",
"indicates",
"if",
"the",
"lock",
"file",
"has",
"been",
"touched",
"since",
"the",
"specified",
"time"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_linux.go#L12-L20 | train |
containers/storage | pkg/archive/archive.go | NewDefaultArchiver | func NewDefaultArchiver() *Archiver {
return &Archiver{Untar: Untar, TarIDMappings: &idtools.IDMappings{}, UntarIDMappings: &idtools.IDMappings{}}
} | go | func NewDefaultArchiver() *Archiver {
return &Archiver{Untar: Untar, TarIDMappings: &idtools.IDMappings{}, UntarIDMappings: &idtools.IDMappings{}}
} | [
"func",
"NewDefaultArchiver",
"(",
")",
"*",
"Archiver",
"{",
"return",
"&",
"Archiver",
"{",
"Untar",
":",
"Untar",
",",
"TarIDMappings",
":",
"&",
"idtools",
".",
"IDMappings",
"{",
"}",
",",
"UntarIDMappings",
":",
"&",
"idtools",
".",
"IDMappings",
"{"... | // NewDefaultArchiver returns a new Archiver without any IDMappings | [
"NewDefaultArchiver",
"returns",
"a",
"new",
"Archiver",
"without",
"any",
"IDMappings"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L83-L85 | train |
containers/storage | pkg/archive/archive.go | NewArchiver | func NewArchiver(idMappings *idtools.IDMappings) *Archiver {
if idMappings == nil {
idMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: idMappings, UntarIDMappings: idMappings}
} | go | func NewArchiver(idMappings *idtools.IDMappings) *Archiver {
if idMappings == nil {
idMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: idMappings, UntarIDMappings: idMappings}
} | [
"func",
"NewArchiver",
"(",
"idMappings",
"*",
"idtools",
".",
"IDMappings",
")",
"*",
"Archiver",
"{",
"if",
"idMappings",
"==",
"nil",
"{",
"idMappings",
"=",
"&",
"idtools",
".",
"IDMappings",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Archiver",
"{",... | // NewArchiver returns a new Archiver | [
"NewArchiver",
"returns",
"a",
"new",
"Archiver"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1338-L1343 | train |
containers/storage | pkg/archive/archive.go | NewArchiverWithChown | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *Archiver {
if tarIDMappings == nil {
tarIDMappings = &idtools.IDMappings{}
}
if untarIDMappings == nil {
untarIDMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMa... | go | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *Archiver {
if tarIDMappings == nil {
tarIDMappings = &idtools.IDMappings{}
}
if untarIDMappings == nil {
untarIDMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMa... | [
"func",
"NewArchiverWithChown",
"(",
"tarIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"chownOpts",
"*",
"idtools",
".",
"IDPair",
",",
"untarIDMappings",
"*",
"idtools",
".",
"IDMappings",
")",
"*",
"Archiver",
"{",
"if",
"tarIDMappings",
"==",
"nil",
... | // NewArchiverWithChown returns a new Archiver which uses Untar and the provided ID mapping configuration on both ends | [
"NewArchiverWithChown",
"returns",
"a",
"new",
"Archiver",
"which",
"uses",
"Untar",
"and",
"the",
"provided",
"ID",
"mapping",
"configuration",
"on",
"both",
"ends"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1346-L1354 | train |
containers/storage | pkg/archive/archive.go | TarPath | func TarPath(uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(path string) (io.ReadCloser, error) {
tarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
return func(path string) (io.ReadCloser, error) {
return TarWithOptions(path, &TarOptions{
Compression: Uncompressed,
UIDMaps: tarMappings.UI... | go | func TarPath(uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(path string) (io.ReadCloser, error) {
tarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
return func(path string) (io.ReadCloser, error) {
return TarWithOptions(path, &TarOptions{
Compression: Uncompressed,
UIDMaps: tarMappings.UI... | [
"func",
"TarPath",
"(",
"uidmap",
"[",
"]",
"idtools",
".",
"IDMap",
",",
"gidmap",
"[",
"]",
"idtools",
".",
"IDMap",
")",
"func",
"(",
"path",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"tarMappings",
":=",
"idtools",
".",... | // TarPath returns a function which creates an archive of a specified
// location in the container's filesystem, mapping permissions using the
// container's ID maps | [
"TarPath",
"returns",
"a",
"function",
"which",
"creates",
"an",
"archive",
"of",
"a",
"specified",
"location",
"in",
"the",
"container",
"s",
"filesystem",
"mapping",
"permissions",
"using",
"the",
"container",
"s",
"ID",
"maps"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1431-L1440 | train |
Masterminds/semver | version.go | NewVersion | func NewVersion(v string) (*Version, error) {
m := versionRegex.FindStringSubmatch(v)
if m == nil {
return nil, ErrInvalidSemVer
}
sv := &Version{
metadata: m[8],
pre: m[5],
original: v,
}
var temp int64
temp, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("Error p... | go | func NewVersion(v string) (*Version, error) {
m := versionRegex.FindStringSubmatch(v)
if m == nil {
return nil, ErrInvalidSemVer
}
sv := &Version{
metadata: m[8],
pre: m[5],
original: v,
}
var temp int64
temp, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("Error p... | [
"func",
"NewVersion",
"(",
"v",
"string",
")",
"(",
"*",
"Version",
",",
"error",
")",
"{",
"m",
":=",
"versionRegex",
".",
"FindStringSubmatch",
"(",
"v",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrInvalidSemVer",
"\n",
"}",
"... | // NewVersion parses a given version and returns an instance of Version or
// an error if unable to parse the version. | [
"NewVersion",
"parses",
"a",
"given",
"version",
"and",
"returns",
"an",
"instance",
"of",
"Version",
"or",
"an",
"error",
"if",
"unable",
"to",
"parse",
"the",
"version",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L54-L94 | train |
Masterminds/semver | version.go | MustParse | func MustParse(v string) *Version {
sv, err := NewVersion(v)
if err != nil {
panic(err)
}
return sv
} | go | func MustParse(v string) *Version {
sv, err := NewVersion(v)
if err != nil {
panic(err)
}
return sv
} | [
"func",
"MustParse",
"(",
"v",
"string",
")",
"*",
"Version",
"{",
"sv",
",",
"err",
":=",
"NewVersion",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // MustParse parses a given version and panics on error. | [
"MustParse",
"parses",
"a",
"given",
"version",
"and",
"panics",
"on",
"error",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L97-L103 | train |
Masterminds/semver | version.go | originalVPrefix | func (v *Version) originalVPrefix() string {
// Note, only lowercase v is supported as a prefix by the parser.
if v.original != "" && v.original[:1] == "v" {
return v.original[:1]
}
return ""
} | go | func (v *Version) originalVPrefix() string {
// Note, only lowercase v is supported as a prefix by the parser.
if v.original != "" && v.original[:1] == "v" {
return v.original[:1]
}
return ""
} | [
"func",
"(",
"v",
"*",
"Version",
")",
"originalVPrefix",
"(",
")",
"string",
"{",
"// Note, only lowercase v is supported as a prefix by the parser.",
"if",
"v",
".",
"original",
"!=",
"\"",
"\"",
"&&",
"v",
".",
"original",
"[",
":",
"1",
"]",
"==",
"\"",
... | // originalVPrefix returns the original 'v' prefix if any. | [
"originalVPrefix",
"returns",
"the",
"original",
"v",
"prefix",
"if",
"any",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L155-L162 | train |
Masterminds/semver | version.go | IncMinor | func (v Version) IncMinor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = v.minor + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | go | func (v Version) IncMinor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = v.minor + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | [
"func",
"(",
"v",
"Version",
")",
"IncMinor",
"(",
")",
"Version",
"{",
"vNext",
":=",
"v",
"\n",
"vNext",
".",
"metadata",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"pre",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"patch",
"=",
"0",
"\n",
"vNext",
".",
... | // IncMinor produces the next minor version.
// Sets patch to 0.
// Increments minor number.
// Unsets metadata.
// Unsets prerelease status. | [
"IncMinor",
"produces",
"the",
"next",
"minor",
"version",
".",
"Sets",
"patch",
"to",
"0",
".",
"Increments",
"minor",
"number",
".",
"Unsets",
"metadata",
".",
"Unsets",
"prerelease",
"status",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L192-L200 | train |
Masterminds/semver | version.go | IncMajor | func (v Version) IncMajor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = 0
vNext.major = v.major + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | go | func (v Version) IncMajor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = 0
vNext.major = v.major + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | [
"func",
"(",
"v",
"Version",
")",
"IncMajor",
"(",
")",
"Version",
"{",
"vNext",
":=",
"v",
"\n",
"vNext",
".",
"metadata",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"pre",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"patch",
"=",
"0",
"\n",
"vNext",
".",
... | // IncMajor produces the next major version.
// Sets patch to 0.
// Sets minor to 0.
// Increments major number.
// Unsets metadata.
// Unsets prerelease status. | [
"IncMajor",
"produces",
"the",
"next",
"major",
"version",
".",
"Sets",
"patch",
"to",
"0",
".",
"Sets",
"minor",
"to",
"0",
".",
"Increments",
"major",
"number",
".",
"Unsets",
"metadata",
".",
"Unsets",
"prerelease",
"status",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L208-L217 | train |
Masterminds/semver | version.go | SetPrerelease | func (v Version) SetPrerelease(prerelease string) (Version, error) {
vNext := v
if len(prerelease) > 0 && !validPrereleaseRegex.MatchString(prerelease) {
return vNext, ErrInvalidPrerelease
}
vNext.pre = prerelease
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | go | func (v Version) SetPrerelease(prerelease string) (Version, error) {
vNext := v
if len(prerelease) > 0 && !validPrereleaseRegex.MatchString(prerelease) {
return vNext, ErrInvalidPrerelease
}
vNext.pre = prerelease
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | [
"func",
"(",
"v",
"Version",
")",
"SetPrerelease",
"(",
"prerelease",
"string",
")",
"(",
"Version",
",",
"error",
")",
"{",
"vNext",
":=",
"v",
"\n",
"if",
"len",
"(",
"prerelease",
")",
">",
"0",
"&&",
"!",
"validPrereleaseRegex",
".",
"MatchString",
... | // SetPrerelease defines the prerelease value.
// Value must not include the required 'hypen' prefix. | [
"SetPrerelease",
"defines",
"the",
"prerelease",
"value",
".",
"Value",
"must",
"not",
"include",
"the",
"required",
"hypen",
"prefix",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L221-L229 | train |
Masterminds/semver | version.go | SetMetadata | func (v Version) SetMetadata(metadata string) (Version, error) {
vNext := v
if len(metadata) > 0 && !validPrereleaseRegex.MatchString(metadata) {
return vNext, ErrInvalidMetadata
}
vNext.metadata = metadata
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | go | func (v Version) SetMetadata(metadata string) (Version, error) {
vNext := v
if len(metadata) > 0 && !validPrereleaseRegex.MatchString(metadata) {
return vNext, ErrInvalidMetadata
}
vNext.metadata = metadata
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | [
"func",
"(",
"v",
"Version",
")",
"SetMetadata",
"(",
"metadata",
"string",
")",
"(",
"Version",
",",
"error",
")",
"{",
"vNext",
":=",
"v",
"\n",
"if",
"len",
"(",
"metadata",
")",
">",
"0",
"&&",
"!",
"validPrereleaseRegex",
".",
"MatchString",
"(",
... | // SetMetadata defines metadata value.
// Value must not include the required 'plus' prefix. | [
"SetMetadata",
"defines",
"metadata",
"value",
".",
"Value",
"must",
"not",
"include",
"the",
"required",
"plus",
"prefix",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L233-L241 | train |
Masterminds/semver | version.go | Compare | func (v *Version) Compare(o *Version) int {
// Compare the major, minor, and patch version for differences. If a
// difference is found return the comparison.
if d := compareSegment(v.Major(), o.Major()); d != 0 {
return d
}
if d := compareSegment(v.Minor(), o.Minor()); d != 0 {
return d
}
if d := compareSeg... | go | func (v *Version) Compare(o *Version) int {
// Compare the major, minor, and patch version for differences. If a
// difference is found return the comparison.
if d := compareSegment(v.Major(), o.Major()); d != 0 {
return d
}
if d := compareSegment(v.Minor(), o.Minor()); d != 0 {
return d
}
if d := compareSeg... | [
"func",
"(",
"v",
"*",
"Version",
")",
"Compare",
"(",
"o",
"*",
"Version",
")",
"int",
"{",
"// Compare the major, minor, and patch version for differences. If a",
"// difference is found return the comparison.",
"if",
"d",
":=",
"compareSegment",
"(",
"v",
".",
"Major... | // Compare compares this version to another one. It returns -1, 0, or 1 if
// the version smaller, equal, or larger than the other version.
//
// Versions are compared by X.Y.Z. Build metadata is ignored. Prerelease is
// lower than the version without a prerelease. | [
"Compare",
"compares",
"this",
"version",
"to",
"another",
"one",
".",
"It",
"returns",
"-",
"1",
"0",
"or",
"1",
"if",
"the",
"version",
"smaller",
"equal",
"or",
"larger",
"than",
"the",
"other",
"version",
".",
"Versions",
"are",
"compared",
"by",
"X"... | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L265-L293 | train |
Masterminds/semver | version.go | UnmarshalJSON | func (v *Version) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
temp, err := NewVersion(s)
if err != nil {
return err
}
v.major = temp.major
v.minor = temp.minor
v.patch = temp.patch
v.pre = temp.pre
v.metadata = temp.metadata
v.original = temp.o... | go | func (v *Version) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
temp, err := NewVersion(s)
if err != nil {
return err
}
v.major = temp.major
v.minor = temp.minor
v.patch = temp.patch
v.pre = temp.pre
v.metadata = temp.metadata
v.original = temp.o... | [
"func",
"(",
"v",
"*",
"Version",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return"... | // UnmarshalJSON implements JSON.Unmarshaler interface. | [
"UnmarshalJSON",
"implements",
"JSON",
".",
"Unmarshaler",
"interface",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L296-L313 | train |
Masterminds/semver | constraints.go | NewConstraint | func NewConstraint(c string) (*Constraints, error) {
// Rewrite - ranges into a comparison operation.
c = rewriteRange(c)
ors := strings.Split(c, "||")
or := make([][]*constraint, len(ors))
for k, v := range ors {
cs := strings.Split(v, ",")
result := make([]*constraint, len(cs))
for i, s := range cs {
... | go | func NewConstraint(c string) (*Constraints, error) {
// Rewrite - ranges into a comparison operation.
c = rewriteRange(c)
ors := strings.Split(c, "||")
or := make([][]*constraint, len(ors))
for k, v := range ors {
cs := strings.Split(v, ",")
result := make([]*constraint, len(cs))
for i, s := range cs {
... | [
"func",
"NewConstraint",
"(",
"c",
"string",
")",
"(",
"*",
"Constraints",
",",
"error",
")",
"{",
"// Rewrite - ranges into a comparison operation.",
"c",
"=",
"rewriteRange",
"(",
"c",
")",
"\n\n",
"ors",
":=",
"strings",
".",
"Split",
"(",
"c",
",",
"\"",... | // NewConstraint returns a Constraints instance that a Version instance can
// be checked against. If there is a parse error it will be returned. | [
"NewConstraint",
"returns",
"a",
"Constraints",
"instance",
"that",
"a",
"Version",
"instance",
"can",
"be",
"checked",
"against",
".",
"If",
"there",
"is",
"a",
"parse",
"error",
"it",
"will",
"be",
"returned",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L18-L41 | train |
Masterminds/semver | constraints.go | Check | func (cs Constraints) Check(v *Version) bool {
// loop over the ORs and check the inner ANDs
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
joy = false
break
}
}
if joy {
return true
}
}
return false
} | go | func (cs Constraints) Check(v *Version) bool {
// loop over the ORs and check the inner ANDs
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
joy = false
break
}
}
if joy {
return true
}
}
return false
} | [
"func",
"(",
"cs",
"Constraints",
")",
"Check",
"(",
"v",
"*",
"Version",
")",
"bool",
"{",
"// loop over the ORs and check the inner ANDs",
"for",
"_",
",",
"o",
":=",
"range",
"cs",
".",
"constraints",
"{",
"joy",
":=",
"true",
"\n",
"for",
"_",
",",
"... | // Check tests if a version satisfies the constraints. | [
"Check",
"tests",
"if",
"a",
"version",
"satisfies",
"the",
"constraints",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L44-L61 | train |
Masterminds/semver | constraints.go | Validate | func (cs Constraints) Validate(v *Version) (bool, []error) {
// loop over the ORs and check the inner ANDs
var e []error
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
em := fmt.Errorf(c.msg, v, c.orig)
e = append(e, em)
joy = false
}
}
if joy {
re... | go | func (cs Constraints) Validate(v *Version) (bool, []error) {
// loop over the ORs and check the inner ANDs
var e []error
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
em := fmt.Errorf(c.msg, v, c.orig)
e = append(e, em)
joy = false
}
}
if joy {
re... | [
"func",
"(",
"cs",
"Constraints",
")",
"Validate",
"(",
"v",
"*",
"Version",
")",
"(",
"bool",
",",
"[",
"]",
"error",
")",
"{",
"// loop over the ORs and check the inner ANDs",
"var",
"e",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
... | // Validate checks if a version satisfies a constraint. If not a slice of
// reasons for the failure are returned in addition to a bool. | [
"Validate",
"checks",
"if",
"a",
"version",
"satisfies",
"a",
"constraint",
".",
"If",
"not",
"a",
"slice",
"of",
"reasons",
"for",
"the",
"failure",
"are",
"returned",
"in",
"addition",
"to",
"a",
"bool",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L65-L84 | train |
Masterminds/semver | constraints.go | check | func (c *constraint) check(v *Version) bool {
return c.function(v, c)
} | go | func (c *constraint) check(v *Version) bool {
return c.function(v, c)
} | [
"func",
"(",
"c",
"*",
"constraint",
")",
"check",
"(",
"v",
"*",
"Version",
")",
"bool",
"{",
"return",
"c",
".",
"function",
"(",
"v",
",",
"c",
")",
"\n",
"}"
] | // Check if a version meets the constraint | [
"Check",
"if",
"a",
"version",
"meets",
"the",
"constraint"
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L158-L160 | train |
Masterminds/semver | collection.go | Less | func (c Collection) Less(i, j int) bool {
return c[i].LessThan(c[j])
} | go | func (c Collection) Less(i, j int) bool {
return c[i].LessThan(c[j])
} | [
"func",
"(",
"c",
"Collection",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"c",
"[",
"i",
"]",
".",
"LessThan",
"(",
"c",
"[",
"j",
"]",
")",
"\n",
"}"
] | // Less is needed for the sort interface to compare two Version objects on the
// slice. If checks if one is less than the other. | [
"Less",
"is",
"needed",
"for",
"the",
"sort",
"interface",
"to",
"compare",
"two",
"Version",
"objects",
"on",
"the",
"slice",
".",
"If",
"checks",
"if",
"one",
"is",
"less",
"than",
"the",
"other",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/collection.go#L16-L18 | train |
Masterminds/semver | collection.go | Swap | func (c Collection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
} | go | func (c Collection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
} | [
"func",
"(",
"c",
"Collection",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"c",
"[",
"i",
"]",
",",
"c",
"[",
"j",
"]",
"=",
"c",
"[",
"j",
"]",
",",
"c",
"[",
"i",
"]",
"\n",
"}"
] | // Swap is needed for the sort interface to replace the Version objects
// at two different positions in the slice. | [
"Swap",
"is",
"needed",
"for",
"the",
"sort",
"interface",
"to",
"replace",
"the",
"Version",
"objects",
"at",
"two",
"different",
"positions",
"in",
"the",
"slice",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/collection.go#L22-L24 | train |
mdlayher/netlink | debug.go | newDebugger | func newDebugger(args []string) *debugger {
d := &debugger{
Log: log.New(os.Stderr, "nl: ", 0),
Level: 1,
}
for _, a := range args {
kv := strings.Split(a, "=")
if len(kv) != 2 {
// Ignore malformed pairs and assume callers wants defaults.
continue
}
switch kv[0] {
// Select the log level for... | go | func newDebugger(args []string) *debugger {
d := &debugger{
Log: log.New(os.Stderr, "nl: ", 0),
Level: 1,
}
for _, a := range args {
kv := strings.Split(a, "=")
if len(kv) != 2 {
// Ignore malformed pairs and assume callers wants defaults.
continue
}
switch kv[0] {
// Select the log level for... | [
"func",
"newDebugger",
"(",
"args",
"[",
"]",
"string",
")",
"*",
"debugger",
"{",
"d",
":=",
"&",
"debugger",
"{",
"Log",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"0",
")",
",",
"Level",
":",
"1",
",",
"}",
"\n... | // newDebugger creates a debugger by parsing key=value arguments. | [
"newDebugger",
"creates",
"a",
"debugger",
"by",
"parsing",
"key",
"=",
"value",
"arguments",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/debug.go#L31-L57 | train |
mdlayher/netlink | debug.go | debugf | func (d *debugger) debugf(level int, format string, v ...interface{}) {
if d.Level >= level {
d.Log.Printf(format, v...)
}
} | go | func (d *debugger) debugf(level int, format string, v ...interface{}) {
if d.Level >= level {
d.Log.Printf(format, v...)
}
} | [
"func",
"(",
"d",
"*",
"debugger",
")",
"debugf",
"(",
"level",
"int",
",",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"d",
".",
"Level",
">=",
"level",
"{",
"d",
".",
"Log",
".",
"Printf",
"(",
"format",
",",
"... | // debugf prints debugging information at the specified level, if d.Level is
// high enough to print the message. | [
"debugf",
"prints",
"debugging",
"information",
"at",
"the",
"specified",
"level",
"if",
"d",
".",
"Level",
"is",
"high",
"enough",
"to",
"print",
"the",
"message",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/debug.go#L61-L65 | train |
mdlayher/netlink | nlenc/int.go | PutUint8 | func PutUint8(b []byte, v uint8) {
if l := len(b); l != 1 {
panic(fmt.Sprintf("PutUint8: unexpected byte slice length: %d", l))
}
b[0] = v
} | go | func PutUint8(b []byte, v uint8) {
if l := len(b); l != 1 {
panic(fmt.Sprintf("PutUint8: unexpected byte slice length: %d", l))
}
b[0] = v
} | [
"func",
"PutUint8",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint8",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"1",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"b"... | // PutUint8 encodes a uint8 into b.
// If b is not exactly 1 byte in length, PutUint8 will panic. | [
"PutUint8",
"encodes",
"a",
"uint8",
"into",
"b",
".",
"If",
"b",
"is",
"not",
"exactly",
"1",
"byte",
"in",
"length",
"PutUint8",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L10-L16 | train |
mdlayher/netlink | nlenc/int.go | PutUint16 | func PutUint16(b []byte, v uint16) {
if l := len(b); l != 2 {
panic(fmt.Sprintf("PutUint16: unexpected byte slice length: %d", l))
}
*(*uint16)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint16(b []byte, v uint16) {
if l := len(b); l != 2 {
panic(fmt.Sprintf("PutUint16: unexpected byte slice length: %d", l))
}
*(*uint16)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint16",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint16",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"2",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint16 encodes a uint16 into b using the host machine's native endianness.
// If b is not exactly 2 bytes in length, PutUint16 will panic. | [
"PutUint16",
"encodes",
"a",
"uint16",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"2",
"bytes",
"in",
"length",
"PutUint16",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L20-L26 | train |
mdlayher/netlink | nlenc/int.go | PutUint32 | func PutUint32(b []byte, v uint32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutUint32: unexpected byte slice length: %d", l))
}
*(*uint32)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint32(b []byte, v uint32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutUint32: unexpected byte slice length: %d", l))
}
*(*uint32)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint32",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint32",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint32 encodes a uint32 into b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, PutUint32 will panic. | [
"PutUint32",
"encodes",
"a",
"uint32",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"PutUint32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L30-L36 | train |
mdlayher/netlink | nlenc/int.go | PutUint64 | func PutUint64(b []byte, v uint64) {
if l := len(b); l != 8 {
panic(fmt.Sprintf("PutUint64: unexpected byte slice length: %d", l))
}
*(*uint64)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint64(b []byte, v uint64) {
if l := len(b); l != 8 {
panic(fmt.Sprintf("PutUint64: unexpected byte slice length: %d", l))
}
*(*uint64)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint64",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint64",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"8",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint64 encodes a uint64 into b using the host machine's native endianness.
// If b is not exactly 8 bytes in length, PutUint64 will panic. | [
"PutUint64",
"encodes",
"a",
"uint64",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"8",
"bytes",
"in",
"length",
"PutUint64",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L40-L46 | train |
mdlayher/netlink | nlenc/int.go | PutInt32 | func PutInt32(b []byte, v int32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutInt32: unexpected byte slice length: %d", l))
}
*(*int32)(unsafe.Pointer(&b[0])) = v
} | go | func PutInt32(b []byte, v int32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutInt32: unexpected byte slice length: %d", l))
}
*(*int32)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutInt32",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"int32",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"*"... | // PutInt32 encodes a int32 into b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, PutInt32 will panic. | [
"PutInt32",
"encodes",
"a",
"int32",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"PutInt32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L50-L56 | train |
mdlayher/netlink | nlenc/int.go | Uint8 | func Uint8(b []byte) uint8 {
if l := len(b); l != 1 {
panic(fmt.Sprintf("Uint8: unexpected byte slice length: %d", l))
}
return b[0]
} | go | func Uint8(b []byte) uint8 {
if l := len(b); l != 1 {
panic(fmt.Sprintf("Uint8: unexpected byte slice length: %d", l))
}
return b[0]
} | [
"func",
"Uint8",
"(",
"b",
"[",
"]",
"byte",
")",
"uint8",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"1",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"b",
"... | // Uint8 decodes a uint8 from b.
// If b is not exactly 1 byte in length, Uint8 will panic. | [
"Uint8",
"decodes",
"a",
"uint8",
"from",
"b",
".",
"If",
"b",
"is",
"not",
"exactly",
"1",
"byte",
"in",
"length",
"Uint8",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L60-L66 | train |
mdlayher/netlink | nlenc/int.go | Uint16 | func Uint16(b []byte) uint16 {
if l := len(b); l != 2 {
panic(fmt.Sprintf("Uint16: unexpected byte slice length: %d", l))
}
return *(*uint16)(unsafe.Pointer(&b[0]))
} | go | func Uint16(b []byte) uint16 {
if l := len(b); l != 2 {
panic(fmt.Sprintf("Uint16: unexpected byte slice length: %d", l))
}
return *(*uint16)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint16",
"(",
"b",
"[",
"]",
"byte",
")",
"uint16",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"2",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint16 decodes a uint16 from b using the host machine's native endianness.
// If b is not exactly 2 bytes in length, Uint16 will panic. | [
"Uint16",
"decodes",
"a",
"uint16",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"2",
"bytes",
"in",
"length",
"Uint16",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L70-L76 | train |
mdlayher/netlink | nlenc/int.go | Uint32 | func Uint32(b []byte) uint32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Uint32: unexpected byte slice length: %d", l))
}
return *(*uint32)(unsafe.Pointer(&b[0]))
} | go | func Uint32(b []byte) uint32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Uint32: unexpected byte slice length: %d", l))
}
return *(*uint32)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint32",
"(",
"b",
"[",
"]",
"byte",
")",
"uint32",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint32 decodes a uint32 from b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, Uint32 will panic. | [
"Uint32",
"decodes",
"a",
"uint32",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"Uint32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L80-L86 | train |
mdlayher/netlink | nlenc/int.go | Uint64 | func Uint64(b []byte) uint64 {
if l := len(b); l != 8 {
panic(fmt.Sprintf("Uint64: unexpected byte slice length: %d", l))
}
return *(*uint64)(unsafe.Pointer(&b[0]))
} | go | func Uint64(b []byte) uint64 {
if l := len(b); l != 8 {
panic(fmt.Sprintf("Uint64: unexpected byte slice length: %d", l))
}
return *(*uint64)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint64",
"(",
"b",
"[",
"]",
"byte",
")",
"uint64",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"8",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint64 decodes a uint64 from b using the host machine's native endianness.
// If b is not exactly 8 bytes in length, Uint64 will panic. | [
"Uint64",
"decodes",
"a",
"uint64",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"8",
"bytes",
"in",
"length",
"Uint64",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L90-L96 | train |
mdlayher/netlink | nlenc/int.go | Int32 | func Int32(b []byte) int32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Int32: unexpected byte slice length: %d", l))
}
return *(*int32)(unsafe.Pointer(&b[0]))
} | go | func Int32(b []byte) int32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Int32: unexpected byte slice length: %d", l))
}
return *(*int32)(unsafe.Pointer(&b[0]))
} | [
"func",
"Int32",
"(",
"b",
"[",
"]",
"byte",
")",
"int32",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
"... | // Int32 decodes an int32 from b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, Int32 will panic. | [
"Int32",
"decodes",
"an",
"int32",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"Int32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L100-L106 | train |
mdlayher/netlink | nlenc/int.go | Uint8Bytes | func Uint8Bytes(v uint8) []byte {
b := make([]byte, 1)
PutUint8(b, v)
return b
} | go | func Uint8Bytes(v uint8) []byte {
b := make([]byte, 1)
PutUint8(b, v)
return b
} | [
"func",
"Uint8Bytes",
"(",
"v",
"uint8",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"PutUint8",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint8Bytes encodes a uint8 into a newly-allocated byte slice. It is a
// shortcut for allocating a new byte slice and filling it using PutUint8. | [
"Uint8Bytes",
"encodes",
"a",
"uint8",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"filling",
"it",
"using",
"PutUint8",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L110-L114 | train |
mdlayher/netlink | nlenc/int.go | Uint16Bytes | func Uint16Bytes(v uint16) []byte {
b := make([]byte, 2)
PutUint16(b, v)
return b
} | go | func Uint16Bytes(v uint16) []byte {
b := make([]byte, 2)
PutUint16(b, v)
return b
} | [
"func",
"Uint16Bytes",
"(",
"v",
"uint16",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",
"PutUint16",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint16Bytes encodes a uint16 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint16. | [
"Uint16Bytes",
"encodes",
"a",
"uint16",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L119-L123 | train |
mdlayher/netlink | nlenc/int.go | Uint32Bytes | func Uint32Bytes(v uint32) []byte {
b := make([]byte, 4)
PutUint32(b, v)
return b
} | go | func Uint32Bytes(v uint32) []byte {
b := make([]byte, 4)
PutUint32(b, v)
return b
} | [
"func",
"Uint32Bytes",
"(",
"v",
"uint32",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"PutUint32",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint32Bytes encodes a uint32 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint32. | [
"Uint32Bytes",
"encodes",
"a",
"uint32",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L128-L132 | train |
mdlayher/netlink | nlenc/int.go | Uint64Bytes | func Uint64Bytes(v uint64) []byte {
b := make([]byte, 8)
PutUint64(b, v)
return b
} | go | func Uint64Bytes(v uint64) []byte {
b := make([]byte, 8)
PutUint64(b, v)
return b
} | [
"func",
"Uint64Bytes",
"(",
"v",
"uint64",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"PutUint64",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint64Bytes encodes a uint64 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint64. | [
"Uint64Bytes",
"encodes",
"a",
"uint64",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L137-L141 | train |
mdlayher/netlink | nlenc/int.go | Int32Bytes | func Int32Bytes(v int32) []byte {
b := make([]byte, 4)
PutInt32(b, v)
return b
} | go | func Int32Bytes(v int32) []byte {
b := make([]byte, 4)
PutInt32(b, v)
return b
} | [
"func",
"Int32Bytes",
"(",
"v",
"int32",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"PutInt32",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Int32Bytes encodes a int32 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutInt32. | [
"Int32Bytes",
"encodes",
"a",
"int32",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fill... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L146-L150 | train |
mdlayher/netlink | nlenc/endian.go | NativeEndian | func NativeEndian() binary.ByteOrder {
// Determine endianness by storing a uint16 in a byte slice.
b := Uint16Bytes(1)
if b[0] == 1 {
return binary.LittleEndian
}
return binary.BigEndian
} | go | func NativeEndian() binary.ByteOrder {
// Determine endianness by storing a uint16 in a byte slice.
b := Uint16Bytes(1)
if b[0] == 1 {
return binary.LittleEndian
}
return binary.BigEndian
} | [
"func",
"NativeEndian",
"(",
")",
"binary",
".",
"ByteOrder",
"{",
"// Determine endianness by storing a uint16 in a byte slice.",
"b",
":=",
"Uint16Bytes",
"(",
"1",
")",
"\n",
"if",
"b",
"[",
"0",
"]",
"==",
"1",
"{",
"return",
"binary",
".",
"LittleEndian",
... | // NativeEndian returns the native byte order of this system. | [
"NativeEndian",
"returns",
"the",
"native",
"byte",
"order",
"of",
"this",
"system",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/endian.go#L6-L14 | train |
mdlayher/netlink | message.go | String | func (f HeaderFlags) String() string {
names := []string{
"request",
"multi",
"acknowledge",
"echo",
"dumpinterrupted",
"dumpfiltered",
}
var s string
left := uint(f)
for i, name := range names {
if f&(1<<uint(i)) != 0 {
if s != "" {
s += "|"
}
s += name
left ^= (1 << uint(i))
... | go | func (f HeaderFlags) String() string {
names := []string{
"request",
"multi",
"acknowledge",
"echo",
"dumpinterrupted",
"dumpfiltered",
}
var s string
left := uint(f)
for i, name := range names {
if f&(1<<uint(i)) != 0 {
if s != "" {
s += "|"
}
s += name
left ^= (1 << uint(i))
... | [
"func",
"(",
"f",
"HeaderFlags",
")",
"String",
"(",
")",
"string",
"{",
"names",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"}",
"\n\n",
"var",
"s",
... | // String returns the string representation of a HeaderFlags. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"HeaderFlags",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L77-L115 | train |
mdlayher/netlink | message.go | String | func (t HeaderType) String() string {
switch t {
case Noop:
return "noop"
case Error:
return "error"
case Done:
return "done"
case Overrun:
return "overrun"
default:
return fmt.Sprintf("unknown(%d)", t)
}
} | go | func (t HeaderType) String() string {
switch t {
case Noop:
return "noop"
case Error:
return "error"
case Done:
return "done"
case Overrun:
return "overrun"
default:
return fmt.Sprintf("unknown(%d)", t)
}
} | [
"func",
"(",
"t",
"HeaderType",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Noop",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Error",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Done",
":",
"return",
"\"",
"\"",
"\n",
"case",
... | // String returns the string representation of a HeaderType. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"HeaderType",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L136-L149 | train |
mdlayher/netlink | message.go | MarshalBinary | func (m Message) MarshalBinary() ([]byte, error) {
ml := nlmsgAlign(int(m.Header.Length))
if ml < nlmsgHeaderLen || ml != int(m.Header.Length) {
return nil, errIncorrectMessageLength
}
b := make([]byte, ml)
nlenc.PutUint32(b[0:4], m.Header.Length)
nlenc.PutUint16(b[4:6], uint16(m.Header.Type))
nlenc.PutUint1... | go | func (m Message) MarshalBinary() ([]byte, error) {
ml := nlmsgAlign(int(m.Header.Length))
if ml < nlmsgHeaderLen || ml != int(m.Header.Length) {
return nil, errIncorrectMessageLength
}
b := make([]byte, ml)
nlenc.PutUint32(b[0:4], m.Header.Length)
nlenc.PutUint16(b[4:6], uint16(m.Header.Type))
nlenc.PutUint1... | [
"func",
"(",
"m",
"Message",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ml",
":=",
"nlmsgAlign",
"(",
"int",
"(",
"m",
".",
"Header",
".",
"Length",
")",
")",
"\n",
"if",
"ml",
"<",
"nlmsgHeaderLen",
"||",
"ml... | // MarshalBinary marshals a Message into a byte slice. | [
"MarshalBinary",
"marshals",
"a",
"Message",
"into",
"a",
"byte",
"slice",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L185-L201 | train |
mdlayher/netlink | message.go | UnmarshalBinary | func (m *Message) UnmarshalBinary(b []byte) error {
if len(b) < nlmsgHeaderLen {
return errShortMessage
}
if len(b) != nlmsgAlign(len(b)) {
return errUnalignedMessage
}
// Don't allow misleading length
m.Header.Length = nlenc.Uint32(b[0:4])
if int(m.Header.Length) != len(b) {
return errShortMessage
}
m... | go | func (m *Message) UnmarshalBinary(b []byte) error {
if len(b) < nlmsgHeaderLen {
return errShortMessage
}
if len(b) != nlmsgAlign(len(b)) {
return errUnalignedMessage
}
// Don't allow misleading length
m.Header.Length = nlenc.Uint32(b[0:4])
if int(m.Header.Length) != len(b) {
return errShortMessage
}
m... | [
"func",
"(",
"m",
"*",
"Message",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"nlmsgHeaderLen",
"{",
"return",
"errShortMessage",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"nlmsgA... | // UnmarshalBinary unmarshals the contents of a byte slice into a Message. | [
"UnmarshalBinary",
"unmarshals",
"the",
"contents",
"of",
"a",
"byte",
"slice",
"into",
"a",
"Message",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L204-L225 | train |
mdlayher/netlink | message.go | checkMessage | func checkMessage(m Message) error {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
const success = 0
// Per libnl documentation, only messages that indicate type error can
// contain error codes:
... | go | func checkMessage(m Message) error {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
const success = 0
// Per libnl documentation, only messages that indicate type error can
// contain error codes:
... | [
"func",
"checkMessage",
"(",
"m",
"Message",
")",
"error",
"{",
"// NB: All non-nil errors returned from this function *must* be of type",
"// OpError in order to maintain the appropriate contract with callers of",
"// this package.",
"const",
"success",
"=",
"0",
"\n\n",
"// Per lib... | // checkMessage checks a single Message for netlink errors. | [
"checkMessage",
"checks",
"a",
"single",
"Message",
"for",
"netlink",
"errors",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L228-L260 | train |
mdlayher/netlink | attribute.go | marshal | func (a *Attribute) marshal(b []byte) (int, error) {
if int(a.Length) < nlaHeaderLen {
return 0, errInvalidAttribute
}
nlenc.PutUint16(b[0:2], a.Length)
nlenc.PutUint16(b[2:4], a.Type)
n := copy(b[nlaHeaderLen:], a.Data)
return nlaHeaderLen + nlaAlign(n), nil
} | go | func (a *Attribute) marshal(b []byte) (int, error) {
if int(a.Length) < nlaHeaderLen {
return 0, errInvalidAttribute
}
nlenc.PutUint16(b[0:2], a.Length)
nlenc.PutUint16(b[2:4], a.Type)
n := copy(b[nlaHeaderLen:], a.Data)
return nlaHeaderLen + nlaAlign(n), nil
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"marshal",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"int",
"(",
"a",
".",
"Length",
")",
"<",
"nlaHeaderLen",
"{",
"return",
"0",
",",
"errInvalidAttribute",
"\n",
"}",
"\... | // marshal marshals the contents of a into b and returns the number of bytes
// written to b, including attribute alignment padding. | [
"marshal",
"marshals",
"the",
"contents",
"of",
"a",
"into",
"b",
"and",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"b",
"including",
"attribute",
"alignment",
"padding",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L29-L39 | train |
mdlayher/netlink | attribute.go | unmarshal | func (a *Attribute) unmarshal(b []byte) error {
if len(b) < nlaHeaderLen {
return errInvalidAttribute
}
a.Length = nlenc.Uint16(b[0:2])
a.Type = nlenc.Uint16(b[2:4])
if int(a.Length) > len(b) {
return errInvalidAttribute
}
switch {
// No length, no data
case a.Length == 0:
a.Data = make([]byte, 0)
//... | go | func (a *Attribute) unmarshal(b []byte) error {
if len(b) < nlaHeaderLen {
return errInvalidAttribute
}
a.Length = nlenc.Uint16(b[0:2])
a.Type = nlenc.Uint16(b[2:4])
if int(a.Length) > len(b) {
return errInvalidAttribute
}
switch {
// No length, no data
case a.Length == 0:
a.Data = make([]byte, 0)
//... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"unmarshal",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"nlaHeaderLen",
"{",
"return",
"errInvalidAttribute",
"\n",
"}",
"\n\n",
"a",
".",
"Length",
"=",
"nlenc",
".",
"U... | // unmarshal unmarshals the contents of a byte slice into an Attribute. | [
"unmarshal",
"unmarshals",
"the",
"contents",
"of",
"a",
"byte",
"slice",
"into",
"an",
"Attribute",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L42-L68 | train |
mdlayher/netlink | attribute.go | MarshalAttributes | func MarshalAttributes(attrs []Attribute) ([]byte, error) {
// Count how many bytes we should allocate to store each attribute's contents.
var c int
for _, a := range attrs {
c += nlaHeaderLen + nlaAlign(len(a.Data))
}
// Advance through b with idx to place attribute data at the correct offset.
var idx int
b ... | go | func MarshalAttributes(attrs []Attribute) ([]byte, error) {
// Count how many bytes we should allocate to store each attribute's contents.
var c int
for _, a := range attrs {
c += nlaHeaderLen + nlaAlign(len(a.Data))
}
// Advance through b with idx to place attribute data at the correct offset.
var idx int
b ... | [
"func",
"MarshalAttributes",
"(",
"attrs",
"[",
"]",
"Attribute",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Count how many bytes we should allocate to store each attribute's contents.",
"var",
"c",
"int",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
... | // MarshalAttributes packs a slice of Attributes into a single byte slice.
// In most cases, the Length field of each Attribute should be set to 0, so it
// can be calculated and populated automatically for each Attribute. | [
"MarshalAttributes",
"packs",
"a",
"slice",
"of",
"Attributes",
"into",
"a",
"single",
"byte",
"slice",
".",
"In",
"most",
"cases",
"the",
"Length",
"field",
"of",
"each",
"Attribute",
"should",
"be",
"set",
"to",
"0",
"so",
"it",
"can",
"be",
"calculated"... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L73-L98 | train |
mdlayher/netlink | attribute.go | UnmarshalAttributes | func UnmarshalAttributes(b []byte) ([]Attribute, error) {
var attrs []Attribute
var i int
for {
if i > len(b) || len(b[i:]) == 0 {
break
}
var a Attribute
if err := (&a).unmarshal(b[i:]); err != nil {
return nil, err
}
if a.Length == 0 {
i += nlaHeaderLen
continue
}
i += nlaAlign(int(a... | go | func UnmarshalAttributes(b []byte) ([]Attribute, error) {
var attrs []Attribute
var i int
for {
if i > len(b) || len(b[i:]) == 0 {
break
}
var a Attribute
if err := (&a).unmarshal(b[i:]); err != nil {
return nil, err
}
if a.Length == 0 {
i += nlaHeaderLen
continue
}
i += nlaAlign(int(a... | [
"func",
"UnmarshalAttributes",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"Attribute",
",",
"error",
")",
"{",
"var",
"attrs",
"[",
"]",
"Attribute",
"\n",
"var",
"i",
"int",
"\n",
"for",
"{",
"if",
"i",
">",
"len",
"(",
"b",
")",
"||",
"l... | // UnmarshalAttributes unpacks a slice of Attributes from a single byte slice.
//
// It is recommend to use the AttributeDecoder type where possible instead of calling
// UnmarshalAttributes and using package nlenc functions directly. | [
"UnmarshalAttributes",
"unpacks",
"a",
"slice",
"of",
"Attributes",
"from",
"a",
"single",
"byte",
"slice",
".",
"It",
"is",
"recommend",
"to",
"use",
"the",
"AttributeDecoder",
"type",
"where",
"possible",
"instead",
"of",
"calling",
"UnmarshalAttributes",
"and",... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L104-L128 | train |
mdlayher/netlink | attribute.go | NewAttributeDecoder | func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
attrs, err := UnmarshalAttributes(b)
if err != nil {
return nil, err
}
return &AttributeDecoder{
// By default, use native byte order.
ByteOrder: nlenc.NativeEndian(),
attrs: attrs,
}, nil
} | go | func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
attrs, err := UnmarshalAttributes(b)
if err != nil {
return nil, err
}
return &AttributeDecoder{
// By default, use native byte order.
ByteOrder: nlenc.NativeEndian(),
attrs: attrs,
}, nil
} | [
"func",
"NewAttributeDecoder",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"*",
"AttributeDecoder",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"UnmarshalAttributes",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"... | // NewAttributeDecoder creates an AttributeDecoder that unpacks Attributes
// from b and prepares the decoder for iteration. | [
"NewAttributeDecoder",
"creates",
"an",
"AttributeDecoder",
"that",
"unpacks",
"Attributes",
"from",
"b",
"and",
"prepares",
"the",
"decoder",
"for",
"iteration",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L157-L169 | train |
mdlayher/netlink | attribute.go | Next | func (ad *AttributeDecoder) Next() bool {
if ad.err != nil {
// Hit an error, stop iteration.
return false
}
ad.i++
// More attributes?
return len(ad.attrs) >= ad.i
} | go | func (ad *AttributeDecoder) Next() bool {
if ad.err != nil {
// Hit an error, stop iteration.
return false
}
ad.i++
// More attributes?
return len(ad.attrs) >= ad.i
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"// Hit an error, stop iteration.",
"return",
"false",
"\n",
"}",
"\n\n",
"ad",
".",
"i",
"++",
"\n\n",
"// More attributes?",
"return... | // Next advances the decoder to the next netlink attribute. It returns false
// when no more attributes are present, or an error was encountered. | [
"Next",
"advances",
"the",
"decoder",
"to",
"the",
"next",
"netlink",
"attribute",
".",
"It",
"returns",
"false",
"when",
"no",
"more",
"attributes",
"are",
"present",
"or",
"an",
"error",
"was",
"encountered",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L173-L183 | train |
mdlayher/netlink | attribute.go | Bytes | func (ad *AttributeDecoder) Bytes() []byte {
src := ad.data()
dest := make([]byte, len(src))
copy(dest, src)
return dest
} | go | func (ad *AttributeDecoder) Bytes() []byte {
src := ad.data()
dest := make([]byte, len(src))
copy(dest, src)
return dest
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"src",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"dest",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"src",
")",
")",
"\n",
"copy",
"(",
"dest... | // Bytes returns the raw bytes of the current Attribute's data. | [
"Bytes",
"returns",
"the",
"raw",
"bytes",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L207-L212 | train |
mdlayher/netlink | attribute.go | String | func (ad *AttributeDecoder) String() string {
if ad.err != nil {
return ""
}
return nlenc.String(ad.data())
} | go | func (ad *AttributeDecoder) String() string {
if ad.err != nil {
return ""
}
return nlenc.String(ad.data())
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"nlenc",
".",
"String",
"(",
"ad",
".",
"data",
"(",
")",
")",
"\n",
... | // String returns the string representation of the current Attribute's data. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L215-L221 | train |
mdlayher/netlink | attribute.go | Uint8 | func (ad *AttributeDecoder) Uint8() uint8 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 1 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint8; length: %d", ad.Type(), len(b))
return 0
}
return uint8(b[0])
} | go | func (ad *AttributeDecoder) Uint8() uint8 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 1 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint8; length: %d", ad.Type(), len(b))
return 0
}
return uint8(b[0])
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint8",
"(",
")",
"uint8",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"1",... | // Uint8 returns the uint8 representation of the current Attribute's data. | [
"Uint8",
"returns",
"the",
"uint8",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L224-L236 | train |
mdlayher/netlink | attribute.go | Uint16 | func (ad *AttributeDecoder) Uint16() uint16 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 2 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint16; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint16(b)
} | go | func (ad *AttributeDecoder) Uint16() uint16 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 2 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint16; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint16(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint16",
"(",
")",
"uint16",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"2... | // Uint16 returns the uint16 representation of the current Attribute's data. | [
"Uint16",
"returns",
"the",
"uint16",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L239-L251 | train |
mdlayher/netlink | attribute.go | Uint32 | func (ad *AttributeDecoder) Uint32() uint32 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 4 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint32; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint32(b)
} | go | func (ad *AttributeDecoder) Uint32() uint32 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 4 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint32; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint32(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint32",
"(",
")",
"uint32",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"4... | // Uint32 returns the uint32 representation of the current Attribute's data. | [
"Uint32",
"returns",
"the",
"uint32",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L254-L266 | train |
mdlayher/netlink | attribute.go | Uint64 | func (ad *AttributeDecoder) Uint64() uint64 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 8 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint64; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint64(b)
} | go | func (ad *AttributeDecoder) Uint64() uint64 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 8 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint64; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint64(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint64",
"(",
")",
"uint64",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"8... | // Uint64 returns the uint64 representation of the current Attribute's data. | [
"Uint64",
"returns",
"the",
"uint64",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L269-L281 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.