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", "\n", "}" ]
// 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", ".", "Join", "(", "root", ",", "driver", ")", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "p", ")", ";", "err", "==", "nil", "&&", "driver", "!=", "\"", "\"", "{", "driversMap", "[", "driver", "]", "=", "true", "\n", "}", "\n", "}", "\n", "return", "driversMap", "\n", "}" ]
// 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", ".", "Open", "(", "path", ",", "os", ".", "O_RDWR", "|", "os", ".", "O_CREATE", ",", "unix", ".", "S_IRUSR", "|", "unix", ".", "S_IWUSR", ")", "\n", "}" ]
// 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", "openLock", "will", "open", "the", "path", "read", "-", "write", "and", "create", "the", "file", "if", "necessary", "." ]
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. panic("calling Unlock on unlocked lock") } l.counter-- if l.counter < 0 { // Panic when the counter is negative. There is no way we can // recover from a corrupted lock and we need to protect the // storage from corruption. panic(fmt.Sprintf("lock %q has been unlocked too often", l.file)) } if l.counter == 0 { // We should only release the lock when the counter is 0 to // avoid releasing read-locks too early; a given process may // acquire a read lock multiple times. l.locked = false for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil { time.Sleep(10 * time.Millisecond) } // Close the file descriptor on the last unlock. unix.Close(int(l.fd)) } if l.locktype == unix.F_RDLCK { l.rwMutex.RUnlock() } else { l.rwMutex.Unlock() } l.stateMutex.Unlock() }
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. panic("calling Unlock on unlocked lock") } l.counter-- if l.counter < 0 { // Panic when the counter is negative. There is no way we can // recover from a corrupted lock and we need to protect the // storage from corruption. panic(fmt.Sprintf("lock %q has been unlocked too often", l.file)) } if l.counter == 0 { // We should only release the lock when the counter is 0 to // avoid releasing read-locks too early; a given process may // acquire a read lock multiple times. l.locked = false for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil { time.Sleep(10 * time.Millisecond) } // Close the file descriptor on the last unlock. unix.Close(int(l.fd)) } if l.locktype == unix.F_RDLCK { l.rwMutex.RUnlock() } else { l.rwMutex.Unlock() } l.stateMutex.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", "(", ")", ")", ",", "}", "\n", "l", ".", "stateMutex", ".", "Lock", "(", ")", "\n", "if", "l", ".", "locked", "==", "false", "{", "// Panic when unlocking an unlocked lock. That's a violation", "// of the lock semantics and will reveal such.", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "counter", "--", "\n", "if", "l", ".", "counter", "<", "0", "{", "// Panic when the counter is negative. There is no way we can", "// recover from a corrupted lock and we need to protect the", "// storage from corruption.", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "file", ")", ")", "\n", "}", "\n", "if", "l", ".", "counter", "==", "0", "{", "// We should only release the lock when the counter is 0 to", "// avoid releasing read-locks too early; a given process may", "// acquire a read lock multiple times.", "l", ".", "locked", "=", "false", "\n", "for", "unix", ".", "FcntlFlock", "(", "l", ".", "fd", ",", "unix", ".", "F_SETLKW", ",", "&", "lk", ")", "!=", "nil", "{", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "// Close the file descriptor on the last unlock.", "unix", ".", "Close", "(", "int", "(", "l", ".", "fd", ")", ")", "\n", "}", "\n", "if", "l", ".", "locktype", "==", "unix", ".", "F_RDLCK", "{", "l", ".", "rwMutex", ".", "RUnlock", "(", ")", "\n", "}", "else", "{", "l", ".", "rwMutex", ".", "Unlock", "(", ")", "\n", "}", "\n", "l", ".", "stateMutex", ".", "Unlock", "(", ")", "\n", "}" ]
// 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", ".", "locktype", "==", "unix", ".", "F_WRLCK", ")", "\n", "}" ]
// 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 != nil { return err } n, err := unix.Write(int(l.fd), id) if err != nil { return err } if n != len(id) { return unix.ENOSPC } err = unix.Fsync(int(l.fd)) if err != nil { return err } return nil }
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 != nil { return err } n, err := unix.Write(int(l.fd), id) if err != nil { return err } if n != len(id) { return unix.ENOSPC } err = unix.Fsync(int(l.fd)) if err != nil { return err } return nil }
[ "func", "(", "l", "*", "lockfile", ")", "Touch", "(", ")", "error", "{", "l", ".", "stateMutex", ".", "Lock", "(", ")", "\n", "if", "!", "l", ".", "locked", "||", "(", "l", ".", "locktype", "!=", "unix", ".", "F_WRLCK", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "stateMutex", ".", "Unlock", "(", ")", "\n", "l", ".", "lw", "=", "stringid", ".", "GenerateRandomID", "(", ")", "\n", "id", ":=", "[", "]", "byte", "(", "l", ".", "lw", ")", "\n", "_", ",", "err", ":=", "unix", ".", "Seek", "(", "int", "(", "l", ".", "fd", ")", ",", "0", ",", "os", ".", "SEEK_SET", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "n", ",", "err", ":=", "unix", ".", "Write", "(", "int", "(", "l", ".", "fd", ")", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "n", "!=", "len", "(", "id", ")", "{", "return", "unix", ".", "ENOSPC", "\n", "}", "\n", "err", "=", "unix", ".", "Fsync", "(", "int", "(", "l", ".", "fd", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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(l.fd), id) if err != nil { return true, err } if n != len(id) { return true, nil } lw := l.lw l.lw = string(id) return l.lw != lw, nil }
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(l.fd), id) if err != nil { return true, err } if n != len(id) { return true, nil } lw := l.lw l.lw = string(id) return l.lw != lw, nil }
[ "func", "(", "l", "*", "lockfile", ")", "Modified", "(", ")", "(", "bool", ",", "error", ")", "{", "id", ":=", "[", "]", "byte", "(", "l", ".", "lw", ")", "\n", "l", ".", "stateMutex", ".", "Lock", "(", ")", "\n", "if", "!", "l", ".", "locked", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "stateMutex", ".", "Unlock", "(", ")", "\n", "_", ",", "err", ":=", "unix", ".", "Seek", "(", "int", "(", "l", ".", "fd", ")", ",", "0", ",", "os", ".", "SEEK_SET", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "n", ",", "err", ":=", "unix", ".", "Read", "(", "int", "(", "l", ".", "fd", ")", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "if", "n", "!=", "len", "(", "id", ")", "{", "return", "true", ",", "nil", "\n", "}", "\n", "lw", ":=", "l", ".", "lw", "\n", "l", ".", "lw", "=", "string", "(", "id", ")", "\n", "return", "l", ".", "lw", "!=", "lw", ",", "nil", "\n", "}" ]
// 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 { return nil, stdErr } for i := range idSpec { if i%3 != 0 { continue } cid, hid, size, err := parseTriple(idSpec[i : i+3]) if err != nil { return nil, stdErr } // Avoid possible integer overflow on 32bit builds if bits.UintSize == 32 && (cid > math.MaxInt32 || hid > math.MaxInt32 || size > math.MaxInt32) { return nil, stdErr } mapping := IDMap{ ContainerID: int(cid), HostID: int(hid), Size: int(size), } idmap = append(idmap, mapping) } } return idmap, nil }
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 { return nil, stdErr } for i := range idSpec { if i%3 != 0 { continue } cid, hid, size, err := parseTriple(idSpec[i : i+3]) if err != nil { return nil, stdErr } // Avoid possible integer overflow on 32bit builds if bits.UintSize == 32 && (cid > math.MaxInt32 || hid > math.MaxInt32 || size > math.MaxInt32) { return nil, stdErr } mapping := IDMap{ ContainerID: int(cid), HostID: int(hid), Size: int(size), } idmap = append(idmap, mapping) } } return idmap, nil }
[ "func", "ParseIDMap", "(", "mapSpec", "[", "]", "string", ",", "mapSetting", "string", ")", "(", "idmap", "[", "]", "IDMap", ",", "err", "error", ")", "{", "stdErr", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mapSetting", ")", "\n", "for", "_", ",", "idMapSpec", ":=", "range", "mapSpec", "{", "idSpec", ":=", "strings", ".", "Fields", "(", "strings", ".", "Map", "(", "nonDigitsToWhitespace", ",", "idMapSpec", ")", ")", "\n", "if", "len", "(", "idSpec", ")", "%", "3", "!=", "0", "{", "return", "nil", ",", "stdErr", "\n", "}", "\n", "for", "i", ":=", "range", "idSpec", "{", "if", "i", "%", "3", "!=", "0", "{", "continue", "\n", "}", "\n", "cid", ",", "hid", ",", "size", ",", "err", ":=", "parseTriple", "(", "idSpec", "[", "i", ":", "i", "+", "3", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "stdErr", "\n", "}", "\n", "// Avoid possible integer overflow on 32bit builds", "if", "bits", ".", "UintSize", "==", "32", "&&", "(", "cid", ">", "math", ".", "MaxInt32", "||", "hid", ">", "math", ".", "MaxInt32", "||", "size", ">", "math", ".", "MaxInt32", ")", "{", "return", "nil", ",", "stdErr", "\n", "}", "\n", "mapping", ":=", "IDMap", "{", "ContainerID", ":", "int", "(", "cid", ")", ",", "HostID", ":", "int", "(", "hid", ")", ",", "Size", ":", "int", "(", "size", ")", ",", "}", "\n", "idmap", "=", "append", "(", "idmap", ",", "mapping", ")", "\n", "}", "\n", "}", "\n", "return", "idmap", ",", "nil", "\n", "}" ]
// 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", "*", "npages", ")", "\n", "}" ]
// 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", ",", "size", ")", "}", ",", "}", "\n", "return", "&", "BufioReaderPool", "{", "pool", ":", "pool", "}", "\n", "}" ]
// 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", "(", "dst", ",", "buf", ")", "\n", "BufioReader32KPool", ".", "Put", "(", "buf", ")", "\n", "return", "\n", "}" ]
// 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.Errorf("Failed to get projid for %s: %v", targetPath, errno.Error()) } fsx.fsx_projid = C.__u32(projectID) fsx.fsx_xflags |= C.FS_XFLAG_PROJINHERIT _, _, errno = unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSSETXATTR, uintptr(unsafe.Pointer(&fsx))) if errno != 0 { return fmt.Errorf("Failed to set projid for %s: %v", targetPath, errno.Error()) } return nil }
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.Errorf("Failed to get projid for %s: %v", targetPath, errno.Error()) } fsx.fsx_projid = C.__u32(projectID) fsx.fsx_xflags |= C.FS_XFLAG_PROJINHERIT _, _, errno = unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSSETXATTR, uintptr(unsafe.Pointer(&fsx))) if errno != 0 { return fmt.Errorf("Failed to set projid for %s: %v", targetPath, errno.Error()) } return nil }
[ "func", "setProjectID", "(", "targetPath", "string", ",", "projectID", "uint32", ")", "error", "{", "dir", ",", "err", ":=", "openDir", "(", "targetPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "closeDir", "(", "dir", ")", "\n\n", "var", "fsx", "C", ".", "struct_fsxattr", "\n", "_", ",", "_", ",", "errno", ":=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_IOCTL", ",", "getDirFd", "(", "dir", ")", ",", "C", ".", "FS_IOC_FSGETXATTR", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "fsx", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "targetPath", ",", "errno", ".", "Error", "(", ")", ")", "\n", "}", "\n", "fsx", ".", "fsx_projid", "=", "C", ".", "__u32", "(", "projectID", ")", "\n", "fsx", ".", "fsx_xflags", "|=", "C", ".", "FS_XFLAG_PROJINHERIT", "\n", "_", ",", "_", ",", "errno", "=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_IOCTL", ",", "getDirFd", "(", "dir", ")", ",", "C", ".", "FS_IOC_FSSETXATTR", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "fsx", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "targetPath", ",", "errno", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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 err != nil { return err } if projid > 0 { q.quotas[path] = projid } if q.nextProjectID <= projid { q.nextProjectID = projid + 1 } } return nil }
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 err != nil { return err } if projid > 0 { q.quotas[path] = projid } if q.nextProjectID <= projid { q.nextProjectID = projid + 1 } } return nil }
[ "func", "(", "q", "*", "Control", ")", "findNextProjectID", "(", "home", "string", ")", "error", "{", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "home", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "home", ")", "\n", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "if", "!", "file", ".", "IsDir", "(", ")", "{", "continue", "\n", "}", "\n", "path", ":=", "filepath", ".", "Join", "(", "home", ",", "file", ".", "Name", "(", ")", ")", "\n", "projid", ",", "err", ":=", "getProjectID", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "projid", ">", "0", "{", "q", ".", "quotas", "[", "path", "]", "=", "projid", "\n", "}", "\n", "if", "q", ".", "nextProjectID", "<=", "projid", "{", "q", ".", "nextProjectID", "=", "projid", "+", "1", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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, opts) } if err != nil { return err } diff, err := d.Diff(template, templateIDMappings, parent, parentIDMappings, opts.MountLabel) if err != nil { if err2 := d.Remove(id); err2 != nil { logrus.Errorf("error removing layer %q: %v", id, err2) } return err } if _, err = d.ApplyDiff(id, templateIDMappings, parent, opts.MountLabel, diff); err != nil { if err2 := d.Remove(id); err2 != nil { logrus.Errorf("error removing layer %q: %v", id, err2) } return err } return nil }
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, opts) } if err != nil { return err } diff, err := d.Diff(template, templateIDMappings, parent, parentIDMappings, opts.MountLabel) if err != nil { if err2 := d.Remove(id); err2 != nil { logrus.Errorf("error removing layer %q: %v", id, err2) } return err } if _, err = d.ApplyDiff(id, templateIDMappings, parent, opts.MountLabel, diff); err != nil { if err2 := d.Remove(id); err2 != nil { logrus.Errorf("error removing layer %q: %v", id, err2) } return err } return nil }
[ "func", "NaiveCreateFromTemplate", "(", "d", "TemplateDriver", ",", "id", ",", "template", "string", ",", "templateIDMappings", "*", "idtools", ".", "IDMappings", ",", "parent", "string", ",", "parentIDMappings", "*", "idtools", ".", "IDMappings", ",", "opts", "*", "CreateOpts", ",", "readWrite", "bool", ")", "error", "{", "var", "err", "error", "\n", "if", "readWrite", "{", "err", "=", "d", ".", "CreateReadWrite", "(", "id", ",", "parent", ",", "opts", ")", "\n", "}", "else", "{", "err", "=", "d", ".", "Create", "(", "id", ",", "parent", ",", "opts", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "diff", ",", "err", ":=", "d", ".", "Diff", "(", "template", ",", "templateIDMappings", ",", "parent", ",", "parentIDMappings", ",", "opts", ".", "MountLabel", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err2", ":=", "d", ".", "Remove", "(", "id", ")", ";", "err2", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err2", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", "=", "d", ".", "ApplyDiff", "(", "id", ",", "templateIDMappings", ",", "parent", ",", "opts", ".", "MountLabel", ",", "diff", ")", ";", "err", "!=", "nil", "{", "if", "err2", ":=", "d", ".", "Remove", "(", "id", ")", ";", "err2", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err2", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "were", "actually", "a", "child", "of", "the", "child", "layer", "." ]
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", ";", "i", "<", "n", ";", "i", "++", "{", "res", "[", "i", "]", "=", "chars", "[", "rand", ".", "Intn", "(", "len", "(", "chars", ")", ")", "]", "\n", "}", "\n", "return", "string", "(", "res", ")", "\n", "}" ]
// 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", "[", ":", "maxlen", "]", ")", "\n", "}" ]
// 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", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// 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", "(", "' '", ")", "\n", "}", "\n", "quote", "(", "arg", ",", "&", "buf", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// 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", "{", "// 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", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// 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.Digest)) } digests[image.Digest] = struct{}{} validDigests = append(validDigests, image.Digest) } for name, digest := range image.BigDataDigests { if !bigDataNameIsManifest(name) { continue } if digest.Validate() != nil { return errors.Wrapf(digest.Validate(), "error validating digest %q for big data item %q", string(digest), name) } // Deduplicate the digest values. if _, known := digests[digest]; !known { digests[digest] = struct{}{} validDigests = append(validDigests, digest) } } if image.Digest == "" && len(validDigests) > 0 { image.Digest = validDigests[0] } image.Digests = validDigests return nil }
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.Digest)) } digests[image.Digest] = struct{}{} validDigests = append(validDigests, image.Digest) } for name, digest := range image.BigDataDigests { if !bigDataNameIsManifest(name) { continue } if digest.Validate() != nil { return errors.Wrapf(digest.Validate(), "error validating digest %q for big data item %q", string(digest), name) } // Deduplicate the digest values. if _, known := digests[digest]; !known { digests[digest] = struct{}{} validDigests = append(validDigests, digest) } } if image.Digest == "" && len(validDigests) > 0 { image.Digest = validDigests[0] } image.Digests = validDigests return nil }
[ "func", "(", "image", "*", "Image", ")", "recomputeDigests", "(", ")", "error", "{", "validDigests", ":=", "make", "(", "[", "]", "digest", ".", "Digest", ",", "0", ",", "len", "(", "image", ".", "BigDataDigests", ")", "+", "1", ")", "\n", "digests", ":=", "make", "(", "map", "[", "digest", ".", "Digest", "]", "struct", "{", "}", ")", "\n", "if", "image", ".", "Digest", "!=", "\"", "\"", "{", "if", "err", ":=", "image", ".", "Digest", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "string", "(", "image", ".", "Digest", ")", ")", "\n", "}", "\n", "digests", "[", "image", ".", "Digest", "]", "=", "struct", "{", "}", "{", "}", "\n", "validDigests", "=", "append", "(", "validDigests", ",", "image", ".", "Digest", ")", "\n", "}", "\n", "for", "name", ",", "digest", ":=", "range", "image", ".", "BigDataDigests", "{", "if", "!", "bigDataNameIsManifest", "(", "name", ")", "{", "continue", "\n", "}", "\n", "if", "digest", ".", "Validate", "(", ")", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "digest", ".", "Validate", "(", ")", ",", "\"", "\"", ",", "string", "(", "digest", ")", ",", "name", ")", "\n", "}", "\n", "// Deduplicate the digest values.", "if", "_", ",", "known", ":=", "digests", "[", "digest", "]", ";", "!", "known", "{", "digests", "[", "digest", "]", "=", "struct", "{", "}", "{", "}", "\n", "validDigests", "=", "append", "(", "validDigests", ",", "digest", ")", "\n", "}", "\n", "}", "\n", "if", "image", ".", "Digest", "==", "\"", "\"", "&&", "len", "(", "validDigests", ")", ">", "0", "{", "image", ".", "Digest", "=", "validDigests", "[", "0", "]", "\n", "}", "\n", "image", ".", "Digests", "=", "validDigests", "\n", "return", "nil", "\n", "}" ]
// 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 mount options") } else { return nil, fmt.Errorf("option %s not supported", option) } } fsType, err := getFileSystemType(string(home[0])) if err != nil { return nil, err } if strings.ToLower(fsType) == "refs" { return nil, fmt.Errorf("%s is on an ReFS volume - ReFS volumes are not supported", home) } if err := idtools.MkdirAllAs(home, 0700, 0, 0); err != nil { return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err) } d := &Driver{ info: hcsshim.DriverInfo{ HomeDir: home, Flavour: filterDriver, }, cache: make(map[string]string), ctr: graphdriver.NewRefCounter(&checker{}), } return d, nil }
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 mount options") } else { return nil, fmt.Errorf("option %s not supported", option) } } fsType, err := getFileSystemType(string(home[0])) if err != nil { return nil, err } if strings.ToLower(fsType) == "refs" { return nil, fmt.Errorf("%s is on an ReFS volume - ReFS volumes are not supported", home) } if err := idtools.MkdirAllAs(home, 0700, 0, 0); err != nil { return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err) } d := &Driver{ info: hcsshim.DriverInfo{ HomeDir: home, Flavour: filterDriver, }, cache: make(map[string]string), ctr: graphdriver.NewRefCounter(&checker{}), } return d, nil }
[ "func", "InitFilter", "(", "home", "string", ",", "options", "[", "]", "string", ",", "uidMaps", ",", "gidMaps", "[", "]", "idtools", ".", "IDMap", ")", "(", "graphdriver", ".", "Driver", ",", "error", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "home", ")", "\n\n", "for", "_", ",", "option", ":=", "range", "options", "{", "if", "strings", ".", "HasPrefix", "(", "option", ",", "\"", "\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "else", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "option", ")", "\n", "}", "\n", "}", "\n\n", "fsType", ",", "err", ":=", "getFileSystemType", "(", "string", "(", "home", "[", "0", "]", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "strings", ".", "ToLower", "(", "fsType", ")", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "home", ")", "\n", "}", "\n\n", "if", "err", ":=", "idtools", ".", "MkdirAllAs", "(", "home", ",", "0700", ",", "0", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "home", ",", "err", ")", "\n", "}", "\n\n", "d", ":=", "&", "Driver", "{", "info", ":", "hcsshim", ".", "DriverInfo", "{", "HomeDir", ":", "home", ",", "Flavour", ":", "filterDriver", ",", "}", ",", "cache", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "ctr", ":", "graphdriver", ".", "NewRefCounter", "(", "&", "checker", "{", "}", ")", ",", "}", "\n", "return", "d", ",", "nil", "\n", "}" ]
// 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.Unlock() // If the cache was not populated, then the layer was left unprepared and deactivated if !exists { return nil } if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { return err } return hcsshim.DeactivateLayer(d.info, rID) }
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.Unlock() // If the cache was not populated, then the layer was left unprepared and deactivated if !exists { return nil } if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { return err } return hcsshim.DeactivateLayer(d.info, rID) }
[ "func", "(", "d", "*", "Driver", ")", "Put", "(", "id", "string", ")", "error", "{", "panicIfUsedByLcow", "(", ")", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "id", ")", "\n\n", "rID", ",", "err", ":=", "d", ".", "resolveID", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "count", ":=", "d", ".", "ctr", ".", "Decrement", "(", "rID", ")", ";", "count", ">", "0", "{", "return", "nil", "\n", "}", "\n", "d", ".", "cacheMu", ".", "Lock", "(", ")", "\n", "_", ",", "exists", ":=", "d", ".", "cache", "[", "rID", "]", "\n", "delete", "(", "d", ".", "cache", ",", "rID", ")", "\n", "d", ".", "cacheMu", ".", "Unlock", "(", ")", "\n\n", "// If the cache was not populated, then the layer was left unprepared and deactivated", "if", "!", "exists", "{", "return", "nil", "\n", "}", "\n\n", "if", "err", ":=", "hcsshim", ".", "UnprepareLayer", "(", "d", ".", "info", ",", "rID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "hcsshim", ".", "DeactivateLayer", "(", "d", ".", "info", ",", "rID", ")", "\n", "}" ]
// 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 } // this is assuming that the layer is unmounted if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { return nil, err } prepare := func() { if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil { logrus.Warnf("Failed to Deactivate %s: %s", rID, err) } } arch, err := d.exportLayer(rID, layerChain) if err != nil { prepare() return } return ioutils.NewReadCloserWrapper(arch, func() error { err := arch.Close() prepare() return err }), nil }
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 } // this is assuming that the layer is unmounted if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { return nil, err } prepare := func() { if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil { logrus.Warnf("Failed to Deactivate %s: %s", rID, err) } } arch, err := d.exportLayer(rID, layerChain) if err != nil { prepare() return } return ioutils.NewReadCloserWrapper(arch, func() error { err := arch.Close() prepare() return err }), nil }
[ "func", "(", "d", "*", "Driver", ")", "Diff", "(", "id", "string", ",", "idMappings", "*", "idtools", ".", "IDMappings", ",", "parent", "string", ",", "parentMappings", "*", "idtools", ".", "IDMappings", ",", "mountLabel", "string", ")", "(", "_", "io", ".", "ReadCloser", ",", "err", "error", ")", "{", "panicIfUsedByLcow", "(", ")", "\n", "rID", ",", "err", ":=", "d", ".", "resolveID", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "layerChain", ",", "err", ":=", "d", ".", "getLayerChain", "(", "rID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// this is assuming that the layer is unmounted", "if", "err", ":=", "hcsshim", ".", "UnprepareLayer", "(", "d", ".", "info", ",", "rID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "prepare", ":=", "func", "(", ")", "{", "if", "err", ":=", "hcsshim", ".", "PrepareLayer", "(", "d", ".", "info", ",", "rID", ",", "layerChain", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "rID", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "arch", ",", "err", ":=", "d", ".", "exportLayer", "(", "rID", ",", "layerChain", ")", "\n", "if", "err", "!=", "nil", "{", "prepare", "(", ")", "\n", "return", "\n", "}", "\n", "return", "ioutils", ".", "NewReadCloserWrapper", "(", "arch", ",", "func", "(", ")", "error", "{", "err", ":=", "arch", ".", "Close", "(", ")", "\n", "prepare", "(", ")", "\n", "return", "err", "\n", "}", ")", ",", "nil", "\n", "}" ]
// 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 err != nil { return 0, err } parentPath, err := hcsshim.GetLayerMountPath(d.info, rPId) if err != nil { return 0, err } layerChain = append(layerChain, parentPath) layerChain = append(layerChain, parentChain...) } size, err := d.importLayer(id, diff, layerChain) if err != nil { return 0, err } if err = d.setLayerChain(id, layerChain); err != nil { return 0, err } return size, nil }
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 err != nil { return 0, err } parentPath, err := hcsshim.GetLayerMountPath(d.info, rPId) if err != nil { return 0, err } layerChain = append(layerChain, parentPath) layerChain = append(layerChain, parentChain...) } size, err := d.importLayer(id, diff, layerChain) if err != nil { return 0, err } if err = d.setLayerChain(id, layerChain); err != nil { return 0, err } return size, nil }
[ "func", "(", "d", "*", "Driver", ")", "ApplyDiff", "(", "id", "string", ",", "idMappings", "*", "idtools", ".", "IDMappings", ",", "parent", ",", "mountLabel", "string", ",", "diff", "io", ".", "Reader", ")", "(", "int64", ",", "error", ")", "{", "panicIfUsedByLcow", "(", ")", "\n", "var", "layerChain", "[", "]", "string", "\n", "if", "parent", "!=", "\"", "\"", "{", "rPId", ",", "err", ":=", "d", ".", "resolveID", "(", "parent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "parentChain", ",", "err", ":=", "d", ".", "getLayerChain", "(", "rPId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "parentPath", ",", "err", ":=", "hcsshim", ".", "GetLayerMountPath", "(", "d", ".", "info", ",", "rPId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "layerChain", "=", "append", "(", "layerChain", ",", "parentPath", ")", "\n", "layerChain", "=", "append", "(", "layerChain", ",", "parentChain", "...", ")", "\n", "}", "\n\n", "size", ",", "err", ":=", "d", ".", "importLayer", "(", "id", ",", "diff", ",", "layerChain", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "d", ".", "setLayerChain", "(", "id", ",", "layerChain", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "size", ",", "nil", "\n", "}" ]
// 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", "not", "be", "mounted", "when", "calling", "this", "function" ]
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", ")", "\n", "m", "[", "\"", "\"", "]", "=", "d", ".", "dir", "(", "id", ")", "\n", "return", "m", ",", "nil", "\n", "}" ]
// 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", "(", "\"", "\"", ")", "\n", "}" ]
// 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 } logrus.Debugf("devmapper: Found deleted device %s.", info.Hash) deletedDevices = append(deletedDevices, info) } // Delete the deleted devices. DeleteDevice() first takes the info lock // and then devices.Lock(). So drop it to avoid deadlock. devices.Unlock() for _, info := range deletedDevices { // This will again try deferred deletion. if err := devices.DeleteDevice(info.Hash, false); err != nil { logrus.Warnf("devmapper: Deletion of device %s, device_id=%v failed:%v", info.Hash, info.DeviceID, err) } } return nil }
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 } logrus.Debugf("devmapper: Found deleted device %s.", info.Hash) deletedDevices = append(deletedDevices, info) } // Delete the deleted devices. DeleteDevice() first takes the info lock // and then devices.Lock(). So drop it to avoid deadlock. devices.Unlock() for _, info := range deletedDevices { // This will again try deferred deletion. if err := devices.DeleteDevice(info.Hash, false); err != nil { logrus.Warnf("devmapper: Deletion of device %s, device_id=%v failed:%v", info.Hash, info.DeviceID, err) } } return nil }
[ "func", "(", "devices", "*", "DeviceSet", ")", "cleanupDeletedDevices", "(", ")", "error", "{", "devices", ".", "Lock", "(", ")", "\n\n", "// If there are no deleted devices, there is nothing to do.", "if", "devices", ".", "nrDeletedDevices", "==", "0", "{", "devices", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n\n", "var", "deletedDevices", "[", "]", "*", "devInfo", "\n\n", "for", "_", ",", "info", ":=", "range", "devices", ".", "Devices", "{", "if", "!", "info", ".", "Deleted", "{", "continue", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "info", ".", "Hash", ")", "\n", "deletedDevices", "=", "append", "(", "deletedDevices", ",", "info", ")", "\n", "}", "\n\n", "// Delete the deleted devices. DeleteDevice() first takes the info lock", "// and then devices.Lock(). So drop it to avoid deadlock.", "devices", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "info", ":=", "range", "deletedDevices", "{", "// This will again try deferred deletion.", "if", "err", ":=", "devices", ".", "DeleteDevice", "(", "info", ".", "Hash", ",", "false", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "info", ".", "Hash", ",", "info", ".", "DeviceID", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", thinPoolDevice, err) } // Device does not exist. if info.Exists == 0 { return false, nil } _, _, deviceType, _, err := devicemapper.GetStatus(thinPoolDevice) if err != nil { return false, fmt.Errorf("devmapper: GetStatus() on device %s failed: %v", thinPoolDevice, err) } if deviceType != "thin-pool" { return false, fmt.Errorf("devmapper: Device %s is not a thin pool", thinPoolDevice) } return true, nil }
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", thinPoolDevice, err) } // Device does not exist. if info.Exists == 0 { return false, nil } _, _, deviceType, _, err := devicemapper.GetStatus(thinPoolDevice) if err != nil { return false, fmt.Errorf("devmapper: GetStatus() on device %s failed: %v", thinPoolDevice, err) } if deviceType != "thin-pool" { return false, fmt.Errorf("devmapper: Device %s is not a thin pool", thinPoolDevice) } return true, nil }
[ "func", "(", "devices", "*", "DeviceSet", ")", "thinPoolExists", "(", "thinPoolDevice", "string", ")", "(", "bool", ",", "error", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "thinPoolDevice", ")", "\n\n", "info", ",", "err", ":=", "devicemapper", ".", "GetInfo", "(", "thinPoolDevice", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "thinPoolDevice", ",", "err", ")", "\n", "}", "\n\n", "// Device does not exist.", "if", "info", ".", "Exists", "==", "0", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "_", ",", "_", ",", "deviceType", ",", "_", ",", "err", ":=", "devicemapper", ".", "GetStatus", "(", "thinPoolDevice", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "thinPoolDevice", ",", "err", ")", "\n", "}", "\n\n", "if", "deviceType", "!=", "\"", "\"", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "thinPoolDevice", ")", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// 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, minorNum) return majorNum, minorNum, nil }
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, minorNum) return majorNum, minorNum, nil }
[ "func", "getDeviceMajorMinor", "(", "file", "*", "os", ".", "File", ")", "(", "uint64", ",", "uint64", ",", "error", ")", "{", "var", "stat", "unix", ".", "Stat_t", "\n", "err", ":=", "unix", ".", "Stat", "(", "file", ".", "Name", "(", ")", ",", "&", "stat", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "0", ",", "err", "\n", "}", "\n\n", "dev", ":=", "stat", ".", "Rdev", "\n", "majorNum", ":=", "major", "(", "dev", ")", "\n", "minorNum", ":=", "minor", "(", "dev", ")", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "file", ".", "Name", "(", ")", ",", "majorNum", ",", "minorNum", ")", "\n", "return", "majorNum", ",", "minorNum", ",", "nil", "\n", "}" ]
// 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 device, so we do it // manually. // Even if device is deferred deleted, activate it and issue // discards. if err := devices.activateDeviceIfNeeded(info, true); err != nil { return err } devinfo, err := devicemapper.GetInfo(info.Name()) if err != nil { return err } if devinfo.OpenCount != 0 { logrus.Debugf("devmapper: Device: %s is in use. OpenCount=%d. Not issuing discards.", info.Hash, devinfo.OpenCount) return nil } if err := devicemapper.BlockDeviceDiscard(info.DevName()); err != nil { logrus.Debugf("devmapper: Error discarding block on device: %s (ignoring)", err) } return nil }
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 device, so we do it // manually. // Even if device is deferred deleted, activate it and issue // discards. if err := devices.activateDeviceIfNeeded(info, true); err != nil { return err } devinfo, err := devicemapper.GetInfo(info.Name()) if err != nil { return err } if devinfo.OpenCount != 0 { logrus.Debugf("devmapper: Device: %s is in use. OpenCount=%d. Not issuing discards.", info.Hash, devinfo.OpenCount) return nil } if err := devicemapper.BlockDeviceDiscard(info.DevName()); err != nil { logrus.Debugf("devmapper: Error discarding block on device: %s (ignoring)", err) } return nil }
[ "func", "(", "devices", "*", "DeviceSet", ")", "issueDiscard", "(", "info", "*", "devInfo", ")", "error", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "info", ".", "Hash", ")", "\n", "defer", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "info", ".", "Hash", ")", "\n", "// This is a workaround for the kernel not discarding block so", "// on the thin pool when we remove a thinp device, so we do it", "// manually.", "// Even if device is deferred deleted, activate it and issue", "// discards.", "if", "err", ":=", "devices", ".", "activateDeviceIfNeeded", "(", "info", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "devinfo", ",", "err", ":=", "devicemapper", ".", "GetInfo", "(", "info", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "devinfo", ".", "OpenCount", "!=", "0", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "info", ".", "Hash", ",", "devinfo", ".", "OpenCount", ")", "\n", "return", "nil", "\n", "}", "\n\n", "if", "err", ":=", "devicemapper", ".", "BlockDeviceDiscard", "(", "info", ".", "DevName", "(", ")", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "(", ")", ")", ")", "\n", "}" ]
// 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 != nil { return nil, err } driverPrefix := s.graphDriverName + "-" rlpath := filepath.Join(s.runRoot, driverPrefix+"layers") if err := os.MkdirAll(rlpath, 0700); err != nil { return nil, err } glpath := filepath.Join(s.graphRoot, driverPrefix+"layers") if err := os.MkdirAll(glpath, 0700); err != nil { return nil, err } rls, err := newLayerStore(rlpath, glpath, driver, s.uidMap, s.gidMap) if err != nil { return nil, err } s.layerStore = rls return s.layerStore, nil }
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 != nil { return nil, err } driverPrefix := s.graphDriverName + "-" rlpath := filepath.Join(s.runRoot, driverPrefix+"layers") if err := os.MkdirAll(rlpath, 0700); err != nil { return nil, err } glpath := filepath.Join(s.graphRoot, driverPrefix+"layers") if err := os.MkdirAll(glpath, 0700); err != nil { return nil, err } rls, err := newLayerStore(rlpath, glpath, driver, s.uidMap, s.gidMap) if err != nil { return nil, err } s.layerStore = rls return s.layerStore, nil }
[ "func", "(", "s", "*", "store", ")", "LayerStore", "(", ")", "(", "LayerStore", ",", "error", ")", "{", "s", ".", "graphLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "graphLock", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "graphLock", ".", "TouchedSince", "(", "s", ".", "lastLoaded", ")", "{", "s", ".", "graphDriver", "=", "nil", "\n", "s", ".", "layerStore", "=", "nil", "\n", "s", ".", "lastLoaded", "=", "time", ".", "Now", "(", ")", "\n", "}", "\n", "if", "s", ".", "layerStore", "!=", "nil", "{", "return", "s", ".", "layerStore", ",", "nil", "\n", "}", "\n", "driver", ",", "err", ":=", "s", ".", "getGraphDriver", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "driverPrefix", ":=", "s", ".", "graphDriverName", "+", "\"", "\"", "\n", "rlpath", ":=", "filepath", ".", "Join", "(", "s", ".", "runRoot", ",", "driverPrefix", "+", "\"", "\"", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "rlpath", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "glpath", ":=", "filepath", ".", "Join", "(", "s", ".", "graphRoot", ",", "driverPrefix", "+", "\"", "\"", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "glpath", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rls", ",", "err", ":=", "newLayerStore", "(", "rlpath", ",", "glpath", ",", "driver", ",", "s", ".", "uidMap", ",", "s", ".", "gidMap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ".", "layerStore", "=", "rls", "\n", "return", "s", ".", "layerStore", ",", "nil", "\n", "}" ]
// 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", "not", "a", "part", "of", "the", "exported", "Store", "interface", "." ]
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", ",", "ErrLoadError", "\n", "}" ]
// 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", "not", "a", "part", "of", "the", "exported", "Store", "interface", "." ]
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", ",", "ErrLoadError", "\n", "}" ]
// 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", "not", "a", "part", "of", "the", "exported", "Store", "interface", "." ]
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.StdEncoding.EncodeToString([]byte(key)) } return key }
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.StdEncoding.EncodeToString([]byte(key)) } return key }
[ "func", "makeBigDataBaseName", "(", "key", "string", ")", "string", "{", "reader", ":=", "strings", ".", "NewReader", "(", "key", ")", "\n", "for", "reader", ".", "Len", "(", ")", ">", "0", "{", "ch", ",", "size", ",", "err", ":=", "reader", ".", "ReadRune", "(", ")", "\n", "if", "err", "!=", "nil", "||", "size", "!=", "1", "{", "break", "\n", "}", "\n", "if", "ch", "!=", "'.'", "&&", "!", "(", "ch", ">=", "'0'", "&&", "ch", "<=", "'9'", ")", "&&", "!", "(", "ch", ">=", "'a'", "&&", "ch", "<=", "'z'", ")", "{", "break", "\n", "}", "\n", "}", "\n", "if", "reader", ".", "Len", "(", ")", ">", "0", "{", "return", "\"", "\"", "+", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "key", ")", ")", "\n", "}", "\n", "return", "key", "\n", "}" ]
// 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", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "filepath", ".", "Join", "(", "home", ",", "\"", "\"", ")", ",", "nil", "\n", "}", "\n", "return", "defaultConfigFile", ",", "nil", "\n", "}" ]
// 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: make(map[string]*FileInfo), parent: parent, idMappings: root.idMappings, } cpath := filepath.Join(dir, path) stat, err := system.FromStatT(fi.Sys().(*syscall.Stat_t)) if err != nil { return err } info.stat = stat info.capability, _ = system.Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access parent.children[info.name] = info return nil }
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: make(map[string]*FileInfo), parent: parent, idMappings: root.idMappings, } cpath := filepath.Join(dir, path) stat, err := system.FromStatT(fi.Sys().(*syscall.Stat_t)) if err != nil { return err } info.stat = stat info.capability, _ = system.Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access parent.children[info.name] = info return nil }
[ "func", "walkchunk", "(", "path", "string", ",", "fi", "os", ".", "FileInfo", ",", "dir", "string", ",", "root", "*", "FileInfo", ")", "error", "{", "if", "fi", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "parent", ":=", "root", ".", "LookUp", "(", "filepath", ".", "Dir", "(", "path", ")", ")", "\n", "if", "parent", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "info", ":=", "&", "FileInfo", "{", "name", ":", "filepath", ".", "Base", "(", "path", ")", ",", "children", ":", "make", "(", "map", "[", "string", "]", "*", "FileInfo", ")", ",", "parent", ":", "parent", ",", "idMappings", ":", "root", ".", "idMappings", ",", "}", "\n", "cpath", ":=", "filepath", ".", "Join", "(", "dir", ",", "path", ")", "\n", "stat", ",", "err", ":=", "system", ".", "FromStatT", "(", "fi", ".", "Sys", "(", ")", ".", "(", "*", "syscall", ".", "Stat_t", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "info", ".", "stat", "=", "stat", "\n", "info", ".", "capability", ",", "_", "=", "system", ".", "Lgetxattr", "(", "cpath", ",", "\"", "\"", ")", "// lgetxattr(2): fs access", "\n", "parent", ".", "children", "[", "info", ".", "name", "]", "=", "info", "\n", "return", "nil", "\n", "}" ]
// 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", "size", "in", "bytes", "of", "the", "contents", "of", "the", "layer", "." ]
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 decompress { layer, err = DecompressStream(layer) if err != nil { return 0, err } } return UnpackLayer(dest, layer, options) }
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 decompress { layer, err = DecompressStream(layer) if err != nil { return 0, err } } return UnpackLayer(dest, layer, options) }
[ "func", "applyLayerHandler", "(", "dest", "string", ",", "layer", "io", ".", "Reader", ",", "options", "*", "TarOptions", ",", "decompress", "bool", ")", "(", "int64", ",", "error", ")", "{", "dest", "=", "filepath", ".", "Clean", "(", "dest", ")", "\n\n", "// We need to be able to set any perms", "oldmask", ",", "err", ":=", "system", ".", "Umask", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "defer", "system", ".", "Umask", "(", "oldmask", ")", "// ignore err, ErrNotSupportedPlatform", "\n\n", "if", "decompress", "{", "layer", ",", "err", "=", "DecompressStream", "(", "layer", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "}", "\n", "return", "UnpackLayer", "(", "dest", ",", "layer", ",", "options", ")", "\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()}) if err != nil { return err } cmd := reexec.Command(chownByMapsCmd, path) cmd.Stdin = bytes.NewReader(config) output, err := cmd.CombinedOutput() if len(output) > 0 && err != nil { return fmt.Errorf("%v: %s", err, string(output)) } if err != nil { return err } if len(output) > 0 { return fmt.Errorf("%s", string(output)) } return nil }
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()}) if err != nil { return err } cmd := reexec.Command(chownByMapsCmd, path) cmd.Stdin = bytes.NewReader(config) output, err := cmd.CombinedOutput() if len(output) > 0 && err != nil { return fmt.Errorf("%v: %s", err, string(output)) } if err != nil { return err } if len(output) > 0 { return fmt.Errorf("%s", string(output)) } return nil }
[ "func", "ChownPathByMaps", "(", "path", "string", ",", "toContainer", ",", "toHost", "*", "idtools", ".", "IDMappings", ")", "error", "{", "if", "toContainer", "==", "nil", "{", "toContainer", "=", "&", "idtools", ".", "IDMappings", "{", "}", "\n", "}", "\n", "if", "toHost", "==", "nil", "{", "toHost", "=", "&", "idtools", ".", "IDMappings", "{", "}", "\n", "}", "\n\n", "config", ",", "err", ":=", "json", ".", "Marshal", "(", "[", "4", "]", "[", "]", "idtools", ".", "IDMap", "{", "toContainer", ".", "UIDs", "(", ")", ",", "toContainer", ".", "GIDs", "(", ")", ",", "toHost", ".", "UIDs", "(", ")", ",", "toHost", ".", "GIDs", "(", ")", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "cmd", ":=", "reexec", ".", "Command", "(", "chownByMapsCmd", ",", "path", ")", "\n", "cmd", ".", "Stdin", "=", "bytes", ".", "NewReader", "(", "config", ")", "\n", "output", ",", "err", ":=", "cmd", ".", "CombinedOutput", "(", ")", "\n", "if", "len", "(", "output", ")", ">", "0", "&&", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "string", "(", "output", ")", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "output", ")", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "output", ")", ")", "\n", "}", "\n\n", "return", "nil", "\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 "container" IDs.
[ "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", "container", "IDs", "." ]
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) }() return ChownPathByMaps(layerFs, toContainer, toHost) }
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) }() return ChownPathByMaps(layerFs, toContainer, toHost) }
[ "func", "(", "n", "*", "naiveLayerIDMapUpdater", ")", "UpdateLayerIDMap", "(", "id", "string", ",", "toContainer", ",", "toHost", "*", "idtools", ".", "IDMappings", ",", "mountLabel", "string", ")", "error", "{", "driver", ":=", "n", ".", "ProtoDriver", "\n", "options", ":=", "MountOpts", "{", "MountLabel", ":", "mountLabel", ",", "}", "\n", "layerFs", ",", "err", ":=", "driver", ".", "Get", "(", "id", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "driver", ".", "Put", "(", "id", ")", "\n", "}", "(", ")", "\n\n", "return", "ChownPathByMaps", "(", "layerFs", ",", "toContainer", ",", "toHost", ")", "\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 // same "container" IDs.
[ "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", "same", "container", "IDs", "." ]
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] != 102) || (buf.f_basetype[2] != 115) || (buf.f_basetype[3] != 0) { logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath) return false, ErrPrerequisites } return true, nil }
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] != 102) || (buf.f_basetype[2] != 115) || (buf.f_basetype[3] != 0) { logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath) return false, ErrPrerequisites } return true, nil }
[ "func", "Mounted", "(", "fsType", "FsMagic", ",", "mountPath", "string", ")", "(", "bool", ",", "error", ")", "{", "cs", ":=", "C", ".", "CString", "(", "filepath", ".", "Dir", "(", "mountPath", ")", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cs", ")", ")", "\n", "buf", ":=", "C", ".", "getstatfs", "(", "cs", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "buf", ")", ")", "\n\n", "// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]", "if", "(", "buf", ".", "f_basetype", "[", "0", "]", "!=", "122", ")", "||", "(", "buf", ".", "f_basetype", "[", "1", "]", "!=", "102", ")", "||", "(", "buf", ".", "f_basetype", "[", "2", "]", "!=", "115", ")", "||", "(", "buf", ".", "f_basetype", "[", "3", "]", "!=", "0", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "mountPath", ")", "\n", "return", "false", ",", "ErrPrerequisites", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// 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", ")", ",", "&", "st", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", "\n", "}", "\n", "touched", ":=", "time", ".", "Unix", "(", "st", ".", "Mtim", ".", "Unix", "(", ")", ")", "\n", "return", "when", ".", "Before", "(", "touched", ")", "\n", "}" ]
// 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", "{", "}", "}", "\n", "}" ]
// 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", "{", "Untar", ":", "Untar", ",", "TarIDMappings", ":", "idMappings", ",", "UntarIDMappings", ":", "idMappings", "}", "\n", "}" ]
// 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, TarIDMappings: tarIDMappings, ChownOpts: chownOpts, UntarIDMappings: untarIDMappings} }
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, TarIDMappings: tarIDMappings, ChownOpts: chownOpts, UntarIDMappings: untarIDMappings} }
[ "func", "NewArchiverWithChown", "(", "tarIDMappings", "*", "idtools", ".", "IDMappings", ",", "chownOpts", "*", "idtools", ".", "IDPair", ",", "untarIDMappings", "*", "idtools", ".", "IDMappings", ")", "*", "Archiver", "{", "if", "tarIDMappings", "==", "nil", "{", "tarIDMappings", "=", "&", "idtools", ".", "IDMappings", "{", "}", "\n", "}", "\n", "if", "untarIDMappings", "==", "nil", "{", "untarIDMappings", "=", "&", "idtools", ".", "IDMappings", "{", "}", "\n", "}", "\n", "return", "&", "Archiver", "{", "Untar", ":", "Untar", ",", "TarIDMappings", ":", "tarIDMappings", ",", "ChownOpts", ":", "chownOpts", ",", "UntarIDMappings", ":", "untarIDMappings", "}", "\n", "}" ]
// 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.UIDs(), GIDMaps: tarMappings.GIDs(), }) } }
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.UIDs(), GIDMaps: tarMappings.GIDs(), }) } }
[ "func", "TarPath", "(", "uidmap", "[", "]", "idtools", ".", "IDMap", ",", "gidmap", "[", "]", "idtools", ".", "IDMap", ")", "func", "(", "path", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "tarMappings", ":=", "idtools", ".", "NewIDMappingsFromMaps", "(", "uidmap", ",", "gidmap", ")", "\n", "return", "func", "(", "path", "string", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "TarWithOptions", "(", "path", ",", "&", "TarOptions", "{", "Compression", ":", "Uncompressed", ",", "UIDMaps", ":", "tarMappings", ".", "UIDs", "(", ")", ",", "GIDMaps", ":", "tarMappings", ".", "GIDs", "(", ")", ",", "}", ")", "\n", "}", "\n", "}" ]
// 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 parsing version segment: %s", err) } sv.major = temp if m[2] != "" { temp, err = strconv.ParseInt(strings.TrimPrefix(m[2], "."), 10, 64) if err != nil { return nil, fmt.Errorf("Error parsing version segment: %s", err) } sv.minor = temp } else { sv.minor = 0 } if m[3] != "" { temp, err = strconv.ParseInt(strings.TrimPrefix(m[3], "."), 10, 64) if err != nil { return nil, fmt.Errorf("Error parsing version segment: %s", err) } sv.patch = temp } else { sv.patch = 0 } return sv, nil }
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 parsing version segment: %s", err) } sv.major = temp if m[2] != "" { temp, err = strconv.ParseInt(strings.TrimPrefix(m[2], "."), 10, 64) if err != nil { return nil, fmt.Errorf("Error parsing version segment: %s", err) } sv.minor = temp } else { sv.minor = 0 } if m[3] != "" { temp, err = strconv.ParseInt(strings.TrimPrefix(m[3], "."), 10, 64) if err != nil { return nil, fmt.Errorf("Error parsing version segment: %s", err) } sv.patch = temp } else { sv.patch = 0 } return sv, nil }
[ "func", "NewVersion", "(", "v", "string", ")", "(", "*", "Version", ",", "error", ")", "{", "m", ":=", "versionRegex", ".", "FindStringSubmatch", "(", "v", ")", "\n", "if", "m", "==", "nil", "{", "return", "nil", ",", "ErrInvalidSemVer", "\n", "}", "\n\n", "sv", ":=", "&", "Version", "{", "metadata", ":", "m", "[", "8", "]", ",", "pre", ":", "m", "[", "5", "]", ",", "original", ":", "v", ",", "}", "\n\n", "var", "temp", "int64", "\n", "temp", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "m", "[", "1", "]", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "sv", ".", "major", "=", "temp", "\n\n", "if", "m", "[", "2", "]", "!=", "\"", "\"", "{", "temp", ",", "err", "=", "strconv", ".", "ParseInt", "(", "strings", ".", "TrimPrefix", "(", "m", "[", "2", "]", ",", "\"", "\"", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "sv", ".", "minor", "=", "temp", "\n", "}", "else", "{", "sv", ".", "minor", "=", "0", "\n", "}", "\n\n", "if", "m", "[", "3", "]", "!=", "\"", "\"", "{", "temp", ",", "err", "=", "strconv", ".", "ParseInt", "(", "strings", ".", "TrimPrefix", "(", "m", "[", "3", "]", ",", "\"", "\"", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "sv", ".", "patch", "=", "temp", "\n", "}", "else", "{", "sv", ".", "patch", "=", "0", "\n", "}", "\n\n", "return", "sv", ",", "nil", "\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", "]", "==", "\"", "\"", "{", "return", "v", ".", "original", "[", ":", "1", "]", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// 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", ".", "minor", "=", "v", ".", "minor", "+", "1", "\n", "vNext", ".", "original", "=", "v", ".", "originalVPrefix", "(", ")", "+", "\"", "\"", "+", "vNext", ".", "String", "(", ")", "\n", "return", "vNext", "\n", "}" ]
// 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", ".", "minor", "=", "0", "\n", "vNext", ".", "major", "=", "v", ".", "major", "+", "1", "\n", "vNext", ".", "original", "=", "v", ".", "originalVPrefix", "(", ")", "+", "\"", "\"", "+", "vNext", ".", "String", "(", ")", "\n", "return", "vNext", "\n", "}" ]
// 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", "(", "prerelease", ")", "{", "return", "vNext", ",", "ErrInvalidPrerelease", "\n", "}", "\n", "vNext", ".", "pre", "=", "prerelease", "\n", "vNext", ".", "original", "=", "v", ".", "originalVPrefix", "(", ")", "+", "\"", "\"", "+", "vNext", ".", "String", "(", ")", "\n", "return", "vNext", ",", "nil", "\n", "}" ]
// 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", "(", "metadata", ")", "{", "return", "vNext", ",", "ErrInvalidMetadata", "\n", "}", "\n", "vNext", ".", "metadata", "=", "metadata", "\n", "vNext", ".", "original", "=", "v", ".", "originalVPrefix", "(", ")", "+", "\"", "\"", "+", "vNext", ".", "String", "(", ")", "\n", "return", "vNext", ",", "nil", "\n", "}" ]
// 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 := compareSegment(v.Patch(), o.Patch()); d != 0 { return d } // At this point the major, minor, and patch versions are the same. ps := v.pre po := o.Prerelease() if ps == "" && po == "" { return 0 } if ps == "" { return 1 } if po == "" { return -1 } return comparePrerelease(ps, po) }
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 := compareSegment(v.Patch(), o.Patch()); d != 0 { return d } // At this point the major, minor, and patch versions are the same. ps := v.pre po := o.Prerelease() if ps == "" && po == "" { return 0 } if ps == "" { return 1 } if po == "" { return -1 } return comparePrerelease(ps, po) }
[ "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", "\n", "}", "\n", "if", "d", ":=", "compareSegment", "(", "v", ".", "Minor", "(", ")", ",", "o", ".", "Minor", "(", ")", ")", ";", "d", "!=", "0", "{", "return", "d", "\n", "}", "\n", "if", "d", ":=", "compareSegment", "(", "v", ".", "Patch", "(", ")", ",", "o", ".", "Patch", "(", ")", ")", ";", "d", "!=", "0", "{", "return", "d", "\n", "}", "\n\n", "// At this point the major, minor, and patch versions are the same.", "ps", ":=", "v", ".", "pre", "\n", "po", ":=", "o", ".", "Prerelease", "(", ")", "\n\n", "if", "ps", "==", "\"", "\"", "&&", "po", "==", "\"", "\"", "{", "return", "0", "\n", "}", "\n", "if", "ps", "==", "\"", "\"", "{", "return", "1", "\n", "}", "\n", "if", "po", "==", "\"", "\"", "{", "return", "-", "1", "\n", "}", "\n\n", "return", "comparePrerelease", "(", "ps", ",", "po", ")", "\n", "}" ]
// 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", ".", "Y", ".", "Z", ".", "Build", "metadata", "is", "ignored", ".", "Prerelease", "is", "lower", "than", "the", "version", "without", "a", "prerelease", "." ]
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.original temp = nil return nil }
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.original temp = nil return nil }
[ "func", "(", "v", "*", "Version", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "var", "s", "string", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "s", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "temp", ",", "err", ":=", "NewVersion", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "v", ".", "major", "=", "temp", ".", "major", "\n", "v", ".", "minor", "=", "temp", ".", "minor", "\n", "v", ".", "patch", "=", "temp", ".", "patch", "\n", "v", ".", "pre", "=", "temp", ".", "pre", "\n", "v", ".", "metadata", "=", "temp", ".", "metadata", "\n", "v", ".", "original", "=", "temp", ".", "original", "\n", "temp", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// 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 { pc, err := parseConstraint(s) if err != nil { return nil, err } result[i] = pc } or[k] = result } o := &Constraints{constraints: or} return o, nil }
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 { pc, err := parseConstraint(s) if err != nil { return nil, err } result[i] = pc } or[k] = result } o := &Constraints{constraints: or} return o, nil }
[ "func", "NewConstraint", "(", "c", "string", ")", "(", "*", "Constraints", ",", "error", ")", "{", "// Rewrite - ranges into a comparison operation.", "c", "=", "rewriteRange", "(", "c", ")", "\n\n", "ors", ":=", "strings", ".", "Split", "(", "c", ",", "\"", "\"", ")", "\n", "or", ":=", "make", "(", "[", "]", "[", "]", "*", "constraint", ",", "len", "(", "ors", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "ors", "{", "cs", ":=", "strings", ".", "Split", "(", "v", ",", "\"", "\"", ")", "\n", "result", ":=", "make", "(", "[", "]", "*", "constraint", ",", "len", "(", "cs", ")", ")", "\n", "for", "i", ",", "s", ":=", "range", "cs", "{", "pc", ",", "err", ":=", "parseConstraint", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", "[", "i", "]", "=", "pc", "\n", "}", "\n", "or", "[", "k", "]", "=", "result", "\n", "}", "\n\n", "o", ":=", "&", "Constraints", "{", "constraints", ":", "or", "}", "\n", "return", "o", ",", "nil", "\n", "}" ]
// 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", "_", ",", "c", ":=", "range", "o", "{", "if", "!", "c", ".", "check", "(", "v", ")", "{", "joy", "=", "false", "\n", "break", "\n", "}", "\n", "}", "\n\n", "if", "joy", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// 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 { return true, []error{} } } return false, e }
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 { return true, []error{} } } return false, e }
[ "func", "(", "cs", "Constraints", ")", "Validate", "(", "v", "*", "Version", ")", "(", "bool", ",", "[", "]", "error", ")", "{", "// loop over the ORs and check the inner ANDs", "var", "e", "[", "]", "error", "\n", "for", "_", ",", "o", ":=", "range", "cs", ".", "constraints", "{", "joy", ":=", "true", "\n", "for", "_", ",", "c", ":=", "range", "o", "{", "if", "!", "c", ".", "check", "(", "v", ")", "{", "em", ":=", "fmt", ".", "Errorf", "(", "c", ".", "msg", ",", "v", ",", "c", ".", "orig", ")", "\n", "e", "=", "append", "(", "e", ",", "em", ")", "\n", "joy", "=", "false", "\n", "}", "\n", "}", "\n\n", "if", "joy", "{", "return", "true", ",", "[", "]", "error", "{", "}", "\n", "}", "\n", "}", "\n\n", "return", "false", ",", "e", "\n", "}" ]
// 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 the debugger. case "level": level, err := strconv.Atoi(kv[1]) if err != nil { panicf("netlink: invalid NLDEBUG level: %q", a) } d.Level = level } } return d }
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 the debugger. case "level": level, err := strconv.Atoi(kv[1]) if err != nil { panicf("netlink: invalid NLDEBUG level: %q", a) } d.Level = level } } return d }
[ "func", "newDebugger", "(", "args", "[", "]", "string", ")", "*", "debugger", "{", "d", ":=", "&", "debugger", "{", "Log", ":", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "0", ")", ",", "Level", ":", "1", ",", "}", "\n\n", "for", "_", ",", "a", ":=", "range", "args", "{", "kv", ":=", "strings", ".", "Split", "(", "a", ",", "\"", "\"", ")", "\n", "if", "len", "(", "kv", ")", "!=", "2", "{", "// Ignore malformed pairs and assume callers wants defaults.", "continue", "\n", "}", "\n\n", "switch", "kv", "[", "0", "]", "{", "// Select the log level for the debugger.", "case", "\"", "\"", ":", "level", ",", "err", ":=", "strconv", ".", "Atoi", "(", "kv", "[", "1", "]", ")", "\n", "if", "err", "!=", "nil", "{", "panicf", "(", "\"", "\"", ",", "a", ")", "\n", "}", "\n\n", "d", ".", "Level", "=", "level", "\n", "}", "\n", "}", "\n\n", "return", "d", "\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", ",", "v", "...", ")", "\n", "}", "\n", "}" ]
// 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", "[", "0", "]", "=", "v", "\n", "}" ]
// 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", "*", "(", "*", "uint16", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "=", "v", "\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", "*", "(", "*", "uint32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "=", "v", "\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", "*", "(", "*", "uint64", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "=", "v", "\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", "*", "(", "*", "int32", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "=", "v", "\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", "[", "0", "]", "\n", "}" ]
// 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", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "\n", "}" ]
// 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", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "\n", "}" ]
// 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", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "\n", "}" ]
// 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", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", "[", "0", "]", ")", ")", "\n", "}" ]
// 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", "filling", "it", "using", "PutUint16", "." ]
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", "filling", "it", "using", "PutUint32", "." ]
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", "filling", "it", "using", "PutUint64", "." ]
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", "filling", "it", "using", "PutInt32", "." ]
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", "\n", "}", "\n\n", "return", "binary", ".", "BigEndian", "\n", "}" ]
// 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)) } } if s == "" && left == 0 { s = "0" } if left > 0 { if s != "" { s += "|" } s += fmt.Sprintf("%#x", left) } return s }
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)) } } if s == "" && left == 0 { s = "0" } if left > 0 { if s != "" { s += "|" } s += fmt.Sprintf("%#x", left) } return s }
[ "func", "(", "f", "HeaderFlags", ")", "String", "(", ")", "string", "{", "names", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n\n", "var", "s", "string", "\n\n", "left", ":=", "uint", "(", "f", ")", "\n\n", "for", "i", ",", "name", ":=", "range", "names", "{", "if", "f", "&", "(", "1", "<<", "uint", "(", "i", ")", ")", "!=", "0", "{", "if", "s", "!=", "\"", "\"", "{", "s", "+=", "\"", "\"", "\n", "}", "\n\n", "s", "+=", "name", "\n\n", "left", "^=", "(", "1", "<<", "uint", "(", "i", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "s", "==", "\"", "\"", "&&", "left", "==", "0", "{", "s", "=", "\"", "\"", "\n", "}", "\n\n", "if", "left", ">", "0", "{", "if", "s", "!=", "\"", "\"", "{", "s", "+=", "\"", "\"", "\n", "}", "\n", "s", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "left", ")", "\n", "}", "\n\n", "return", "s", "\n", "}" ]
// 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", "Overrun", ":", "return", "\"", "\"", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ")", "\n", "}", "\n", "}" ]
// 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.PutUint16(b[6:8], uint16(m.Header.Flags)) nlenc.PutUint32(b[8:12], m.Header.Sequence) nlenc.PutUint32(b[12:16], m.Header.PID) copy(b[16:], m.Data) return b, nil }
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.PutUint16(b[6:8], uint16(m.Header.Flags)) nlenc.PutUint32(b[8:12], m.Header.Sequence) nlenc.PutUint32(b[12:16], m.Header.PID) copy(b[16:], m.Data) return b, nil }
[ "func", "(", "m", "Message", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ml", ":=", "nlmsgAlign", "(", "int", "(", "m", ".", "Header", ".", "Length", ")", ")", "\n", "if", "ml", "<", "nlmsgHeaderLen", "||", "ml", "!=", "int", "(", "m", ".", "Header", ".", "Length", ")", "{", "return", "nil", ",", "errIncorrectMessageLength", "\n", "}", "\n\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "ml", ")", "\n\n", "nlenc", ".", "PutUint32", "(", "b", "[", "0", ":", "4", "]", ",", "m", ".", "Header", ".", "Length", ")", "\n", "nlenc", ".", "PutUint16", "(", "b", "[", "4", ":", "6", "]", ",", "uint16", "(", "m", ".", "Header", ".", "Type", ")", ")", "\n", "nlenc", ".", "PutUint16", "(", "b", "[", "6", ":", "8", "]", ",", "uint16", "(", "m", ".", "Header", ".", "Flags", ")", ")", "\n", "nlenc", ".", "PutUint32", "(", "b", "[", "8", ":", "12", "]", ",", "m", ".", "Header", ".", "Sequence", ")", "\n", "nlenc", ".", "PutUint32", "(", "b", "[", "12", ":", "16", "]", ",", "m", ".", "Header", ".", "PID", ")", "\n", "copy", "(", "b", "[", "16", ":", "]", ",", "m", ".", "Data", ")", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// 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.Header.Type = HeaderType(nlenc.Uint16(b[4:6])) m.Header.Flags = HeaderFlags(nlenc.Uint16(b[6:8])) m.Header.Sequence = nlenc.Uint32(b[8:12]) m.Header.PID = nlenc.Uint32(b[12:16]) m.Data = b[16:] return nil }
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.Header.Type = HeaderType(nlenc.Uint16(b[4:6])) m.Header.Flags = HeaderFlags(nlenc.Uint16(b[6:8])) m.Header.Sequence = nlenc.Uint32(b[8:12]) m.Header.PID = nlenc.Uint32(b[12:16]) m.Data = b[16:] return nil }
[ "func", "(", "m", "*", "Message", ")", "UnmarshalBinary", "(", "b", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "b", ")", "<", "nlmsgHeaderLen", "{", "return", "errShortMessage", "\n", "}", "\n", "if", "len", "(", "b", ")", "!=", "nlmsgAlign", "(", "len", "(", "b", ")", ")", "{", "return", "errUnalignedMessage", "\n", "}", "\n\n", "// Don't allow misleading length", "m", ".", "Header", ".", "Length", "=", "nlenc", ".", "Uint32", "(", "b", "[", "0", ":", "4", "]", ")", "\n", "if", "int", "(", "m", ".", "Header", ".", "Length", ")", "!=", "len", "(", "b", ")", "{", "return", "errShortMessage", "\n", "}", "\n\n", "m", ".", "Header", ".", "Type", "=", "HeaderType", "(", "nlenc", ".", "Uint16", "(", "b", "[", "4", ":", "6", "]", ")", ")", "\n", "m", ".", "Header", ".", "Flags", "=", "HeaderFlags", "(", "nlenc", ".", "Uint16", "(", "b", "[", "6", ":", "8", "]", ")", ")", "\n", "m", ".", "Header", ".", "Sequence", "=", "nlenc", ".", "Uint32", "(", "b", "[", "8", ":", "12", "]", ")", "\n", "m", ".", "Header", ".", "PID", "=", "nlenc", ".", "Uint32", "(", "b", "[", "12", ":", "16", "]", ")", "\n", "m", ".", "Data", "=", "b", "[", "16", ":", "]", "\n\n", "return", "nil", "\n", "}" ]
// 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: // https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg. // // However, at one point, this package checked both done and error for // error codes. Because there was no issue associated with the change, // it is unknown whether this change was correct or not. If you run into // a problem with your application because of this change, please file // an issue. if m.Header.Type != Error { return nil } if len(m.Data) < 4 { return newOpError("receive", errShortErrorMessage) } if c := nlenc.Int32(m.Data[0:4]); c != success { // Error code is a negative integer, convert it into an OS-specific raw // system call error, but do not wrap with os.NewSyscallError to signify // that this error was produced by a netlink message; not a system call. return newOpError("receive", newError(-1*int(c))) } return nil }
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: // https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg. // // However, at one point, this package checked both done and error for // error codes. Because there was no issue associated with the change, // it is unknown whether this change was correct or not. If you run into // a problem with your application because of this change, please file // an issue. if m.Header.Type != Error { return nil } if len(m.Data) < 4 { return newOpError("receive", errShortErrorMessage) } if c := nlenc.Int32(m.Data[0:4]); c != success { // Error code is a negative integer, convert it into an OS-specific raw // system call error, but do not wrap with os.NewSyscallError to signify // that this error was produced by a netlink message; not a system call. return newOpError("receive", newError(-1*int(c))) } return nil }
[ "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 libnl documentation, only messages that indicate type error can", "// contain error codes:", "// https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg.", "//", "// However, at one point, this package checked both done and error for", "// error codes. Because there was no issue associated with the change,", "// it is unknown whether this change was correct or not. If you run into", "// a problem with your application because of this change, please file", "// an issue.", "if", "m", ".", "Header", ".", "Type", "!=", "Error", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "m", ".", "Data", ")", "<", "4", "{", "return", "newOpError", "(", "\"", "\"", ",", "errShortErrorMessage", ")", "\n", "}", "\n\n", "if", "c", ":=", "nlenc", ".", "Int32", "(", "m", ".", "Data", "[", "0", ":", "4", "]", ")", ";", "c", "!=", "success", "{", "// Error code is a negative integer, convert it into an OS-specific raw", "// system call error, but do not wrap with os.NewSyscallError to signify", "// that this error was produced by a netlink message; not a system call.", "return", "newOpError", "(", "\"", "\"", ",", "newError", "(", "-", "1", "*", "int", "(", "c", ")", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", "}", "\n\n", "nlenc", ".", "PutUint16", "(", "b", "[", "0", ":", "2", "]", ",", "a", ".", "Length", ")", "\n", "nlenc", ".", "PutUint16", "(", "b", "[", "2", ":", "4", "]", ",", "a", ".", "Type", ")", "\n", "n", ":=", "copy", "(", "b", "[", "nlaHeaderLen", ":", "]", ",", "a", ".", "Data", ")", "\n\n", "return", "nlaHeaderLen", "+", "nlaAlign", "(", "n", ")", ",", "nil", "\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) // Not enough length for any data case int(a.Length) < nlaHeaderLen: return errInvalidAttribute // Data present case int(a.Length) >= nlaHeaderLen: a.Data = make([]byte, len(b[nlaHeaderLen:a.Length])) copy(a.Data, b[nlaHeaderLen:a.Length]) } return nil }
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) // Not enough length for any data case int(a.Length) < nlaHeaderLen: return errInvalidAttribute // Data present case int(a.Length) >= nlaHeaderLen: a.Data = make([]byte, len(b[nlaHeaderLen:a.Length])) copy(a.Data, b[nlaHeaderLen:a.Length]) } return nil }
[ "func", "(", "a", "*", "Attribute", ")", "unmarshal", "(", "b", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "b", ")", "<", "nlaHeaderLen", "{", "return", "errInvalidAttribute", "\n", "}", "\n\n", "a", ".", "Length", "=", "nlenc", ".", "Uint16", "(", "b", "[", "0", ":", "2", "]", ")", "\n", "a", ".", "Type", "=", "nlenc", ".", "Uint16", "(", "b", "[", "2", ":", "4", "]", ")", "\n\n", "if", "int", "(", "a", ".", "Length", ")", ">", "len", "(", "b", ")", "{", "return", "errInvalidAttribute", "\n", "}", "\n\n", "switch", "{", "// No length, no data", "case", "a", ".", "Length", "==", "0", ":", "a", ".", "Data", "=", "make", "(", "[", "]", "byte", ",", "0", ")", "\n", "// Not enough length for any data", "case", "int", "(", "a", ".", "Length", ")", "<", "nlaHeaderLen", ":", "return", "errInvalidAttribute", "\n", "// Data present", "case", "int", "(", "a", ".", "Length", ")", ">=", "nlaHeaderLen", ":", "a", ".", "Data", "=", "make", "(", "[", "]", "byte", ",", "len", "(", "b", "[", "nlaHeaderLen", ":", "a", ".", "Length", "]", ")", ")", "\n", "copy", "(", "a", ".", "Data", ",", "b", "[", "nlaHeaderLen", ":", "a", ".", "Length", "]", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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 := make([]byte, c) for _, a := range attrs { // Infer the length of attribute if zero. if a.Length == 0 { a.Length = uint16(nlaHeaderLen + len(a.Data)) } // Marshal a into b and advance idx to show many bytes are occupied. n, err := a.marshal(b[idx:]) if err != nil { return nil, err } idx += n } return b, nil }
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 := make([]byte, c) for _, a := range attrs { // Infer the length of attribute if zero. if a.Length == 0 { a.Length = uint16(nlaHeaderLen + len(a.Data)) } // Marshal a into b and advance idx to show many bytes are occupied. n, err := a.marshal(b[idx:]) if err != nil { return nil, err } idx += n } return b, nil }
[ "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", "attrs", "{", "c", "+=", "nlaHeaderLen", "+", "nlaAlign", "(", "len", "(", "a", ".", "Data", ")", ")", "\n", "}", "\n\n", "// Advance through b with idx to place attribute data at the correct offset.", "var", "idx", "int", "\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "c", ")", "\n", "for", "_", ",", "a", ":=", "range", "attrs", "{", "// Infer the length of attribute if zero.", "if", "a", ".", "Length", "==", "0", "{", "a", ".", "Length", "=", "uint16", "(", "nlaHeaderLen", "+", "len", "(", "a", ".", "Data", ")", ")", "\n", "}", "\n\n", "// Marshal a into b and advance idx to show many bytes are occupied.", "n", ",", "err", ":=", "a", ".", "marshal", "(", "b", "[", "idx", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "idx", "+=", "n", "\n", "}", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// 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", "and", "populated", "automatically", "for", "each", "Attribute", "." ]
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.Length)) attrs = append(attrs, a) } return attrs, nil }
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.Length)) attrs = append(attrs, a) } return attrs, nil }
[ "func", "UnmarshalAttributes", "(", "b", "[", "]", "byte", ")", "(", "[", "]", "Attribute", ",", "error", ")", "{", "var", "attrs", "[", "]", "Attribute", "\n", "var", "i", "int", "\n", "for", "{", "if", "i", ">", "len", "(", "b", ")", "||", "len", "(", "b", "[", "i", ":", "]", ")", "==", "0", "{", "break", "\n", "}", "\n\n", "var", "a", "Attribute", "\n", "if", "err", ":=", "(", "&", "a", ")", ".", "unmarshal", "(", "b", "[", "i", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "a", ".", "Length", "==", "0", "{", "i", "+=", "nlaHeaderLen", "\n", "continue", "\n", "}", "\n\n", "i", "+=", "nlaAlign", "(", "int", "(", "a", ".", "Length", ")", ")", "\n\n", "attrs", "=", "append", "(", "attrs", ",", "a", ")", "\n", "}", "\n\n", "return", "attrs", ",", "nil", "\n", "}" ]
// 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", "using", "package", "nlenc", "functions", "directly", "." ]
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", "\n", "}", "\n\n", "return", "&", "AttributeDecoder", "{", "// By default, use native byte order.", "ByteOrder", ":", "nlenc", ".", "NativeEndian", "(", ")", ",", "attrs", ":", "attrs", ",", "}", ",", "nil", "\n", "}" ]
// 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", "len", "(", "ad", ".", "attrs", ")", ">=", "ad", ".", "i", "\n", "}" ]
// 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", ",", "src", ")", "\n", "return", "dest", "\n", "}" ]
// 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", "{", "ad", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ad", ".", "Type", "(", ")", ",", "len", "(", "b", ")", ")", "\n", "return", "0", "\n", "}", "\n\n", "return", "uint8", "(", "b", "[", "0", "]", ")", "\n", "}" ]
// 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", "{", "ad", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ad", ".", "Type", "(", ")", ",", "len", "(", "b", ")", ")", "\n", "return", "0", "\n", "}", "\n\n", "return", "ad", ".", "ByteOrder", ".", "Uint16", "(", "b", ")", "\n", "}" ]
// 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", "{", "ad", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ad", ".", "Type", "(", ")", ",", "len", "(", "b", ")", ")", "\n", "return", "0", "\n", "}", "\n\n", "return", "ad", ".", "ByteOrder", ".", "Uint32", "(", "b", ")", "\n", "}" ]
// 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", "{", "ad", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ad", ".", "Type", "(", ")", ",", "len", "(", "b", ")", ")", "\n", "return", "0", "\n", "}", "\n\n", "return", "ad", ".", "ByteOrder", ".", "Uint64", "(", "b", ")", "\n", "}" ]
// 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