id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
167,100
gobwas/ws
http.go
httpParseVersion
func httpParseVersion(bts []byte) (major, minor int, ok bool) { switch { case bytes.Equal(bts, httpVersion1_0): return 1, 0, true case bytes.Equal(bts, httpVersion1_1): return 1, 1, true case len(bts) < 8: return case !bytes.Equal(bts[:5], httpVersionPrefix): return } bts = bts[5:] dot := bytes.IndexByte(bts, '.') if dot == -1 { return } var err error major, err = asciiToInt(bts[:dot]) if err != nil { return } minor, err = asciiToInt(bts[dot+1:]) if err != nil { return } return major, minor, true }
go
func httpParseVersion(bts []byte) (major, minor int, ok bool) { switch { case bytes.Equal(bts, httpVersion1_0): return 1, 0, true case bytes.Equal(bts, httpVersion1_1): return 1, 1, true case len(bts) < 8: return case !bytes.Equal(bts[:5], httpVersionPrefix): return } bts = bts[5:] dot := bytes.IndexByte(bts, '.') if dot == -1 { return } var err error major, err = asciiToInt(bts[:dot]) if err != nil { return } minor, err = asciiToInt(bts[dot+1:]) if err != nil { return } return major, minor, true }
[ "func", "httpParseVersion", "(", "bts", "[", "]", "byte", ")", "(", "major", ",", "minor", "int", ",", "ok", "bool", ")", "{", "switch", "{", "case", "bytes", ".", "Equal", "(", "bts", ",", "httpVersion1_0", ")", ":", "return", "1", ",", "0", ",", "true", "\n", "case", "bytes", ".", "Equal", "(", "bts", ",", "httpVersion1_1", ")", ":", "return", "1", ",", "1", ",", "true", "\n", "case", "len", "(", "bts", ")", "<", "8", ":", "return", "\n", "case", "!", "bytes", ".", "Equal", "(", "bts", "[", ":", "5", "]", ",", "httpVersionPrefix", ")", ":", "return", "\n", "}", "\n\n", "bts", "=", "bts", "[", "5", ":", "]", "\n\n", "dot", ":=", "bytes", ".", "IndexByte", "(", "bts", ",", "'.'", ")", "\n", "if", "dot", "==", "-", "1", "{", "return", "\n", "}", "\n", "var", "err", "error", "\n", "major", ",", "err", "=", "asciiToInt", "(", "bts", "[", ":", "dot", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "minor", ",", "err", "=", "asciiToInt", "(", "bts", "[", "dot", "+", "1", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "return", "major", ",", "minor", ",", "true", "\n", "}" ]
// httpParseVersion parses major and minor version of HTTP protocol. It returns // parsed values and true if parse is ok.
[ "httpParseVersion", "parses", "major", "and", "minor", "version", "of", "HTTP", "protocol", ".", "It", "returns", "parsed", "values", "and", "true", "if", "parse", "is", "ok", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/http.go#L124-L153
167,101
gobwas/ws
http.go
httpParseHeaderLine
func httpParseHeaderLine(line []byte) (k, v []byte, ok bool) { colon := bytes.IndexByte(line, ':') if colon == -1 { return } k = btrim(line[:colon]) // TODO(gobwas): maybe use just lower here? canonicalizeHeaderKey(k) v = btrim(line[colon+1:]) return k, v, true }
go
func httpParseHeaderLine(line []byte) (k, v []byte, ok bool) { colon := bytes.IndexByte(line, ':') if colon == -1 { return } k = btrim(line[:colon]) // TODO(gobwas): maybe use just lower here? canonicalizeHeaderKey(k) v = btrim(line[colon+1:]) return k, v, true }
[ "func", "httpParseHeaderLine", "(", "line", "[", "]", "byte", ")", "(", "k", ",", "v", "[", "]", "byte", ",", "ok", "bool", ")", "{", "colon", ":=", "bytes", ".", "IndexByte", "(", "line", ",", "':'", ")", "\n", "if", "colon", "==", "-", "1", "{", "return", "\n", "}", "\n\n", "k", "=", "btrim", "(", "line", "[", ":", "colon", "]", ")", "\n", "// TODO(gobwas): maybe use just lower here?", "canonicalizeHeaderKey", "(", "k", ")", "\n\n", "v", "=", "btrim", "(", "line", "[", "colon", "+", "1", ":", "]", ")", "\n\n", "return", "k", ",", "v", ",", "true", "\n", "}" ]
// httpParseHeaderLine parses HTTP header as key-value pair. It returns parsed // values and true if parse is ok.
[ "httpParseHeaderLine", "parses", "HTTP", "header", "as", "key", "-", "value", "pair", ".", "It", "returns", "parsed", "values", "and", "true", "if", "parse", "is", "ok", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/http.go#L157-L170
167,102
gobwas/ws
http.go
httpGetHeader
func httpGetHeader(h http.Header, key string) string { if h == nil { return "" } v := h[key] if len(v) == 0 { return "" } return v[0] }
go
func httpGetHeader(h http.Header, key string) string { if h == nil { return "" } v := h[key] if len(v) == 0 { return "" } return v[0] }
[ "func", "httpGetHeader", "(", "h", "http", ".", "Header", ",", "key", "string", ")", "string", "{", "if", "h", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "v", ":=", "h", "[", "key", "]", "\n", "if", "len", "(", "v", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "v", "[", "0", "]", "\n", "}" ]
// httpGetHeader is the same as textproto.MIMEHeader.Get, except the thing, // that key is already canonical. This helps to increase performance.
[ "httpGetHeader", "is", "the", "same", "as", "textproto", ".", "MIMEHeader", ".", "Get", "except", "the", "thing", "that", "key", "is", "already", "canonical", ".", "This", "helps", "to", "increase", "performance", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/http.go#L174-L183
167,103
gobwas/ws
http.go
httpError
func httpError(w http.ResponseWriter, body string, code int) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Header().Set("Content-Length", strconv.Itoa(len(body))) w.WriteHeader(code) w.Write([]byte(body)) }
go
func httpError(w http.ResponseWriter, body string, code int) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Header().Set("Content-Length", strconv.Itoa(len(body))) w.WriteHeader(code) w.Write([]byte(body)) }
[ "func", "httpError", "(", "w", "http", ".", "ResponseWriter", ",", "body", "string", ",", "code", "int", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "len", "(", "body", ")", ")", ")", "\n", "w", ".", "WriteHeader", "(", "code", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "body", ")", ")", "\n", "}" ]
// httpError is like the http.Error with WebSocket context exception.
[ "httpError", "is", "like", "the", "http", ".", "Error", "with", "WebSocket", "context", "exception", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/http.go#L375-L380
167,104
gobwas/ws
check.go
Is
func (s State) Is(v State) bool { return uint8(s)&uint8(v) != 0 }
go
func (s State) Is(v State) bool { return uint8(s)&uint8(v) != 0 }
[ "func", "(", "s", "State", ")", "Is", "(", "v", "State", ")", "bool", "{", "return", "uint8", "(", "s", ")", "&", "uint8", "(", "v", ")", "!=", "0", "\n", "}" ]
// Is checks whether the s has v enabled.
[ "Is", "checks", "whether", "the", "s", "has", "v", "enabled", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/check.go#L22-L24
167,105
gobwas/ws
wsutil/reader.go
NewReader
func NewReader(r io.Reader, s ws.State) *Reader { return &Reader{ Source: r, State: s, } }
go
func NewReader(r io.Reader, s ws.State) *Reader { return &Reader{ Source: r, State: s, } }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ",", "s", "ws", ".", "State", ")", "*", "Reader", "{", "return", "&", "Reader", "{", "Source", ":", "r", ",", "State", ":", "s", ",", "}", "\n", "}" ]
// NewReader creates new frame reader that reads from r keeping given state to // make some protocol validity checks when it needed.
[ "NewReader", "creates", "new", "frame", "reader", "that", "reads", "from", "r", "keeping", "given", "state", "to", "make", "some", "protocol", "validity", "checks", "when", "it", "needed", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/reader.go#L53-L58
167,106
gobwas/ws
wsutil/reader.go
Discard
func (r *Reader) Discard() (err error) { for { _, err = io.Copy(ioutil.Discard, &r.raw) if err != nil { break } if !r.fragmented() { break } if _, err = r.NextFrame(); err != nil { break } } r.reset() return err }
go
func (r *Reader) Discard() (err error) { for { _, err = io.Copy(ioutil.Discard, &r.raw) if err != nil { break } if !r.fragmented() { break } if _, err = r.NextFrame(); err != nil { break } } r.reset() return err }
[ "func", "(", "r", "*", "Reader", ")", "Discard", "(", ")", "(", "err", "error", ")", "{", "for", "{", "_", ",", "err", "=", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "&", "r", ".", "raw", ")", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "if", "!", "r", ".", "fragmented", "(", ")", "{", "break", "\n", "}", "\n", "if", "_", ",", "err", "=", "r", ".", "NextFrame", "(", ")", ";", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "}", "\n", "r", ".", "reset", "(", ")", "\n", "return", "err", "\n", "}" ]
// Discard discards current message unread bytes. // It discards all frames of fragmeneted message.
[ "Discard", "discards", "current", "message", "unread", "bytes", ".", "It", "discards", "all", "frames", "of", "fragmeneted", "message", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/reader.go#L128-L143
167,107
gobwas/ws
wsutil/cipher.go
NewCipherReader
func NewCipherReader(r io.Reader, mask [4]byte) *CipherReader { return &CipherReader{r, mask, 0} }
go
func NewCipherReader(r io.Reader, mask [4]byte) *CipherReader { return &CipherReader{r, mask, 0} }
[ "func", "NewCipherReader", "(", "r", "io", ".", "Reader", ",", "mask", "[", "4", "]", "byte", ")", "*", "CipherReader", "{", "return", "&", "CipherReader", "{", "r", ",", "mask", ",", "0", "}", "\n", "}" ]
// NewCipherReader creates xor-cipher reader from r with given mask.
[ "NewCipherReader", "creates", "xor", "-", "cipher", "reader", "from", "r", "with", "given", "mask", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L20-L22
167,108
gobwas/ws
wsutil/cipher.go
Reset
func (c *CipherReader) Reset(r io.Reader, mask [4]byte) { c.r = r c.mask = mask c.pos = 0 }
go
func (c *CipherReader) Reset(r io.Reader, mask [4]byte) { c.r = r c.mask = mask c.pos = 0 }
[ "func", "(", "c", "*", "CipherReader", ")", "Reset", "(", "r", "io", ".", "Reader", ",", "mask", "[", "4", "]", "byte", ")", "{", "c", ".", "r", "=", "r", "\n", "c", ".", "mask", "=", "mask", "\n", "c", ".", "pos", "=", "0", "\n", "}" ]
// Reset resets CipherReader to read from r with given mask.
[ "Reset", "resets", "CipherReader", "to", "read", "from", "r", "with", "given", "mask", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L25-L29
167,109
gobwas/ws
wsutil/cipher.go
Read
func (c *CipherReader) Read(p []byte) (n int, err error) { n, err = c.r.Read(p) ws.Cipher(p[:n], c.mask, c.pos) c.pos += n return }
go
func (c *CipherReader) Read(p []byte) (n int, err error) { n, err = c.r.Read(p) ws.Cipher(p[:n], c.mask, c.pos) c.pos += n return }
[ "func", "(", "c", "*", "CipherReader", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "n", ",", "err", "=", "c", ".", "r", ".", "Read", "(", "p", ")", "\n", "ws", ".", "Cipher", "(", "p", "[", ":", "n", "]", ",", "c", ".", "mask", ",", "c", ".", "pos", ")", "\n", "c", ".", "pos", "+=", "n", "\n", "return", "\n", "}" ]
// Read implements io.Reader interface. It applies mask given during // initialization to every read byte.
[ "Read", "implements", "io", ".", "Reader", "interface", ".", "It", "applies", "mask", "given", "during", "initialization", "to", "every", "read", "byte", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L33-L38
167,110
gobwas/ws
wsutil/cipher.go
NewCipherWriter
func NewCipherWriter(w io.Writer, mask [4]byte) *CipherWriter { return &CipherWriter{w, mask, 0} }
go
func NewCipherWriter(w io.Writer, mask [4]byte) *CipherWriter { return &CipherWriter{w, mask, 0} }
[ "func", "NewCipherWriter", "(", "w", "io", ".", "Writer", ",", "mask", "[", "4", "]", "byte", ")", "*", "CipherWriter", "{", "return", "&", "CipherWriter", "{", "w", ",", "mask", ",", "0", "}", "\n", "}" ]
// NewCipherWriter creates xor-cipher writer to w with given mask.
[ "NewCipherWriter", "creates", "xor", "-", "cipher", "writer", "to", "w", "with", "given", "mask", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L49-L51
167,111
gobwas/ws
wsutil/cipher.go
Reset
func (c *CipherWriter) Reset(w io.Writer, mask [4]byte) { c.w = w c.mask = mask c.pos = 0 }
go
func (c *CipherWriter) Reset(w io.Writer, mask [4]byte) { c.w = w c.mask = mask c.pos = 0 }
[ "func", "(", "c", "*", "CipherWriter", ")", "Reset", "(", "w", "io", ".", "Writer", ",", "mask", "[", "4", "]", "byte", ")", "{", "c", ".", "w", "=", "w", "\n", "c", ".", "mask", "=", "mask", "\n", "c", ".", "pos", "=", "0", "\n", "}" ]
// Reset reset CipherWriter to write to w with given mask.
[ "Reset", "reset", "CipherWriter", "to", "write", "to", "w", "with", "given", "mask", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L54-L58
167,112
gobwas/ws
wsutil/cipher.go
Write
func (c *CipherWriter) Write(p []byte) (n int, err error) { cp := pbytes.GetLen(len(p)) defer pbytes.Put(cp) copy(cp, p) ws.Cipher(cp, c.mask, c.pos) n, err = c.w.Write(cp) c.pos += n return }
go
func (c *CipherWriter) Write(p []byte) (n int, err error) { cp := pbytes.GetLen(len(p)) defer pbytes.Put(cp) copy(cp, p) ws.Cipher(cp, c.mask, c.pos) n, err = c.w.Write(cp) c.pos += n return }
[ "func", "(", "c", "*", "CipherWriter", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "cp", ":=", "pbytes", ".", "GetLen", "(", "len", "(", "p", ")", ")", "\n", "defer", "pbytes", ".", "Put", "(", "cp", ")", "\n\n", "copy", "(", "cp", ",", "p", ")", "\n", "ws", ".", "Cipher", "(", "cp", ",", "c", ".", "mask", ",", "c", ".", "pos", ")", "\n", "n", ",", "err", "=", "c", ".", "w", ".", "Write", "(", "cp", ")", "\n", "c", ".", "pos", "+=", "n", "\n\n", "return", "\n", "}" ]
// Write implements io.Writer interface. It applies mask vien during // initialization to every sent byte. It does not modify original slice.
[ "Write", "implements", "io", ".", "Writer", "interface", ".", "It", "applies", "mask", "vien", "during", "initialization", "to", "every", "sent", "byte", ".", "It", "does", "not", "modify", "original", "slice", "." ]
7338e265e1ab4ea2403da5ce80d934ef5f976923
https://github.com/gobwas/ws/blob/7338e265e1ab4ea2403da5ce80d934ef5f976923/wsutil/cipher.go#L62-L72
167,113
rkt/rkt
store/imagestore/remote.go
GetRemote
func GetRemote(tx *sql.Tx, aciURL string) (*Remote, error) { rows, err := tx.Query("SELECT * FROM remote WHERE aciurl == $1", aciURL) if err != nil { return nil, err } defer rows.Close() if ok := rows.Next(); !ok { return nil, ErrRemoteNotFound } remote := &Remote{} if err := remoteRowScan(rows, remote); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return remote, nil }
go
func GetRemote(tx *sql.Tx, aciURL string) (*Remote, error) { rows, err := tx.Query("SELECT * FROM remote WHERE aciurl == $1", aciURL) if err != nil { return nil, err } defer rows.Close() if ok := rows.Next(); !ok { return nil, ErrRemoteNotFound } remote := &Remote{} if err := remoteRowScan(rows, remote); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return remote, nil }
[ "func", "GetRemote", "(", "tx", "*", "sql", ".", "Tx", ",", "aciURL", "string", ")", "(", "*", "Remote", ",", "error", ")", "{", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "\"", "\"", ",", "aciURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n\n", "if", "ok", ":=", "rows", ".", "Next", "(", ")", ";", "!", "ok", "{", "return", "nil", ",", "ErrRemoteNotFound", "\n", "}", "\n\n", "remote", ":=", "&", "Remote", "{", "}", "\n", "if", "err", ":=", "remoteRowScan", "(", "rows", ",", "remote", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "remote", ",", "nil", "\n", "}" ]
// GetRemote tries to retrieve a remote with the given aciURL. // If remote doesn't exist, it returns ErrRemoteNotFound error.
[ "GetRemote", "tries", "to", "retrieve", "a", "remote", "with", "the", "given", "aciURL", ".", "If", "remote", "doesn", "t", "exist", "it", "returns", "ErrRemoteNotFound", "error", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/remote.go#L56-L77
167,114
rkt/rkt
store/imagestore/remote.go
GetAllRemotes
func GetAllRemotes(tx *sql.Tx) ([]*Remote, error) { var remotes []*Remote query := "SELECT * from remote" rows, err := tx.Query(query) if err != nil { return nil, err } defer rows.Close() for rows.Next() { r := &Remote{} if err := remoteRowScan(rows, r); err != nil { return nil, err } remotes = append(remotes, r) } if err := rows.Err(); err != nil { return nil, err } return remotes, nil }
go
func GetAllRemotes(tx *sql.Tx) ([]*Remote, error) { var remotes []*Remote query := "SELECT * from remote" rows, err := tx.Query(query) if err != nil { return nil, err } defer rows.Close() for rows.Next() { r := &Remote{} if err := remoteRowScan(rows, r); err != nil { return nil, err } remotes = append(remotes, r) } if err := rows.Err(); err != nil { return nil, err } return remotes, nil }
[ "func", "GetAllRemotes", "(", "tx", "*", "sql", ".", "Tx", ")", "(", "[", "]", "*", "Remote", ",", "error", ")", "{", "var", "remotes", "[", "]", "*", "Remote", "\n", "query", ":=", "\"", "\"", "\n\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "query", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n\n", "for", "rows", ".", "Next", "(", ")", "{", "r", ":=", "&", "Remote", "{", "}", "\n", "if", "err", ":=", "remoteRowScan", "(", "rows", ",", "r", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n\n", "}", "\n\n", "remotes", "=", "append", "(", "remotes", ",", "r", ")", "\n\n", "}", "\n\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n\n", "}", "\n\n", "return", "remotes", ",", "nil", "\n\n", "}" ]
// GetAllRemotes returns all the ACIInfos sorted by optional sortfields and // with ascending or descending order.
[ "GetAllRemotes", "returns", "all", "the", "ACIInfos", "sorted", "by", "optional", "sortfields", "and", "with", "ascending", "or", "descending", "order", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/remote.go#L81-L110
167,115
rkt/rkt
store/imagestore/remote.go
RemoveRemote
func RemoveRemote(tx *sql.Tx, blobKey string) error { _, err := tx.Exec("DELETE FROM remote WHERE blobkey == $1", blobKey) if err != nil { return err } return nil }
go
func RemoveRemote(tx *sql.Tx, blobKey string) error { _, err := tx.Exec("DELETE FROM remote WHERE blobkey == $1", blobKey) if err != nil { return err } return nil }
[ "func", "RemoveRemote", "(", "tx", "*", "sql", ".", "Tx", ",", "blobKey", "string", ")", "error", "{", "_", ",", "err", ":=", "tx", ".", "Exec", "(", "\"", "\"", ",", "blobKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveRemote removes the remote with the given blobKey.
[ "RemoveRemote", "removes", "the", "remote", "with", "the", "given", "blobKey", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/remote.go#L128-L134
167,116
rkt/rkt
stage1/init/init.go
machinedRegister
func machinedRegister() bool { // machined has a D-Bus interface following versioning guidelines, see: // http://www.freedesktop.org/wiki/Software/systemd/machined/ // Therefore we can just check if the D-Bus method we need exists and we // don't need to check the signature. var found int conn, err := dbus.SystemBus() if err != nil { return false } node, err := introspect.Call(conn.Object("org.freedesktop.machine1", "/org/freedesktop/machine1")) if err != nil { return false } for _, iface := range node.Interfaces { if iface.Name != "org.freedesktop.machine1.Manager" { continue } // machined v215 supports methods "RegisterMachine" and "CreateMachine" called by nspawn v215. // machined v216+ (since commit 5aa4bb) additionally supports methods "CreateMachineWithNetwork" // and "RegisterMachineWithNetwork", called by nspawn v216+. for _, method := range iface.Methods { if method.Name == "CreateMachineWithNetwork" || method.Name == "RegisterMachineWithNetwork" { found++ } } break } return found == 2 }
go
func machinedRegister() bool { // machined has a D-Bus interface following versioning guidelines, see: // http://www.freedesktop.org/wiki/Software/systemd/machined/ // Therefore we can just check if the D-Bus method we need exists and we // don't need to check the signature. var found int conn, err := dbus.SystemBus() if err != nil { return false } node, err := introspect.Call(conn.Object("org.freedesktop.machine1", "/org/freedesktop/machine1")) if err != nil { return false } for _, iface := range node.Interfaces { if iface.Name != "org.freedesktop.machine1.Manager" { continue } // machined v215 supports methods "RegisterMachine" and "CreateMachine" called by nspawn v215. // machined v216+ (since commit 5aa4bb) additionally supports methods "CreateMachineWithNetwork" // and "RegisterMachineWithNetwork", called by nspawn v216+. for _, method := range iface.Methods { if method.Name == "CreateMachineWithNetwork" || method.Name == "RegisterMachineWithNetwork" { found++ } } break } return found == 2 }
[ "func", "machinedRegister", "(", ")", "bool", "{", "// machined has a D-Bus interface following versioning guidelines, see:", "// http://www.freedesktop.org/wiki/Software/systemd/machined/", "// Therefore we can just check if the D-Bus method we need exists and we", "// don't need to check the signature.", "var", "found", "int", "\n\n", "conn", ",", "err", ":=", "dbus", ".", "SystemBus", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "node", ",", "err", ":=", "introspect", ".", "Call", "(", "conn", ".", "Object", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "iface", ":=", "range", "node", ".", "Interfaces", "{", "if", "iface", ".", "Name", "!=", "\"", "\"", "{", "continue", "\n", "}", "\n", "// machined v215 supports methods \"RegisterMachine\" and \"CreateMachine\" called by nspawn v215.", "// machined v216+ (since commit 5aa4bb) additionally supports methods \"CreateMachineWithNetwork\"", "// and \"RegisterMachineWithNetwork\", called by nspawn v216+.", "for", "_", ",", "method", ":=", "range", "iface", ".", "Methods", "{", "if", "method", ".", "Name", "==", "\"", "\"", "||", "method", ".", "Name", "==", "\"", "\"", "{", "found", "++", "\n", "}", "\n", "}", "\n", "break", "\n", "}", "\n", "return", "found", "==", "2", "\n", "}" ]
// machinedRegister checks if nspawn should register the pod to machined
[ "machinedRegister", "checks", "if", "nspawn", "should", "register", "the", "pod", "to", "machined" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/init.go#L162-L192
167,117
rkt/rkt
stage1/init/init.go
mountContainerV1Cgroups
func mountContainerV1Cgroups(m fs.Mounter, p *stage1commontypes.Pod, enabledCgroups map[int][]string, subcgroup string, serviceNames []string) error { mountContext := os.Getenv(common.EnvSELinuxMountContext) stage1Root := common.Stage1RootfsPath(p.Root) if err := v1.CreateCgroups(m, stage1Root, enabledCgroups, mountContext); err != nil { return errwrap.Wrap(errors.New("error creating container cgroups"), err) } if err := v1.RemountCgroups(m, stage1Root, enabledCgroups, subcgroup, p.InsecureOptions.DisablePaths); err != nil { return errwrap.Wrap(errors.New("error restricting container cgroups"), err) } return nil }
go
func mountContainerV1Cgroups(m fs.Mounter, p *stage1commontypes.Pod, enabledCgroups map[int][]string, subcgroup string, serviceNames []string) error { mountContext := os.Getenv(common.EnvSELinuxMountContext) stage1Root := common.Stage1RootfsPath(p.Root) if err := v1.CreateCgroups(m, stage1Root, enabledCgroups, mountContext); err != nil { return errwrap.Wrap(errors.New("error creating container cgroups"), err) } if err := v1.RemountCgroups(m, stage1Root, enabledCgroups, subcgroup, p.InsecureOptions.DisablePaths); err != nil { return errwrap.Wrap(errors.New("error restricting container cgroups"), err) } return nil }
[ "func", "mountContainerV1Cgroups", "(", "m", "fs", ".", "Mounter", ",", "p", "*", "stage1commontypes", ".", "Pod", ",", "enabledCgroups", "map", "[", "int", "]", "[", "]", "string", ",", "subcgroup", "string", ",", "serviceNames", "[", "]", "string", ")", "error", "{", "mountContext", ":=", "os", ".", "Getenv", "(", "common", ".", "EnvSELinuxMountContext", ")", "\n", "stage1Root", ":=", "common", ".", "Stage1RootfsPath", "(", "p", ".", "Root", ")", "\n", "if", "err", ":=", "v1", ".", "CreateCgroups", "(", "m", ",", "stage1Root", ",", "enabledCgroups", ",", "mountContext", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "v1", ".", "RemountCgroups", "(", "m", ",", "stage1Root", ",", "enabledCgroups", ",", "subcgroup", ",", "p", ".", "InsecureOptions", ".", "DisablePaths", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// mountContainerV1Cgroups mounts the cgroup controllers hierarchy in the container's // namespace read-only, leaving the needed knobs in the subcgroup for each-app // read-write so systemd inside stage1 can apply isolators to them
[ "mountContainerV1Cgroups", "mounts", "the", "cgroup", "controllers", "hierarchy", "in", "the", "container", "s", "namespace", "read", "-", "only", "leaving", "the", "needed", "knobs", "in", "the", "subcgroup", "for", "each", "-", "app", "read", "-", "write", "so", "systemd", "inside", "stage1", "can", "apply", "isolators", "to", "them" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/init.go#L843-L855
167,118
rkt/rkt
common/networking/ports.go
findAppPort
func findAppPort(manifest *schema.PodManifest, portName types.ACName) (*types.Port, error) { var foundPort *types.Port for _, app := range manifest.Apps { for _, port := range app.App.Ports { if portName == port.Name { if foundPort != nil { // error: ambiguous return nil, fmt.Errorf("port name %q defined multiple apps", portName) } p := port // duplicate b/c port gets overwritten foundPort = &p } } } return foundPort, nil }
go
func findAppPort(manifest *schema.PodManifest, portName types.ACName) (*types.Port, error) { var foundPort *types.Port for _, app := range manifest.Apps { for _, port := range app.App.Ports { if portName == port.Name { if foundPort != nil { // error: ambiguous return nil, fmt.Errorf("port name %q defined multiple apps", portName) } p := port // duplicate b/c port gets overwritten foundPort = &p } } } return foundPort, nil }
[ "func", "findAppPort", "(", "manifest", "*", "schema", ".", "PodManifest", ",", "portName", "types", ".", "ACName", ")", "(", "*", "types", ".", "Port", ",", "error", ")", "{", "var", "foundPort", "*", "types", ".", "Port", "\n\n", "for", "_", ",", "app", ":=", "range", "manifest", ".", "Apps", "{", "for", "_", ",", "port", ":=", "range", "app", ".", "App", ".", "Ports", "{", "if", "portName", "==", "port", ".", "Name", "{", "if", "foundPort", "!=", "nil", "{", "// error: ambiguous", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "portName", ")", "\n", "}", "\n", "p", ":=", "port", "// duplicate b/c port gets overwritten", "\n", "foundPort", "=", "&", "p", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "foundPort", ",", "nil", "\n", "}" ]
// findAppPort looks through the manifest to find a port with a given name. // If multiple apps expose the same port name, it will fail
[ "findAppPort", "looks", "through", "the", "manifest", "to", "find", "a", "port", "with", "a", "given", "name", ".", "If", "multiple", "apps", "expose", "the", "same", "port", "name", "it", "will", "fail" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/networking/ports.go#L34-L49
167,119
rkt/rkt
common/networking/ports.go
conflicts
func (fp *ForwardedPort) conflicts(fp1 *ForwardedPort) bool { if fp.PodPort.Protocol != fp1.PodPort.Protocol { return false } if fp.HostPort.HostPort != fp1.HostPort.HostPort { return false } // If either port has the 0.0.0.0 address, they conflict zeroAddr := net.IPv4(0, 0, 0, 0) if fp.HostPort.HostIP.Equal(zeroAddr) || fp1.HostPort.HostIP.Equal(zeroAddr) { return true } if fp.HostPort.HostIP.Equal(fp1.HostPort.HostIP) { return true } return false }
go
func (fp *ForwardedPort) conflicts(fp1 *ForwardedPort) bool { if fp.PodPort.Protocol != fp1.PodPort.Protocol { return false } if fp.HostPort.HostPort != fp1.HostPort.HostPort { return false } // If either port has the 0.0.0.0 address, they conflict zeroAddr := net.IPv4(0, 0, 0, 0) if fp.HostPort.HostIP.Equal(zeroAddr) || fp1.HostPort.HostIP.Equal(zeroAddr) { return true } if fp.HostPort.HostIP.Equal(fp1.HostPort.HostIP) { return true } return false }
[ "func", "(", "fp", "*", "ForwardedPort", ")", "conflicts", "(", "fp1", "*", "ForwardedPort", ")", "bool", "{", "if", "fp", ".", "PodPort", ".", "Protocol", "!=", "fp1", ".", "PodPort", ".", "Protocol", "{", "return", "false", "\n", "}", "\n\n", "if", "fp", ".", "HostPort", ".", "HostPort", "!=", "fp1", ".", "HostPort", ".", "HostPort", "{", "return", "false", "\n", "}", "\n\n", "// If either port has the 0.0.0.0 address, they conflict", "zeroAddr", ":=", "net", ".", "IPv4", "(", "0", ",", "0", ",", "0", ",", "0", ")", "\n", "if", "fp", ".", "HostPort", ".", "HostIP", ".", "Equal", "(", "zeroAddr", ")", "||", "fp1", ".", "HostPort", ".", "HostIP", ".", "Equal", "(", "zeroAddr", ")", "{", "return", "true", "\n", "}", "\n\n", "if", "fp", ".", "HostPort", ".", "HostIP", ".", "Equal", "(", "fp1", ".", "HostPort", ".", "HostIP", ")", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// conflicts checks if two ports conflict with each other
[ "conflicts", "checks", "if", "two", "ports", "conflict", "with", "each", "other" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/networking/ports.go#L99-L119
167,120
rkt/rkt
pkg/flag/pairlist.go
SetOne
func (pl *PairList) SetOne(key, val string) error { // Check that key is allowed if len(pl.permissible) > 0 { permVals, ok := pl.permissible[key] if !ok { return fmt.Errorf("key %v is not allowed", key) } // Check that value is allowed if len(permVals) > 0 { _, ok = permVals[val] if !ok { return fmt.Errorf("key %v does not allow value %v", key, val) } } } pl.Pairs[key] = val return nil }
go
func (pl *PairList) SetOne(key, val string) error { // Check that key is allowed if len(pl.permissible) > 0 { permVals, ok := pl.permissible[key] if !ok { return fmt.Errorf("key %v is not allowed", key) } // Check that value is allowed if len(permVals) > 0 { _, ok = permVals[val] if !ok { return fmt.Errorf("key %v does not allow value %v", key, val) } } } pl.Pairs[key] = val return nil }
[ "func", "(", "pl", "*", "PairList", ")", "SetOne", "(", "key", ",", "val", "string", ")", "error", "{", "// Check that key is allowed", "if", "len", "(", "pl", ".", "permissible", ")", ">", "0", "{", "permVals", ",", "ok", ":=", "pl", ".", "permissible", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n\n", "// Check that value is allowed", "if", "len", "(", "permVals", ")", ">", "0", "{", "_", ",", "ok", "=", "permVals", "[", "val", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "val", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "pl", ".", "Pairs", "[", "key", "]", "=", "val", "\n", "return", "nil", "\n", "}" ]
// SetOne validates and sets an individual key-value pair // It will overwrite an existing value
[ "SetOne", "validates", "and", "sets", "an", "individual", "key", "-", "value", "pair", "It", "will", "overwrite", "an", "existing", "value" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/flag/pairlist.go#L97-L116
167,121
rkt/rkt
pkg/flag/pairlist.go
Keys
func (pl *PairList) Keys() []string { keys := make([]string, 0, len(pl.Pairs)) for k := range pl.Pairs { keys = append(keys, k) } sort.Strings(keys) return keys }
go
func (pl *PairList) Keys() []string { keys := make([]string, 0, len(pl.Pairs)) for k := range pl.Pairs { keys = append(keys, k) } sort.Strings(keys) return keys }
[ "func", "(", "pl", "*", "PairList", ")", "Keys", "(", ")", "[", "]", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "pl", ".", "Pairs", ")", ")", "\n", "for", "k", ":=", "range", "pl", ".", "Pairs", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "return", "keys", "\n", "}" ]
// Keys returns a sorted list of all present keys
[ "Keys", "returns", "a", "sorted", "list", "of", "all", "present", "keys" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/flag/pairlist.go#L119-L126
167,122
rkt/rkt
pkg/flag/pairlist.go
String
func (pl *PairList) String() string { ps := make([]string, 0, len(pl.Pairs)) for _, k := range pl.Keys() { ps = append(ps, fmt.Sprintf("%v=%v", k, pl.Pairs[k])) } return strings.Join(ps, " ") }
go
func (pl *PairList) String() string { ps := make([]string, 0, len(pl.Pairs)) for _, k := range pl.Keys() { ps = append(ps, fmt.Sprintf("%v=%v", k, pl.Pairs[k])) } return strings.Join(ps, " ") }
[ "func", "(", "pl", "*", "PairList", ")", "String", "(", ")", "string", "{", "ps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "pl", ".", "Pairs", ")", ")", "\n", "for", "_", ",", "k", ":=", "range", "pl", ".", "Keys", "(", ")", "{", "ps", "=", "append", "(", "ps", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "pl", ".", "Pairs", "[", "k", "]", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "ps", ",", "\"", "\"", ")", "\n", "}" ]
// String presents a k=v list in key=sorted order
[ "String", "presents", "a", "k", "=", "v", "list", "in", "key", "=", "sorted", "order" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/flag/pairlist.go#L129-L135
167,123
rkt/rkt
pkg/flag/pairlist.go
SerializePairs
func SerializePairs(pairs map[string]string) string { tmp := make([]string, 0, len(pairs)) for k, v := range pairs { tmp = append(tmp, fmt.Sprintf("%s=%s", k, v)) } return strings.Join(tmp, ",") }
go
func SerializePairs(pairs map[string]string) string { tmp := make([]string, 0, len(pairs)) for k, v := range pairs { tmp = append(tmp, fmt.Sprintf("%s=%s", k, v)) } return strings.Join(tmp, ",") }
[ "func", "SerializePairs", "(", "pairs", "map", "[", "string", "]", "string", ")", "string", "{", "tmp", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "pairs", ")", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "pairs", "{", "tmp", "=", "append", "(", "tmp", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "tmp", ",", "\"", "\"", ")", "\n", "}" ]
// Serialize takes a map and generates a string that can be parsed by Set
[ "Serialize", "takes", "a", "map", "and", "generates", "a", "string", "that", "can", "be", "parsed", "by", "Set" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/flag/pairlist.go#L172-L179
167,124
rkt/rkt
pkg/tar/chroot.go
extractTarCommand
func extractTarCommand() error { if len(os.Args) != 5 { return fmt.Errorf("incorrect number of arguments. Usage: %s DIR {true|false} uidShift uidCount", multicallName) } if !sys.HasChrootCapability() { return fmt.Errorf("chroot capability not available.") } dir := os.Args[1] if !filepath.IsAbs(dir) { return fmt.Errorf("dir %s must be an absolute path", dir) } overwrite, err := strconv.ParseBool(os.Args[2]) if err != nil { return fmt.Errorf("error parsing overwrite argument: %v", err) } us, err := strconv.ParseUint(os.Args[3], 10, 32) if err != nil { return fmt.Errorf("error parsing uidShift argument: %v", err) } uc, err := strconv.ParseUint(os.Args[4], 10, 32) if err != nil { return fmt.Errorf("error parsing uidCount argument: %v", err) } uidRange := &user.UidRange{Shift: uint32(us), Count: uint32(uc)} if err := syscall.Chroot(dir); err != nil { return fmt.Errorf("failed to chroot in %s: %v", dir, err) } if err := syscall.Chdir("/"); err != nil { return fmt.Errorf("failed to chdir: %v", err) } fileMapFile := os.NewFile(uintptr(fileMapFdNum), "fileMap") fileMap := map[string]struct{}{} if err := json.NewDecoder(fileMapFile).Decode(&fileMap); err != nil { return fmt.Errorf("error decoding fileMap: %v", err) } editor, err := NewUidShiftingFilePermEditor(uidRange) if err != nil { return fmt.Errorf("error determining current user: %v", err) } if err := ExtractTarInsecure(tar.NewReader(os.Stdin), "/", overwrite, fileMap, editor); err != nil { return fmt.Errorf("error extracting tar: %v", err) } // flush remaining bytes io.Copy(ioutil.Discard, os.Stdin) return nil }
go
func extractTarCommand() error { if len(os.Args) != 5 { return fmt.Errorf("incorrect number of arguments. Usage: %s DIR {true|false} uidShift uidCount", multicallName) } if !sys.HasChrootCapability() { return fmt.Errorf("chroot capability not available.") } dir := os.Args[1] if !filepath.IsAbs(dir) { return fmt.Errorf("dir %s must be an absolute path", dir) } overwrite, err := strconv.ParseBool(os.Args[2]) if err != nil { return fmt.Errorf("error parsing overwrite argument: %v", err) } us, err := strconv.ParseUint(os.Args[3], 10, 32) if err != nil { return fmt.Errorf("error parsing uidShift argument: %v", err) } uc, err := strconv.ParseUint(os.Args[4], 10, 32) if err != nil { return fmt.Errorf("error parsing uidCount argument: %v", err) } uidRange := &user.UidRange{Shift: uint32(us), Count: uint32(uc)} if err := syscall.Chroot(dir); err != nil { return fmt.Errorf("failed to chroot in %s: %v", dir, err) } if err := syscall.Chdir("/"); err != nil { return fmt.Errorf("failed to chdir: %v", err) } fileMapFile := os.NewFile(uintptr(fileMapFdNum), "fileMap") fileMap := map[string]struct{}{} if err := json.NewDecoder(fileMapFile).Decode(&fileMap); err != nil { return fmt.Errorf("error decoding fileMap: %v", err) } editor, err := NewUidShiftingFilePermEditor(uidRange) if err != nil { return fmt.Errorf("error determining current user: %v", err) } if err := ExtractTarInsecure(tar.NewReader(os.Stdin), "/", overwrite, fileMap, editor); err != nil { return fmt.Errorf("error extracting tar: %v", err) } // flush remaining bytes io.Copy(ioutil.Discard, os.Stdin) return nil }
[ "func", "extractTarCommand", "(", ")", "error", "{", "if", "len", "(", "os", ".", "Args", ")", "!=", "5", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "multicallName", ")", "\n", "}", "\n", "if", "!", "sys", ".", "HasChrootCapability", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "dir", ":=", "os", ".", "Args", "[", "1", "]", "\n", "if", "!", "filepath", ".", "IsAbs", "(", "dir", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ")", "\n", "}", "\n", "overwrite", ",", "err", ":=", "strconv", ".", "ParseBool", "(", "os", ".", "Args", "[", "2", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "us", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "os", ".", "Args", "[", "3", "]", ",", "10", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "uc", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "os", ".", "Args", "[", "4", "]", ",", "10", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "uidRange", ":=", "&", "user", ".", "UidRange", "{", "Shift", ":", "uint32", "(", "us", ")", ",", "Count", ":", "uint32", "(", "uc", ")", "}", "\n\n", "if", "err", ":=", "syscall", ".", "Chroot", "(", "dir", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dir", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "syscall", ".", "Chdir", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "fileMapFile", ":=", "os", ".", "NewFile", "(", "uintptr", "(", "fileMapFdNum", ")", ",", "\"", "\"", ")", "\n\n", "fileMap", ":=", "map", "[", "string", "]", "struct", "{", "}", "{", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "fileMapFile", ")", ".", "Decode", "(", "&", "fileMap", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "editor", ",", "err", ":=", "NewUidShiftingFilePermEditor", "(", "uidRange", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "ExtractTarInsecure", "(", "tar", ".", "NewReader", "(", "os", ".", "Stdin", ")", ",", "\"", "\"", ",", "overwrite", ",", "fileMap", ",", "editor", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// flush remaining bytes", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "os", ".", "Stdin", ")", "\n\n", "return", "nil", "\n", "}" ]
// Because this function is executed by multicall in a different process, it is not possible to use errwrap to return errors
[ "Because", "this", "function", "is", "executed", "by", "multicall", "in", "a", "different", "process", "it", "is", "not", "possible", "to", "use", "errwrap", "to", "return", "errors" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/tar/chroot.go#L47-L98
167,125
rkt/rkt
pkg/distribution/docker.go
NewDocker
func NewDocker(u *url.URL) (Distribution, error) { dp, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("cannot parse URI: %q: %v", u.String(), err) } if dp.Type != TypeDocker { return nil, fmt.Errorf("wrong distribution type: %q", dp.Type) } parsed, err := d2acommon.ParseDockerURL(dp.Data) if err != nil { return nil, fmt.Errorf("bad docker URL %q: %v", dp.Data, err) } return &Docker{ url: dp.Data, parsedURL: parsed, simple: SimpleDockerRef(parsed), full: FullDockerRef(parsed), }, nil }
go
func NewDocker(u *url.URL) (Distribution, error) { dp, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("cannot parse URI: %q: %v", u.String(), err) } if dp.Type != TypeDocker { return nil, fmt.Errorf("wrong distribution type: %q", dp.Type) } parsed, err := d2acommon.ParseDockerURL(dp.Data) if err != nil { return nil, fmt.Errorf("bad docker URL %q: %v", dp.Data, err) } return &Docker{ url: dp.Data, parsedURL: parsed, simple: SimpleDockerRef(parsed), full: FullDockerRef(parsed), }, nil }
[ "func", "NewDocker", "(", "u", "*", "url", ".", "URL", ")", "(", "Distribution", ",", "error", ")", "{", "dp", ",", "err", ":=", "parseCIMD", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "err", ")", "\n", "}", "\n", "if", "dp", ".", "Type", "!=", "TypeDocker", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dp", ".", "Type", ")", "\n", "}", "\n\n", "parsed", ",", "err", ":=", "d2acommon", ".", "ParseDockerURL", "(", "dp", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dp", ".", "Data", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "Docker", "{", "url", ":", "dp", ".", "Data", ",", "parsedURL", ":", "parsed", ",", "simple", ":", "SimpleDockerRef", "(", "parsed", ")", ",", "full", ":", "FullDockerRef", "(", "parsed", ")", ",", "}", ",", "nil", "\n", "}" ]
// NewDocker creates a new docker distribution from the provided distribution uri string
[ "NewDocker", "creates", "a", "new", "docker", "distribution", "from", "the", "provided", "distribution", "uri", "string" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/docker.go#L58-L78
167,126
rkt/rkt
stage1/init/common/pod.go
execEscape
func execEscape(i int, str string) string { escapeMap := map[string]string{ `'`: `\`, } if i > 0 { // These are escaped only after the first argument escapeMap[`$`] = `$` escapeMap[`%`] = `%` } escArg := fmt.Sprintf("%q", str) for k := range escapeMap { reStr := `([` + regexp.QuoteMeta(k) + `])` re := regexp.MustCompile(reStr) escArg = re.ReplaceAllStringFunc(escArg, func(s string) string { escaped := escapeMap[s] + s return escaped }) } return escArg }
go
func execEscape(i int, str string) string { escapeMap := map[string]string{ `'`: `\`, } if i > 0 { // These are escaped only after the first argument escapeMap[`$`] = `$` escapeMap[`%`] = `%` } escArg := fmt.Sprintf("%q", str) for k := range escapeMap { reStr := `([` + regexp.QuoteMeta(k) + `])` re := regexp.MustCompile(reStr) escArg = re.ReplaceAllStringFunc(escArg, func(s string) string { escaped := escapeMap[s] + s return escaped }) } return escArg }
[ "func", "execEscape", "(", "i", "int", ",", "str", "string", ")", "string", "{", "escapeMap", ":=", "map", "[", "string", "]", "string", "{", "`'`", ":", "`\\`", ",", "}", "\n\n", "if", "i", ">", "0", "{", "// These are escaped only after the first argument", "escapeMap", "[", "`$`", "]", "=", "`$`", "\n", "escapeMap", "[", "`%`", "]", "=", "`%`", "\n", "}", "\n\n", "escArg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "str", ")", "\n", "for", "k", ":=", "range", "escapeMap", "{", "reStr", ":=", "`([`", "+", "regexp", ".", "QuoteMeta", "(", "k", ")", "+", "`])`", "\n", "re", ":=", "regexp", ".", "MustCompile", "(", "reStr", ")", "\n", "escArg", "=", "re", ".", "ReplaceAllStringFunc", "(", "escArg", ",", "func", "(", "s", "string", ")", "string", "{", "escaped", ":=", "escapeMap", "[", "s", "]", "+", "s", "\n", "return", "escaped", "\n", "}", ")", "\n", "}", "\n", "return", "escArg", "\n", "}" ]
// execEscape uses Golang's string quoting for ", \, \n, and regex for special cases
[ "execEscape", "uses", "Golang", "s", "string", "quoting", "for", "\\", "\\", "n", "and", "regex", "for", "special", "cases" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L51-L71
167,127
rkt/rkt
stage1/init/common/pod.go
quoteExec
func quoteExec(exec []string) string { if len(exec) == 0 { // existing callers always include at least the binary so this shouldn't occur. panic("empty exec") } var qexec []string for i, arg := range exec { escArg := execEscape(i, arg) qexec = append(qexec, escArg) } return strings.Join(qexec, " ") }
go
func quoteExec(exec []string) string { if len(exec) == 0 { // existing callers always include at least the binary so this shouldn't occur. panic("empty exec") } var qexec []string for i, arg := range exec { escArg := execEscape(i, arg) qexec = append(qexec, escArg) } return strings.Join(qexec, " ") }
[ "func", "quoteExec", "(", "exec", "[", "]", "string", ")", "string", "{", "if", "len", "(", "exec", ")", "==", "0", "{", "// existing callers always include at least the binary so this shouldn't occur.", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "qexec", "[", "]", "string", "\n", "for", "i", ",", "arg", ":=", "range", "exec", "{", "escArg", ":=", "execEscape", "(", "i", ",", "arg", ")", "\n", "qexec", "=", "append", "(", "qexec", ",", "escArg", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "qexec", ",", "\"", "\"", ")", "\n", "}" ]
// quoteExec returns an array of quoted strings appropriate for systemd execStart usage
[ "quoteExec", "returns", "an", "array", "of", "quoted", "strings", "appropriate", "for", "systemd", "execStart", "usage" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L74-L86
167,128
rkt/rkt
stage1/init/common/pod.go
SetJournalPermissions
func SetJournalPermissions(p *stage1commontypes.Pod) error { s1 := common.Stage1ImagePath(p.Root) rktgid, err := common.LookupGid(common.RktGroup) if err != nil { return fmt.Errorf("group %q not found", common.RktGroup) } journalPath := filepath.Join(s1, "rootfs", "var", "log", "journal") if err := os.MkdirAll(journalPath, os.FileMode(0755)); err != nil { return errwrap.Wrap(errors.New("error creating journal dir"), err) } a, err := acl.InitACL() if err != nil { return err } defer a.Free() if err := a.ParseACL(fmt.Sprintf("g:%d:r-x,m:r-x", rktgid)); err != nil { return errwrap.Wrap(errors.New("error parsing ACL string"), err) } if err := a.AddBaseEntries(journalPath); err != nil { return errwrap.Wrap(errors.New("error adding base ACL entries"), err) } if err := a.Valid(); err != nil { return err } if err := a.SetFileACLDefault(journalPath); err != nil { return errwrap.Wrap(fmt.Errorf("error setting default ACLs on %q", journalPath), err) } return nil }
go
func SetJournalPermissions(p *stage1commontypes.Pod) error { s1 := common.Stage1ImagePath(p.Root) rktgid, err := common.LookupGid(common.RktGroup) if err != nil { return fmt.Errorf("group %q not found", common.RktGroup) } journalPath := filepath.Join(s1, "rootfs", "var", "log", "journal") if err := os.MkdirAll(journalPath, os.FileMode(0755)); err != nil { return errwrap.Wrap(errors.New("error creating journal dir"), err) } a, err := acl.InitACL() if err != nil { return err } defer a.Free() if err := a.ParseACL(fmt.Sprintf("g:%d:r-x,m:r-x", rktgid)); err != nil { return errwrap.Wrap(errors.New("error parsing ACL string"), err) } if err := a.AddBaseEntries(journalPath); err != nil { return errwrap.Wrap(errors.New("error adding base ACL entries"), err) } if err := a.Valid(); err != nil { return err } if err := a.SetFileACLDefault(journalPath); err != nil { return errwrap.Wrap(fmt.Errorf("error setting default ACLs on %q", journalPath), err) } return nil }
[ "func", "SetJournalPermissions", "(", "p", "*", "stage1commontypes", ".", "Pod", ")", "error", "{", "s1", ":=", "common", ".", "Stage1ImagePath", "(", "p", ".", "Root", ")", "\n\n", "rktgid", ",", "err", ":=", "common", ".", "LookupGid", "(", "common", ".", "RktGroup", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "common", ".", "RktGroup", ")", "\n", "}", "\n\n", "journalPath", ":=", "filepath", ".", "Join", "(", "s1", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "journalPath", ",", "os", ".", "FileMode", "(", "0755", ")", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "a", ",", "err", ":=", "acl", ".", "InitACL", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "a", ".", "Free", "(", ")", "\n\n", "if", "err", ":=", "a", ".", "ParseACL", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "rktgid", ")", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "a", ".", "AddBaseEntries", "(", "journalPath", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "a", ".", "Valid", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "a", ".", "SetFileACLDefault", "(", "journalPath", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "journalPath", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetJournalPermissions sets ACLs and permissions so the rkt group can access // the pod's logs
[ "SetJournalPermissions", "sets", "ACLs", "and", "permissions", "so", "the", "rkt", "group", "can", "access", "the", "pod", "s", "logs" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L118-L154
167,129
rkt/rkt
stage1/init/common/pod.go
findHostPort
func findHostPort(pm schema.PodManifest, name types.ACName) uint { var port uint for _, p := range pm.Ports { if p.Name == name { port = p.HostPort } } return port }
go
func findHostPort(pm schema.PodManifest, name types.ACName) uint { var port uint for _, p := range pm.Ports { if p.Name == name { port = p.HostPort } } return port }
[ "func", "findHostPort", "(", "pm", "schema", ".", "PodManifest", ",", "name", "types", ".", "ACName", ")", "uint", "{", "var", "port", "uint", "\n", "for", "_", ",", "p", ":=", "range", "pm", ".", "Ports", "{", "if", "p", ".", "Name", "==", "name", "{", "port", "=", "p", ".", "HostPort", "\n", "}", "\n", "}", "\n", "return", "port", "\n", "}" ]
// findHostPort returns the port number on the host that corresponds to an // image manifest port identified by name
[ "findHostPort", "returns", "the", "port", "number", "on", "the", "host", "that", "corresponds", "to", "an", "image", "manifest", "port", "identified", "by", "name" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L166-L174
167,130
rkt/rkt
stage1/init/common/pod.go
appSearchPaths
func appSearchPaths(p *stage1commontypes.Pod, workDir string, app types.App) []string { appEnv := app.Environment if imgPath, ok := appEnv.Get("PATH"); ok { return strings.Split(imgPath, ":") } // emulate exec(3) behavior, first check working directory and then the // list of directories returned by confstr(_CS_PATH). That's typically // "/bin:/usr/bin" so let's use that. return []string{workDir, "/bin", "/usr/bin"} }
go
func appSearchPaths(p *stage1commontypes.Pod, workDir string, app types.App) []string { appEnv := app.Environment if imgPath, ok := appEnv.Get("PATH"); ok { return strings.Split(imgPath, ":") } // emulate exec(3) behavior, first check working directory and then the // list of directories returned by confstr(_CS_PATH). That's typically // "/bin:/usr/bin" so let's use that. return []string{workDir, "/bin", "/usr/bin"} }
[ "func", "appSearchPaths", "(", "p", "*", "stage1commontypes", ".", "Pod", ",", "workDir", "string", ",", "app", "types", ".", "App", ")", "[", "]", "string", "{", "appEnv", ":=", "app", ".", "Environment", "\n\n", "if", "imgPath", ",", "ok", ":=", "appEnv", ".", "Get", "(", "\"", "\"", ")", ";", "ok", "{", "return", "strings", ".", "Split", "(", "imgPath", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// emulate exec(3) behavior, first check working directory and then the", "// list of directories returned by confstr(_CS_PATH). That's typically", "// \"/bin:/usr/bin\" so let's use that.", "return", "[", "]", "string", "{", "workDir", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "}" ]
// appSearchPaths returns a list of paths where we should search for // non-absolute exec binaries
[ "appSearchPaths", "returns", "a", "list", "of", "paths", "where", "we", "should", "search", "for", "non", "-", "absolute", "exec", "binaries" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L251-L262
167,131
rkt/rkt
stage1/init/common/pod.go
FindBinPath
func FindBinPath(p *stage1commontypes.Pod, ra *schema.RuntimeApp) (string, error) { if len(ra.App.Exec) == 0 { return "", errors.New("app has no executable") } bin := ra.App.Exec[0] var binPath string switch { // absolute path, just use it case filepath.IsAbs(bin): binPath = bin // non-absolute path containing a slash, look in the working dir case strings.Contains(bin, "/"): binPath = filepath.Join(ra.App.WorkingDirectory, bin) // filename, search in the app's $PATH default: absRoot, err := filepath.Abs(p.Root) if err != nil { return "", errwrap.Wrap(errors.New("could not get pod's root absolute path"), err) } appRootfs := common.AppRootfsPath(absRoot, ra.Name) appPathDirs := appSearchPaths(p, ra.App.WorkingDirectory, *ra.App) appPath := strings.Join(appPathDirs, ":") binPath, err = lookupPathInsideApp(bin, appPath, appRootfs, ra.App.WorkingDirectory) if err != nil { return "", errwrap.Wrap(fmt.Errorf("error looking up %q", bin), err) } } return binPath, nil }
go
func FindBinPath(p *stage1commontypes.Pod, ra *schema.RuntimeApp) (string, error) { if len(ra.App.Exec) == 0 { return "", errors.New("app has no executable") } bin := ra.App.Exec[0] var binPath string switch { // absolute path, just use it case filepath.IsAbs(bin): binPath = bin // non-absolute path containing a slash, look in the working dir case strings.Contains(bin, "/"): binPath = filepath.Join(ra.App.WorkingDirectory, bin) // filename, search in the app's $PATH default: absRoot, err := filepath.Abs(p.Root) if err != nil { return "", errwrap.Wrap(errors.New("could not get pod's root absolute path"), err) } appRootfs := common.AppRootfsPath(absRoot, ra.Name) appPathDirs := appSearchPaths(p, ra.App.WorkingDirectory, *ra.App) appPath := strings.Join(appPathDirs, ":") binPath, err = lookupPathInsideApp(bin, appPath, appRootfs, ra.App.WorkingDirectory) if err != nil { return "", errwrap.Wrap(fmt.Errorf("error looking up %q", bin), err) } } return binPath, nil }
[ "func", "FindBinPath", "(", "p", "*", "stage1commontypes", ".", "Pod", ",", "ra", "*", "schema", ".", "RuntimeApp", ")", "(", "string", ",", "error", ")", "{", "if", "len", "(", "ra", ".", "App", ".", "Exec", ")", "==", "0", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "bin", ":=", "ra", ".", "App", ".", "Exec", "[", "0", "]", "\n\n", "var", "binPath", "string", "\n", "switch", "{", "// absolute path, just use it", "case", "filepath", ".", "IsAbs", "(", "bin", ")", ":", "binPath", "=", "bin", "\n", "// non-absolute path containing a slash, look in the working dir", "case", "strings", ".", "Contains", "(", "bin", ",", "\"", "\"", ")", ":", "binPath", "=", "filepath", ".", "Join", "(", "ra", ".", "App", ".", "WorkingDirectory", ",", "bin", ")", "\n", "// filename, search in the app's $PATH", "default", ":", "absRoot", ",", "err", ":=", "filepath", ".", "Abs", "(", "p", ".", "Root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "appRootfs", ":=", "common", ".", "AppRootfsPath", "(", "absRoot", ",", "ra", ".", "Name", ")", "\n", "appPathDirs", ":=", "appSearchPaths", "(", "p", ",", "ra", ".", "App", ".", "WorkingDirectory", ",", "*", "ra", ".", "App", ")", "\n", "appPath", ":=", "strings", ".", "Join", "(", "appPathDirs", ",", "\"", "\"", ")", "\n\n", "binPath", ",", "err", "=", "lookupPathInsideApp", "(", "bin", ",", "appPath", ",", "appRootfs", ",", "ra", ".", "App", ".", "WorkingDirectory", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "bin", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "binPath", ",", "nil", "\n", "}" ]
// FindBinPath takes a binary path and returns a the absolute path of the // binary relative to the app rootfs. This can be passed to ExecStart on the // app's systemd service file directly.
[ "FindBinPath", "takes", "a", "binary", "path", "and", "returns", "a", "the", "absolute", "path", "of", "the", "binary", "relative", "to", "the", "app", "rootfs", ".", "This", "can", "be", "passed", "to", "ExecStart", "on", "the", "app", "s", "systemd", "service", "file", "directly", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L267-L299
167,132
rkt/rkt
stage1/init/common/pod.go
EvaluateSymlinksInsideApp
func EvaluateSymlinksInsideApp(appRootfs, path string) (string, error) { chroot, err := newChroot(appRootfs) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("chroot to %q failed", appRootfs), err) } target, err := fileutil.EvalSymlinksAlways(path) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("evaluating symlinks of %q failed", path), err) } // EvalSymlinksAlways might return a relative path abs, err := filepath.Abs(target) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("failed to get absolute representation of %q", target), err) } if err := chroot.escape(); err != nil { return "", errwrap.Wrapf(fmt.Sprintf("escaping chroot %q failed", appRootfs), err) } return abs, nil }
go
func EvaluateSymlinksInsideApp(appRootfs, path string) (string, error) { chroot, err := newChroot(appRootfs) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("chroot to %q failed", appRootfs), err) } target, err := fileutil.EvalSymlinksAlways(path) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("evaluating symlinks of %q failed", path), err) } // EvalSymlinksAlways might return a relative path abs, err := filepath.Abs(target) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("failed to get absolute representation of %q", target), err) } if err := chroot.escape(); err != nil { return "", errwrap.Wrapf(fmt.Sprintf("escaping chroot %q failed", appRootfs), err) } return abs, nil }
[ "func", "EvaluateSymlinksInsideApp", "(", "appRootfs", ",", "path", "string", ")", "(", "string", ",", "error", ")", "{", "chroot", ",", "err", ":=", "newChroot", "(", "appRootfs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrapf", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "appRootfs", ")", ",", "err", ")", "\n", "}", "\n\n", "target", ",", "err", ":=", "fileutil", ".", "EvalSymlinksAlways", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrapf", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "path", ")", ",", "err", ")", "\n", "}", "\n\n", "// EvalSymlinksAlways might return a relative path", "abs", ",", "err", ":=", "filepath", ".", "Abs", "(", "target", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrapf", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "target", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "chroot", ".", "escape", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrapf", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "appRootfs", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "abs", ",", "nil", "\n", "}" ]
// EvaluateSymlinksInsideApp tries to resolve symlinks within the path. // It returns the actual path relative to the app rootfs for the given path. // This is needed for absolute symlinks - we are in a different rootfs.
[ "EvaluateSymlinksInsideApp", "tries", "to", "resolve", "symlinks", "within", "the", "path", ".", "It", "returns", "the", "actual", "path", "relative", "to", "the", "app", "rootfs", "for", "the", "given", "path", ".", "This", "is", "needed", "for", "absolute", "symlinks", "-", "we", "are", "in", "a", "different", "rootfs", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L434-L456
167,133
rkt/rkt
stage1/init/common/pod.go
PodToNspawnArgs
func PodToNspawnArgs(p *stage1commontypes.Pod) ([]string, error) { args := []string{ "--uuid=" + p.UUID.String(), "--machine=" + GetMachineID(p), "--directory=" + common.Stage1RootfsPath(p.Root), } for i := range p.Manifest.Apps { aa, err := appToNspawnArgs(p, &p.Manifest.Apps[i]) if err != nil { return nil, err } args = append(args, aa...) } if p.InsecureOptions.DisableCapabilities { args = append(args, "--capability=all") } return args, nil }
go
func PodToNspawnArgs(p *stage1commontypes.Pod) ([]string, error) { args := []string{ "--uuid=" + p.UUID.String(), "--machine=" + GetMachineID(p), "--directory=" + common.Stage1RootfsPath(p.Root), } for i := range p.Manifest.Apps { aa, err := appToNspawnArgs(p, &p.Manifest.Apps[i]) if err != nil { return nil, err } args = append(args, aa...) } if p.InsecureOptions.DisableCapabilities { args = append(args, "--capability=all") } return args, nil }
[ "func", "PodToNspawnArgs", "(", "p", "*", "stage1commontypes", ".", "Pod", ")", "(", "[", "]", "string", ",", "error", ")", "{", "args", ":=", "[", "]", "string", "{", "\"", "\"", "+", "p", ".", "UUID", ".", "String", "(", ")", ",", "\"", "\"", "+", "GetMachineID", "(", "p", ")", ",", "\"", "\"", "+", "common", ".", "Stage1RootfsPath", "(", "p", ".", "Root", ")", ",", "}", "\n\n", "for", "i", ":=", "range", "p", ".", "Manifest", ".", "Apps", "{", "aa", ",", "err", ":=", "appToNspawnArgs", "(", "p", ",", "&", "p", ".", "Manifest", ".", "Apps", "[", "i", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "args", "=", "append", "(", "args", ",", "aa", "...", ")", "\n", "}", "\n\n", "if", "p", ".", "InsecureOptions", ".", "DisableCapabilities", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "args", ",", "nil", "\n", "}" ]
// PodToNspawnArgs renders a prepared Pod as a systemd-nspawn // argument list ready to be executed
[ "PodToNspawnArgs", "renders", "a", "prepared", "Pod", "as", "a", "systemd", "-", "nspawn", "argument", "list", "ready", "to", "be", "executed" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L546-L566
167,134
rkt/rkt
stage1/init/common/pod.go
GetFlavor
func GetFlavor(p *stage1commontypes.Pod) (flavor string, systemdVersion int, err error) { flavor, err = os.Readlink(filepath.Join(common.Stage1RootfsPath(p.Root), "flavor")) if err != nil { return "", -1, errwrap.Wrap(errors.New("unable to determine stage1 flavor"), err) } if flavor == "host" { // This flavor does not contain systemd, parse "systemctl --version" systemctlBin, err := common.LookupPath("systemctl", os.Getenv("PATH")) if err != nil { return "", -1, err } systemdVersion, err := common.SystemdVersion(systemctlBin) if err != nil { return "", -1, errwrap.Wrap(errors.New("error finding systemctl version"), err) } return flavor, systemdVersion, nil } systemdVersionBytes, err := ioutil.ReadFile(filepath.Join(common.Stage1RootfsPath(p.Root), "systemd-version")) if err != nil { return "", -1, errwrap.Wrap(errors.New("unable to determine stage1's systemd version"), err) } systemdVersionString := strings.Trim(string(systemdVersionBytes), " \n") // systemdVersionString is either a tag name or a branch name. If it's a // tag name it's of the form "v229", remove the first character to get the // number. systemdVersion, err = strconv.Atoi(systemdVersionString[1:]) if err != nil { // If we get a syntax error, it means the parsing of the version string // of the form "v229" failed, set it to 0 to indicate we couldn't guess // it. if e, ok := err.(*strconv.NumError); ok && e.Err == strconv.ErrSyntax { systemdVersion = 0 } else { return "", -1, errwrap.Wrap(errors.New("error parsing stage1's systemd version"), err) } } return flavor, systemdVersion, nil }
go
func GetFlavor(p *stage1commontypes.Pod) (flavor string, systemdVersion int, err error) { flavor, err = os.Readlink(filepath.Join(common.Stage1RootfsPath(p.Root), "flavor")) if err != nil { return "", -1, errwrap.Wrap(errors.New("unable to determine stage1 flavor"), err) } if flavor == "host" { // This flavor does not contain systemd, parse "systemctl --version" systemctlBin, err := common.LookupPath("systemctl", os.Getenv("PATH")) if err != nil { return "", -1, err } systemdVersion, err := common.SystemdVersion(systemctlBin) if err != nil { return "", -1, errwrap.Wrap(errors.New("error finding systemctl version"), err) } return flavor, systemdVersion, nil } systemdVersionBytes, err := ioutil.ReadFile(filepath.Join(common.Stage1RootfsPath(p.Root), "systemd-version")) if err != nil { return "", -1, errwrap.Wrap(errors.New("unable to determine stage1's systemd version"), err) } systemdVersionString := strings.Trim(string(systemdVersionBytes), " \n") // systemdVersionString is either a tag name or a branch name. If it's a // tag name it's of the form "v229", remove the first character to get the // number. systemdVersion, err = strconv.Atoi(systemdVersionString[1:]) if err != nil { // If we get a syntax error, it means the parsing of the version string // of the form "v229" failed, set it to 0 to indicate we couldn't guess // it. if e, ok := err.(*strconv.NumError); ok && e.Err == strconv.ErrSyntax { systemdVersion = 0 } else { return "", -1, errwrap.Wrap(errors.New("error parsing stage1's systemd version"), err) } } return flavor, systemdVersion, nil }
[ "func", "GetFlavor", "(", "p", "*", "stage1commontypes", ".", "Pod", ")", "(", "flavor", "string", ",", "systemdVersion", "int", ",", "err", "error", ")", "{", "flavor", ",", "err", "=", "os", ".", "Readlink", "(", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "p", ".", "Root", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "flavor", "==", "\"", "\"", "{", "// This flavor does not contain systemd, parse \"systemctl --version\"", "systemctlBin", ",", "err", ":=", "common", ".", "LookupPath", "(", "\"", "\"", ",", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "err", "\n", "}", "\n\n", "systemdVersion", ",", "err", ":=", "common", ".", "SystemdVersion", "(", "systemctlBin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "flavor", ",", "systemdVersion", ",", "nil", "\n", "}", "\n\n", "systemdVersionBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "p", ".", "Root", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "systemdVersionString", ":=", "strings", ".", "Trim", "(", "string", "(", "systemdVersionBytes", ")", ",", "\"", "\\n", "\"", ")", "\n\n", "// systemdVersionString is either a tag name or a branch name. If it's a", "// tag name it's of the form \"v229\", remove the first character to get the", "// number.", "systemdVersion", ",", "err", "=", "strconv", ".", "Atoi", "(", "systemdVersionString", "[", "1", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "// If we get a syntax error, it means the parsing of the version string", "// of the form \"v229\" failed, set it to 0 to indicate we couldn't guess", "// it.", "if", "e", ",", "ok", ":=", "err", ".", "(", "*", "strconv", ".", "NumError", ")", ";", "ok", "&&", "e", ".", "Err", "==", "strconv", ".", "ErrSyntax", "{", "systemdVersion", "=", "0", "\n", "}", "else", "{", "return", "\"", "\"", ",", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "flavor", ",", "systemdVersion", ",", "nil", "\n", "}" ]
// GetFlavor populates a flavor string based on the flavor itself and respectively the systemd version // If the systemd version couldn't be guessed, it will be set to 0.
[ "GetFlavor", "populates", "a", "flavor", "string", "based", "on", "the", "flavor", "itself", "and", "respectively", "the", "systemd", "version", "If", "the", "systemd", "version", "couldn", "t", "be", "guessed", "it", "will", "be", "set", "to", "0", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L570-L612
167,135
rkt/rkt
stage1/init/common/pod.go
GetAppHashes
func GetAppHashes(p *stage1commontypes.Pod) []types.Hash { var names []types.Hash for _, a := range p.Manifest.Apps { names = append(names, a.Image.ID) } return names }
go
func GetAppHashes(p *stage1commontypes.Pod) []types.Hash { var names []types.Hash for _, a := range p.Manifest.Apps { names = append(names, a.Image.ID) } return names }
[ "func", "GetAppHashes", "(", "p", "*", "stage1commontypes", ".", "Pod", ")", "[", "]", "types", ".", "Hash", "{", "var", "names", "[", "]", "types", ".", "Hash", "\n", "for", "_", ",", "a", ":=", "range", "p", ".", "Manifest", ".", "Apps", "{", "names", "=", "append", "(", "names", ",", "a", ".", "Image", ".", "ID", ")", "\n", "}", "\n\n", "return", "names", "\n", "}" ]
// GetAppHashes returns a list of hashes of the apps in this pod
[ "GetAppHashes", "returns", "a", "list", "of", "hashes", "of", "the", "apps", "in", "this", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L615-L622
167,136
rkt/rkt
stage1/init/common/pod.go
parseLinuxCapabilitiesSet
func parseLinuxCapabilitiesSet(capSet types.LinuxCapabilitiesSet) []string { var capsStr []string for _, cap := range capSet.Set() { capsStr = append(capsStr, string(cap)) } return capsStr }
go
func parseLinuxCapabilitiesSet(capSet types.LinuxCapabilitiesSet) []string { var capsStr []string for _, cap := range capSet.Set() { capsStr = append(capsStr, string(cap)) } return capsStr }
[ "func", "parseLinuxCapabilitiesSet", "(", "capSet", "types", ".", "LinuxCapabilitiesSet", ")", "[", "]", "string", "{", "var", "capsStr", "[", "]", "string", "\n", "for", "_", ",", "cap", ":=", "range", "capSet", ".", "Set", "(", ")", "{", "capsStr", "=", "append", "(", "capsStr", ",", "string", "(", "cap", ")", ")", "\n", "}", "\n", "return", "capsStr", "\n", "}" ]
// parseLinuxCapabilitySet parses a LinuxCapabilitiesSet into string slice
[ "parseLinuxCapabilitySet", "parses", "a", "LinuxCapabilitiesSet", "into", "string", "slice" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L708-L714
167,137
rkt/rkt
stage1/init/common/pod.go
escape
func (c *chroot) escape() error { // change directory to outer root and close it if err := syscall.Fchdir(int(c.root.Fd())); err != nil { return errwrap.Wrapf("changing directory to outer root failed", err) } if err := c.root.Close(); err != nil { return errwrap.Wrapf("closing outer root failed", err) } // chroot to current directory aka "." being the outer root if err := syscall.Chroot("."); err != nil { return errwrap.Wrapf("chroot to current directory failed", err) } // chdir into previous working directory if err := os.Chdir(c.wd); err != nil { return errwrap.Wrapf("chdir to working directory failed", err) } return nil }
go
func (c *chroot) escape() error { // change directory to outer root and close it if err := syscall.Fchdir(int(c.root.Fd())); err != nil { return errwrap.Wrapf("changing directory to outer root failed", err) } if err := c.root.Close(); err != nil { return errwrap.Wrapf("closing outer root failed", err) } // chroot to current directory aka "." being the outer root if err := syscall.Chroot("."); err != nil { return errwrap.Wrapf("chroot to current directory failed", err) } // chdir into previous working directory if err := os.Chdir(c.wd); err != nil { return errwrap.Wrapf("chdir to working directory failed", err) } return nil }
[ "func", "(", "c", "*", "chroot", ")", "escape", "(", ")", "error", "{", "// change directory to outer root and close it", "if", "err", ":=", "syscall", ".", "Fchdir", "(", "int", "(", "c", ".", "root", ".", "Fd", "(", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "root", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// chroot to current directory aka \".\" being the outer root", "if", "err", ":=", "syscall", ".", "Chroot", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// chdir into previous working directory", "if", "err", ":=", "os", ".", "Chdir", "(", "c", ".", "wd", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Escape escapes the chroot environment changing back to the original working directory where newChroot was invoked.
[ "Escape", "escapes", "the", "chroot", "environment", "changing", "back", "to", "the", "original", "working", "directory", "where", "newChroot", "was", "invoked", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/pod.go#L763-L784
167,138
rkt/rkt
common/apps/apps.go
SeccompOverride
func (a *App) SeccompOverride() (mode string, errno string, set []string, e error) { if a.SeccompFilter == "" { return } for _, i := range strings.Split(a.SeccompFilter, ",") { kv := strings.Split(i, "=") if len(kv) == 2 { switch kv[0] { case "mode": if kv[1] != "remove" && kv[1] != "retain" { e = ErrInvalidSeccompMode } mode = kv[1] case "errno": errno = kv[1] default: e = ErrInvalidSeccompOverride } } else { set = append(set, i) } } return }
go
func (a *App) SeccompOverride() (mode string, errno string, set []string, e error) { if a.SeccompFilter == "" { return } for _, i := range strings.Split(a.SeccompFilter, ",") { kv := strings.Split(i, "=") if len(kv) == 2 { switch kv[0] { case "mode": if kv[1] != "remove" && kv[1] != "retain" { e = ErrInvalidSeccompMode } mode = kv[1] case "errno": errno = kv[1] default: e = ErrInvalidSeccompOverride } } else { set = append(set, i) } } return }
[ "func", "(", "a", "*", "App", ")", "SeccompOverride", "(", ")", "(", "mode", "string", ",", "errno", "string", ",", "set", "[", "]", "string", ",", "e", "error", ")", "{", "if", "a", ".", "SeccompFilter", "==", "\"", "\"", "{", "return", "\n", "}", "\n", "for", "_", ",", "i", ":=", "range", "strings", ".", "Split", "(", "a", ".", "SeccompFilter", ",", "\"", "\"", ")", "{", "kv", ":=", "strings", ".", "Split", "(", "i", ",", "\"", "\"", ")", "\n", "if", "len", "(", "kv", ")", "==", "2", "{", "switch", "kv", "[", "0", "]", "{", "case", "\"", "\"", ":", "if", "kv", "[", "1", "]", "!=", "\"", "\"", "&&", "kv", "[", "1", "]", "!=", "\"", "\"", "{", "e", "=", "ErrInvalidSeccompMode", "\n", "}", "\n", "mode", "=", "kv", "[", "1", "]", "\n", "case", "\"", "\"", ":", "errno", "=", "kv", "[", "1", "]", "\n", "default", ":", "e", "=", "ErrInvalidSeccompOverride", "\n", "}", "\n", "}", "else", "{", "set", "=", "append", "(", "set", ",", "i", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// SeccompFilter returns type, filter set and optional errno // for a seccomp filter override specified via CLI
[ "SeccompFilter", "returns", "type", "filter", "set", "and", "optional", "errno", "for", "a", "seccomp", "filter", "override", "specified", "via", "CLI" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/apps/apps.go#L86-L109
167,139
rkt/rkt
common/apps/apps.go
Create
func (al *Apps) Create(img string) { al.apps = append(al.apps, App{Image: img}) }
go
func (al *Apps) Create(img string) { al.apps = append(al.apps, App{Image: img}) }
[ "func", "(", "al", "*", "Apps", ")", "Create", "(", "img", "string", ")", "{", "al", ".", "apps", "=", "append", "(", "al", ".", "apps", ",", "App", "{", "Image", ":", "img", "}", ")", "\n", "}" ]
// Create creates a new app in al and returns a pointer to it
[ "Create", "creates", "a", "new", "app", "in", "al", "and", "returns", "a", "pointer", "to", "it" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/apps/apps.go#L122-L124
167,140
rkt/rkt
common/apps/apps.go
Last
func (al *Apps) Last() *App { if len(al.apps) == 0 { return nil } return &al.apps[len(al.apps)-1] }
go
func (al *Apps) Last() *App { if len(al.apps) == 0 { return nil } return &al.apps[len(al.apps)-1] }
[ "func", "(", "al", "*", "Apps", ")", "Last", "(", ")", "*", "App", "{", "if", "len", "(", "al", ".", "apps", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "&", "al", ".", "apps", "[", "len", "(", "al", ".", "apps", ")", "-", "1", "]", "\n", "}" ]
// Last returns a pointer to the top app in al
[ "Last", "returns", "a", "pointer", "to", "the", "top", "app", "in", "al" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/apps/apps.go#L127-L132
167,141
rkt/rkt
common/apps/apps.go
Walk
func (al *Apps) Walk(f func(*App) error) error { for i := range al.apps { // XXX(vc): note we supply f() with a pointer to the app instance in al.apps to enable modification by f() if err := f(&al.apps[i]); err != nil { return err } } return nil }
go
func (al *Apps) Walk(f func(*App) error) error { for i := range al.apps { // XXX(vc): note we supply f() with a pointer to the app instance in al.apps to enable modification by f() if err := f(&al.apps[i]); err != nil { return err } } return nil }
[ "func", "(", "al", "*", "Apps", ")", "Walk", "(", "f", "func", "(", "*", "App", ")", "error", ")", "error", "{", "for", "i", ":=", "range", "al", ".", "apps", "{", "// XXX(vc): note we supply f() with a pointer to the app instance in al.apps to enable modification by f()", "if", "err", ":=", "f", "(", "&", "al", ".", "apps", "[", "i", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Walk iterates on al.apps calling f for each app // walking stops if f returns an error, the error is simply returned
[ "Walk", "iterates", "on", "al", ".", "apps", "calling", "f", "for", "each", "app", "walking", "stops", "if", "f", "returns", "an", "error", "the", "error", "is", "simply", "returned" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/apps/apps.go#L167-L175
167,142
rkt/rkt
common/apps/apps.go
GetArgs
func (al *Apps) GetArgs() [][]string { var aal [][]string for _, a := range al.apps { aal = append(aal, a.Args) } return aal }
go
func (al *Apps) GetArgs() [][]string { var aal [][]string for _, a := range al.apps { aal = append(aal, a.Args) } return aal }
[ "func", "(", "al", "*", "Apps", ")", "GetArgs", "(", ")", "[", "]", "[", "]", "string", "{", "var", "aal", "[", "]", "[", "]", "string", "\n", "for", "_", ",", "a", ":=", "range", "al", ".", "apps", "{", "aal", "=", "append", "(", "aal", ",", "a", ".", "Args", ")", "\n", "}", "\n", "return", "aal", "\n", "}" ]
// GetArgs returns a list of lists of arguments in al, one list of args per app. // The order reflects the app order in al.
[ "GetArgs", "returns", "a", "list", "of", "lists", "of", "arguments", "in", "al", "one", "list", "of", "args", "per", "app", ".", "The", "order", "reflects", "the", "app", "order", "in", "al", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/apps/apps.go#L192-L198
167,143
rkt/rkt
stage1/common/run.go
WithClearedCloExec
func WithClearedCloExec(lfd int, f func() error) error { err := sys.CloseOnExec(lfd, false) if err != nil { return err } defer sys.CloseOnExec(lfd, true) return f() }
go
func WithClearedCloExec(lfd int, f func() error) error { err := sys.CloseOnExec(lfd, false) if err != nil { return err } defer sys.CloseOnExec(lfd, true) return f() }
[ "func", "WithClearedCloExec", "(", "lfd", "int", ",", "f", "func", "(", ")", "error", ")", "error", "{", "err", ":=", "sys", ".", "CloseOnExec", "(", "lfd", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sys", ".", "CloseOnExec", "(", "lfd", ",", "true", ")", "\n\n", "return", "f", "(", ")", "\n", "}" ]
// WithClearedCloExec executes a given function in between setting and unsetting the close-on-exit flag // on the given file descriptor
[ "WithClearedCloExec", "executes", "a", "given", "function", "in", "between", "setting", "and", "unsetting", "the", "close", "-", "on", "-", "exit", "flag", "on", "the", "given", "file", "descriptor" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/run.go#L31-L39
167,144
rkt/rkt
stage1/common/run.go
PrepareEnterCmd
func PrepareEnterCmd(enterStage2 bool) []string { var args []string enterCmd := os.Getenv(common.CrossingEnterCmd) enterPID := os.Getenv(common.CrossingEnterPID) if enterCmd != "" && enterPID != "" { args = append(args, []string{enterCmd, fmt.Sprintf("--pid=%s", enterPID)}...) enterApp := os.Getenv(common.CrossingEnterApp) if enterApp != "" && enterStage2 { args = append(args, fmt.Sprintf("--app=%s", enterApp)) } args = append(args, "--") } return args }
go
func PrepareEnterCmd(enterStage2 bool) []string { var args []string enterCmd := os.Getenv(common.CrossingEnterCmd) enterPID := os.Getenv(common.CrossingEnterPID) if enterCmd != "" && enterPID != "" { args = append(args, []string{enterCmd, fmt.Sprintf("--pid=%s", enterPID)}...) enterApp := os.Getenv(common.CrossingEnterApp) if enterApp != "" && enterStage2 { args = append(args, fmt.Sprintf("--app=%s", enterApp)) } args = append(args, "--") } return args }
[ "func", "PrepareEnterCmd", "(", "enterStage2", "bool", ")", "[", "]", "string", "{", "var", "args", "[", "]", "string", "\n", "enterCmd", ":=", "os", ".", "Getenv", "(", "common", ".", "CrossingEnterCmd", ")", "\n", "enterPID", ":=", "os", ".", "Getenv", "(", "common", ".", "CrossingEnterPID", ")", "\n", "if", "enterCmd", "!=", "\"", "\"", "&&", "enterPID", "!=", "\"", "\"", "{", "args", "=", "append", "(", "args", ",", "[", "]", "string", "{", "enterCmd", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "enterPID", ")", "}", "...", ")", "\n", "enterApp", ":=", "os", ".", "Getenv", "(", "common", ".", "CrossingEnterApp", ")", "\n", "if", "enterApp", "!=", "\"", "\"", "&&", "enterStage2", "{", "args", "=", "append", "(", "args", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "enterApp", ")", ")", "\n", "}", "\n", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "args", "\n", "}" ]
// PrepareEnterCmd retrieves enter argument and prepare a command list // to further run a command in stage1 context
[ "PrepareEnterCmd", "retrieves", "enter", "argument", "and", "prepare", "a", "command", "list", "to", "further", "run", "a", "command", "in", "stage1", "context" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/run.go#L59-L72
167,145
rkt/rkt
pkg/passwd/passwd.go
LookupUidFromFile
func LookupUidFromFile(userName, passwdFile string) (uid int, err error) { users, err := parsePasswdFile(passwdFile) if err != nil { return -1, errwrap.Wrap(fmt.Errorf("error parsing %q file", passwdFile), err) } user, ok := users[userName] if !ok { return -1, fmt.Errorf("%q user not found", userName) } return user.Uid, nil }
go
func LookupUidFromFile(userName, passwdFile string) (uid int, err error) { users, err := parsePasswdFile(passwdFile) if err != nil { return -1, errwrap.Wrap(fmt.Errorf("error parsing %q file", passwdFile), err) } user, ok := users[userName] if !ok { return -1, fmt.Errorf("%q user not found", userName) } return user.Uid, nil }
[ "func", "LookupUidFromFile", "(", "userName", ",", "passwdFile", "string", ")", "(", "uid", "int", ",", "err", "error", ")", "{", "users", ",", "err", ":=", "parsePasswdFile", "(", "passwdFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "passwdFile", ")", ",", "err", ")", "\n", "}", "\n\n", "user", ",", "ok", ":=", "users", "[", "userName", "]", "\n", "if", "!", "ok", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "userName", ")", "\n", "}", "\n\n", "return", "user", ".", "Uid", ",", "nil", "\n", "}" ]
// LookupUidFromFile reads the passwd file specified by passwdFile, and returns the // uid of the user specified by userName.
[ "LookupUidFromFile", "reads", "the", "passwd", "file", "specified", "by", "passwdFile", "and", "returns", "the", "uid", "of", "the", "user", "specified", "by", "userName", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/passwd/passwd.go#L46-L58
167,146
rkt/rkt
pkg/passwd/passwd.go
LookupUid
func LookupUid(userName string) (uid int, err error) { return LookupUidFromFile(userName, passwdFilePath) }
go
func LookupUid(userName string) (uid int, err error) { return LookupUidFromFile(userName, passwdFilePath) }
[ "func", "LookupUid", "(", "userName", "string", ")", "(", "uid", "int", ",", "err", "error", ")", "{", "return", "LookupUidFromFile", "(", "userName", ",", "passwdFilePath", ")", "\n", "}" ]
// LookupUid reads the passwd file and returns the uid of the user // specified by userName.
[ "LookupUid", "reads", "the", "passwd", "file", "and", "returns", "the", "uid", "of", "the", "user", "specified", "by", "userName", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/passwd/passwd.go#L62-L64
167,147
rkt/rkt
pkg/aci/render.go
RenderACIWithImageID
func RenderACIWithImageID(imageID types.Hash, dir string, ap acirenderer.ACIRegistry, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACIWithImageID(imageID, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
go
func RenderACIWithImageID(imageID types.Hash, dir string, ap acirenderer.ACIRegistry, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACIWithImageID(imageID, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
[ "func", "RenderACIWithImageID", "(", "imageID", "types", ".", "Hash", ",", "dir", "string", ",", "ap", "acirenderer", ".", "ACIRegistry", ",", "uidRange", "*", "user", ".", "UidRange", ")", "error", "{", "renderedACI", ",", "err", ":=", "acirenderer", ".", "GetRenderedACIWithImageID", "(", "imageID", ",", "ap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "renderImage", "(", "renderedACI", ",", "dir", ",", "ap", ",", "uidRange", ")", "\n", "}" ]
// Given an imageID, start with the matching image available in the store, // build its dependency list and render it inside dir
[ "Given", "an", "imageID", "start", "with", "the", "matching", "image", "available", "in", "the", "store", "build", "its", "dependency", "list", "and", "render", "it", "inside", "dir" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/aci/render.go#L31-L37
167,148
rkt/rkt
pkg/aci/render.go
RenderACI
func RenderACI(name types.ACIdentifier, labels types.Labels, dir string, ap acirenderer.ACIRegistry, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACI(name, labels, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
go
func RenderACI(name types.ACIdentifier, labels types.Labels, dir string, ap acirenderer.ACIRegistry, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACI(name, labels, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
[ "func", "RenderACI", "(", "name", "types", ".", "ACIdentifier", ",", "labels", "types", ".", "Labels", ",", "dir", "string", ",", "ap", "acirenderer", ".", "ACIRegistry", ",", "uidRange", "*", "user", ".", "UidRange", ")", "error", "{", "renderedACI", ",", "err", ":=", "acirenderer", ".", "GetRenderedACI", "(", "name", ",", "labels", ",", "ap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "renderImage", "(", "renderedACI", ",", "dir", ",", "ap", ",", "uidRange", ")", "\n", "}" ]
// Given an image app name and optional labels, get the best matching image // available in the store, build its dependency list and render it inside dir
[ "Given", "an", "image", "app", "name", "and", "optional", "labels", "get", "the", "best", "matching", "image", "available", "in", "the", "store", "build", "its", "dependency", "list", "and", "render", "it", "inside", "dir" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/aci/render.go#L41-L47
167,149
rkt/rkt
pkg/aci/render.go
RenderACIFromList
func RenderACIFromList(imgs acirenderer.Images, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACIFromList(imgs, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
go
func RenderACIFromList(imgs acirenderer.Images, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACIFromList(imgs, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
[ "func", "RenderACIFromList", "(", "imgs", "acirenderer", ".", "Images", ",", "dir", "string", ",", "ap", "acirenderer", ".", "ACIProvider", ",", "uidRange", "*", "user", ".", "UidRange", ")", "error", "{", "renderedACI", ",", "err", ":=", "acirenderer", ".", "GetRenderedACIFromList", "(", "imgs", ",", "ap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "renderImage", "(", "renderedACI", ",", "dir", ",", "ap", ",", "uidRange", ")", "\n", "}" ]
// Given an already populated dependency list, it will extract, under the provided // directory, the rendered ACI
[ "Given", "an", "already", "populated", "dependency", "list", "it", "will", "extract", "under", "the", "provided", "directory", "the", "rendered", "ACI" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/aci/render.go#L51-L57
167,150
rkt/rkt
pkg/aci/render.go
renderImage
func renderImage(renderedACI acirenderer.RenderedACI, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error { for _, ra := range renderedACI { rs, err := ap.ReadStream(ra.Key) if err != nil { return err } // Overwrite is not needed. If a file needs to be overwritten then the renderedACI builder has a bug if err := ptar.ExtractTar(rs, dir, false, uidRange, ra.FileMap); err != nil { rs.Close() return errwrap.Wrap(errors.New("error extracting ACI"), err) } rs.Close() } return nil }
go
func renderImage(renderedACI acirenderer.RenderedACI, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error { for _, ra := range renderedACI { rs, err := ap.ReadStream(ra.Key) if err != nil { return err } // Overwrite is not needed. If a file needs to be overwritten then the renderedACI builder has a bug if err := ptar.ExtractTar(rs, dir, false, uidRange, ra.FileMap); err != nil { rs.Close() return errwrap.Wrap(errors.New("error extracting ACI"), err) } rs.Close() } return nil }
[ "func", "renderImage", "(", "renderedACI", "acirenderer", ".", "RenderedACI", ",", "dir", "string", ",", "ap", "acirenderer", ".", "ACIProvider", ",", "uidRange", "*", "user", ".", "UidRange", ")", "error", "{", "for", "_", ",", "ra", ":=", "range", "renderedACI", "{", "rs", ",", "err", ":=", "ap", ".", "ReadStream", "(", "ra", ".", "Key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Overwrite is not needed. If a file needs to be overwritten then the renderedACI builder has a bug", "if", "err", ":=", "ptar", ".", "ExtractTar", "(", "rs", ",", "dir", ",", "false", ",", "uidRange", ",", "ra", ".", "FileMap", ")", ";", "err", "!=", "nil", "{", "rs", ".", "Close", "(", ")", "\n", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "rs", ".", "Close", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Given a RenderedACI, it will extract, under the provided directory, the // needed files from the right source ACI. // The manifest will be extracted from the upper ACI. // No file overwriting is done as it should usually be called // providing an empty directory.
[ "Given", "a", "RenderedACI", "it", "will", "extract", "under", "the", "provided", "directory", "the", "needed", "files", "from", "the", "right", "source", "ACI", ".", "The", "manifest", "will", "be", "extracted", "from", "the", "upper", "ACI", ".", "No", "file", "overwriting", "is", "done", "as", "it", "should", "usually", "be", "called", "providing", "an", "empty", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/aci/render.go#L64-L80
167,151
rkt/rkt
rkt/image/httpfetcher.go
Hash
func (f *httpFetcher) Hash(u *url.URL, a *asc) (string, error) { ensureLogger(f.Debug) urlStr := u.String() if !f.NoCache && f.Rem != nil { if useCached(f.Rem.DownloadTime, f.Rem.CacheMaxAge) { diag.Printf("image for %s isn't expired, not fetching.", urlStr) return f.Rem.BlobKey, nil } } diag.Printf("fetching image from %s", urlStr) aciFile, cd, err := f.fetchURL(u, a, eTag(f.Rem)) if err != nil { return "", err } defer aciFile.Close() if key := maybeUseCached(f.Rem, cd); key != "" { // TODO(krnowak): that does not update the store with // the new CacheMaxAge and Download Time, so it will // query the server every time after initial // CacheMaxAge is exceeded return key, nil } key, err := f.S.WriteACI(aciFile, imagestore.ACIFetchInfo{ Latest: false, }) if err != nil { return "", err } // TODO(krnowak): What's the point of the second parameter? // The SigURL field in imagestore.Remote seems to be completely // unused. newRem := imagestore.NewRemote(urlStr, a.Location) newRem.BlobKey = key newRem.DownloadTime = time.Now() if cd != nil { newRem.ETag = cd.ETag newRem.CacheMaxAge = cd.MaxAge } err = f.S.WriteRemote(newRem) if err != nil { return "", err } return key, nil }
go
func (f *httpFetcher) Hash(u *url.URL, a *asc) (string, error) { ensureLogger(f.Debug) urlStr := u.String() if !f.NoCache && f.Rem != nil { if useCached(f.Rem.DownloadTime, f.Rem.CacheMaxAge) { diag.Printf("image for %s isn't expired, not fetching.", urlStr) return f.Rem.BlobKey, nil } } diag.Printf("fetching image from %s", urlStr) aciFile, cd, err := f.fetchURL(u, a, eTag(f.Rem)) if err != nil { return "", err } defer aciFile.Close() if key := maybeUseCached(f.Rem, cd); key != "" { // TODO(krnowak): that does not update the store with // the new CacheMaxAge and Download Time, so it will // query the server every time after initial // CacheMaxAge is exceeded return key, nil } key, err := f.S.WriteACI(aciFile, imagestore.ACIFetchInfo{ Latest: false, }) if err != nil { return "", err } // TODO(krnowak): What's the point of the second parameter? // The SigURL field in imagestore.Remote seems to be completely // unused. newRem := imagestore.NewRemote(urlStr, a.Location) newRem.BlobKey = key newRem.DownloadTime = time.Now() if cd != nil { newRem.ETag = cd.ETag newRem.CacheMaxAge = cd.MaxAge } err = f.S.WriteRemote(newRem) if err != nil { return "", err } return key, nil }
[ "func", "(", "f", "*", "httpFetcher", ")", "Hash", "(", "u", "*", "url", ".", "URL", ",", "a", "*", "asc", ")", "(", "string", ",", "error", ")", "{", "ensureLogger", "(", "f", ".", "Debug", ")", "\n", "urlStr", ":=", "u", ".", "String", "(", ")", "\n\n", "if", "!", "f", ".", "NoCache", "&&", "f", ".", "Rem", "!=", "nil", "{", "if", "useCached", "(", "f", ".", "Rem", ".", "DownloadTime", ",", "f", ".", "Rem", ".", "CacheMaxAge", ")", "{", "diag", ".", "Printf", "(", "\"", "\"", ",", "urlStr", ")", "\n", "return", "f", ".", "Rem", ".", "BlobKey", ",", "nil", "\n", "}", "\n", "}", "\n\n", "diag", ".", "Printf", "(", "\"", "\"", ",", "urlStr", ")", "\n\n", "aciFile", ",", "cd", ",", "err", ":=", "f", ".", "fetchURL", "(", "u", ",", "a", ",", "eTag", "(", "f", ".", "Rem", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "aciFile", ".", "Close", "(", ")", "\n\n", "if", "key", ":=", "maybeUseCached", "(", "f", ".", "Rem", ",", "cd", ")", ";", "key", "!=", "\"", "\"", "{", "// TODO(krnowak): that does not update the store with", "// the new CacheMaxAge and Download Time, so it will", "// query the server every time after initial", "// CacheMaxAge is exceeded", "return", "key", ",", "nil", "\n", "}", "\n", "key", ",", "err", ":=", "f", ".", "S", ".", "WriteACI", "(", "aciFile", ",", "imagestore", ".", "ACIFetchInfo", "{", "Latest", ":", "false", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// TODO(krnowak): What's the point of the second parameter?", "// The SigURL field in imagestore.Remote seems to be completely", "// unused.", "newRem", ":=", "imagestore", ".", "NewRemote", "(", "urlStr", ",", "a", ".", "Location", ")", "\n", "newRem", ".", "BlobKey", "=", "key", "\n", "newRem", ".", "DownloadTime", "=", "time", ".", "Now", "(", ")", "\n", "if", "cd", "!=", "nil", "{", "newRem", ".", "ETag", "=", "cd", ".", "ETag", "\n", "newRem", ".", "CacheMaxAge", "=", "cd", ".", "MaxAge", "\n", "}", "\n", "err", "=", "f", ".", "S", ".", "WriteRemote", "(", "newRem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "key", ",", "nil", "\n", "}" ]
// Hash fetches the URL, optionally verifies it against passed asc, // stores it in the store and returns the hash.
[ "Hash", "fetches", "the", "URL", "optionally", "verifies", "it", "against", "passed", "asc", "stores", "it", "in", "the", "store", "and", "returns", "the", "hash", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpfetcher.go#L44-L93
167,152
rkt/rkt
stage1/app_add/app_add.go
addMountsStage0
func addMountsStage0(p *stage1types.Pod, ra *schema.RuntimeApp, enterCmd []string) error { sharedVolPath, err := common.CreateSharedVolumesPath(p.Root) if err != nil { return err } vols := make(map[types.ACName]types.Volume) for _, v := range p.Manifest.Volumes { vols[v.Name] = v } imageManifest := p.Images[ra.Name.String()] mounts, err := stage1init.GenerateMounts(ra, p.Manifest.Volumes, stage1init.ConvertedFromDocker(imageManifest)) if err != nil { return errwrap.Wrapf("could not generate mounts", err) } absRoot, err := filepath.Abs(p.Root) if err != nil { return errwrap.Wrapf("could not determine pod's absolute path", err) } appRootfs := common.AppRootfsPath(absRoot, ra.Name) // This logic is mostly copied from appToNspawnArgs // TODO(cdc): deduplicate for _, m := range mounts { shPath := filepath.Join(sharedVolPath, m.Volume.Name.String()) // Evaluate symlinks within the app's rootfs - otherwise absolute // symlinks will be wrong. mntPath, err := stage1init.EvaluateSymlinksInsideApp(appRootfs, m.Mount.Path) if err != nil { return errwrap.Wrap(fmt.Errorf("could not evaluate path %v", m.Mount.Path), err) } // Create the stage1 destination if err := stage1init.PrepareMountpoints(shPath, filepath.Join(appRootfs, mntPath), &m.Volume, m.DockerImplicit); err != nil { return errwrap.Wrapf("could not prepare mountpoint", err) } err = addMountStage0(p, ra, &m, mntPath, enterCmd) if err != nil { return errwrap.Wrap(fmt.Errorf("error adding mount volume %v path %v", m.Mount.Volume, m.Mount.Path), err) } } return nil }
go
func addMountsStage0(p *stage1types.Pod, ra *schema.RuntimeApp, enterCmd []string) error { sharedVolPath, err := common.CreateSharedVolumesPath(p.Root) if err != nil { return err } vols := make(map[types.ACName]types.Volume) for _, v := range p.Manifest.Volumes { vols[v.Name] = v } imageManifest := p.Images[ra.Name.String()] mounts, err := stage1init.GenerateMounts(ra, p.Manifest.Volumes, stage1init.ConvertedFromDocker(imageManifest)) if err != nil { return errwrap.Wrapf("could not generate mounts", err) } absRoot, err := filepath.Abs(p.Root) if err != nil { return errwrap.Wrapf("could not determine pod's absolute path", err) } appRootfs := common.AppRootfsPath(absRoot, ra.Name) // This logic is mostly copied from appToNspawnArgs // TODO(cdc): deduplicate for _, m := range mounts { shPath := filepath.Join(sharedVolPath, m.Volume.Name.String()) // Evaluate symlinks within the app's rootfs - otherwise absolute // symlinks will be wrong. mntPath, err := stage1init.EvaluateSymlinksInsideApp(appRootfs, m.Mount.Path) if err != nil { return errwrap.Wrap(fmt.Errorf("could not evaluate path %v", m.Mount.Path), err) } // Create the stage1 destination if err := stage1init.PrepareMountpoints(shPath, filepath.Join(appRootfs, mntPath), &m.Volume, m.DockerImplicit); err != nil { return errwrap.Wrapf("could not prepare mountpoint", err) } err = addMountStage0(p, ra, &m, mntPath, enterCmd) if err != nil { return errwrap.Wrap(fmt.Errorf("error adding mount volume %v path %v", m.Mount.Volume, m.Mount.Path), err) } } return nil }
[ "func", "addMountsStage0", "(", "p", "*", "stage1types", ".", "Pod", ",", "ra", "*", "schema", ".", "RuntimeApp", ",", "enterCmd", "[", "]", "string", ")", "error", "{", "sharedVolPath", ",", "err", ":=", "common", ".", "CreateSharedVolumesPath", "(", "p", ".", "Root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "vols", ":=", "make", "(", "map", "[", "types", ".", "ACName", "]", "types", ".", "Volume", ")", "\n", "for", "_", ",", "v", ":=", "range", "p", ".", "Manifest", ".", "Volumes", "{", "vols", "[", "v", ".", "Name", "]", "=", "v", "\n", "}", "\n\n", "imageManifest", ":=", "p", ".", "Images", "[", "ra", ".", "Name", ".", "String", "(", ")", "]", "\n\n", "mounts", ",", "err", ":=", "stage1init", ".", "GenerateMounts", "(", "ra", ",", "p", ".", "Manifest", ".", "Volumes", ",", "stage1init", ".", "ConvertedFromDocker", "(", "imageManifest", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "absRoot", ",", "err", ":=", "filepath", ".", "Abs", "(", "p", ".", "Root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "appRootfs", ":=", "common", ".", "AppRootfsPath", "(", "absRoot", ",", "ra", ".", "Name", ")", "\n\n", "// This logic is mostly copied from appToNspawnArgs", "// TODO(cdc): deduplicate", "for", "_", ",", "m", ":=", "range", "mounts", "{", "shPath", ":=", "filepath", ".", "Join", "(", "sharedVolPath", ",", "m", ".", "Volume", ".", "Name", ".", "String", "(", ")", ")", "\n\n", "// Evaluate symlinks within the app's rootfs - otherwise absolute", "// symlinks will be wrong.", "mntPath", ",", "err", ":=", "stage1init", ".", "EvaluateSymlinksInsideApp", "(", "appRootfs", ",", "m", ".", "Mount", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Mount", ".", "Path", ")", ",", "err", ")", "\n", "}", "\n\n", "// Create the stage1 destination", "if", "err", ":=", "stage1init", ".", "PrepareMountpoints", "(", "shPath", ",", "filepath", ".", "Join", "(", "appRootfs", ",", "mntPath", ")", ",", "&", "m", ".", "Volume", ",", "m", ".", "DockerImplicit", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "err", "=", "addMountStage0", "(", "p", ",", "ra", ",", "&", "m", ",", "mntPath", ",", "enterCmd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Mount", ".", "Volume", ",", "m", ".", "Mount", ".", "Path", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// addMountStage0 iterates over all requested mounts and bind mounts them to the stage2 rootfs.
[ "addMountStage0", "iterates", "over", "all", "requested", "mounts", "and", "bind", "mounts", "them", "to", "the", "stage2", "rootfs", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_add/app_add.go#L163-L211
167,153
rkt/rkt
stage1/app_add/app_add.go
Cleanup
func (p *playground) Cleanup() error { if err := os.Remove(p.playground); err != nil { return err } if err := p.mnt.Unmount(p.tmpDir, 0); err != nil { return err } return os.Remove(p.tmpDir) }
go
func (p *playground) Cleanup() error { if err := os.Remove(p.playground); err != nil { return err } if err := p.mnt.Unmount(p.tmpDir, 0); err != nil { return err } return os.Remove(p.tmpDir) }
[ "func", "(", "p", "*", "playground", ")", "Cleanup", "(", ")", "error", "{", "if", "err", ":=", "os", ".", "Remove", "(", "p", ".", "playground", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "mnt", ".", "Unmount", "(", "p", ".", "tmpDir", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "os", ".", "Remove", "(", "p", ".", "tmpDir", ")", "\n", "}" ]
// Cleanup cleans up the playground. // It removes it, unmounts the parent directory, and removes the unmounted directory.
[ "Cleanup", "cleans", "up", "the", "playground", ".", "It", "removes", "it", "unmounts", "the", "parent", "directory", "and", "removes", "the", "unmounted", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_add/app_add.go#L426-L436
167,154
rkt/rkt
pkg/user/util.go
ShiftFiles
func ShiftFiles(filesToShift []string, uidRange *UidRange) error { if uidRange.Shift != 0 && uidRange.Count != 0 { for _, f := range filesToShift { if err := os.Chown(f, int(uidRange.Shift), int(uidRange.Shift)); err != nil { return err } } } return nil }
go
func ShiftFiles(filesToShift []string, uidRange *UidRange) error { if uidRange.Shift != 0 && uidRange.Count != 0 { for _, f := range filesToShift { if err := os.Chown(f, int(uidRange.Shift), int(uidRange.Shift)); err != nil { return err } } } return nil }
[ "func", "ShiftFiles", "(", "filesToShift", "[", "]", "string", ",", "uidRange", "*", "UidRange", ")", "error", "{", "if", "uidRange", ".", "Shift", "!=", "0", "&&", "uidRange", ".", "Count", "!=", "0", "{", "for", "_", ",", "f", ":=", "range", "filesToShift", "{", "if", "err", ":=", "os", ".", "Chown", "(", "f", ",", "int", "(", "uidRange", ".", "Shift", ")", ",", "int", "(", "uidRange", ".", "Shift", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ShiftFiles shifts filesToshift by the amounts specified in uidRange
[ "ShiftFiles", "shifts", "filesToshift", "by", "the", "amounts", "specified", "in", "uidRange" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/user/util.go#L20-L29
167,155
rkt/rkt
rkt/image/namefetcher.go
Hash
func (f *nameFetcher) Hash(app *discovery.App, a *asc) (string, error) { ensureLogger(f.Debug) name := app.Name.String() diag.Printf("searching for app image %s", name) ep, err := f.discoverApp(app) if err != nil { return "", errwrap.Wrap(fmt.Errorf("discovery failed for %q", name), err) } latest := false // No specified version label, mark it as latest if _, ok := app.Labels["version"]; !ok { latest = true } return f.fetchImageFromEndpoints(app, ep, a, latest) }
go
func (f *nameFetcher) Hash(app *discovery.App, a *asc) (string, error) { ensureLogger(f.Debug) name := app.Name.String() diag.Printf("searching for app image %s", name) ep, err := f.discoverApp(app) if err != nil { return "", errwrap.Wrap(fmt.Errorf("discovery failed for %q", name), err) } latest := false // No specified version label, mark it as latest if _, ok := app.Labels["version"]; !ok { latest = true } return f.fetchImageFromEndpoints(app, ep, a, latest) }
[ "func", "(", "f", "*", "nameFetcher", ")", "Hash", "(", "app", "*", "discovery", ".", "App", ",", "a", "*", "asc", ")", "(", "string", ",", "error", ")", "{", "ensureLogger", "(", "f", ".", "Debug", ")", "\n", "name", ":=", "app", ".", "Name", ".", "String", "(", ")", "\n", "diag", ".", "Printf", "(", "\"", "\"", ",", "name", ")", "\n", "ep", ",", "err", ":=", "f", ".", "discoverApp", "(", "app", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", ",", "err", ")", "\n", "}", "\n", "latest", ":=", "false", "\n", "// No specified version label, mark it as latest", "if", "_", ",", "ok", ":=", "app", ".", "Labels", "[", "\"", "\"", "]", ";", "!", "ok", "{", "latest", "=", "true", "\n", "}", "\n", "return", "f", ".", "fetchImageFromEndpoints", "(", "app", ",", "ep", ",", "a", ",", "latest", ")", "\n", "}" ]
// Hash runs the discovery, fetches the image, optionally verifies // it against passed asc, stores it in the store and returns the hash.
[ "Hash", "runs", "the", "discovery", "fetches", "the", "image", "optionally", "verifies", "it", "against", "passed", "asc", "stores", "it", "in", "the", "store", "and", "returns", "the", "hash", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/namefetcher.go#L50-L64
167,156
rkt/rkt
common/overlay/overlay.go
Opts
func (cfg *MountCfg) Opts() string { opts := fmt.Sprintf( "lowerdir=%s,upperdir=%s,workdir=%s", sanitize(cfg.Lower), sanitize(cfg.Upper), sanitize(cfg.Work), ) return label.FormatMountLabel(opts, cfg.Lbl) }
go
func (cfg *MountCfg) Opts() string { opts := fmt.Sprintf( "lowerdir=%s,upperdir=%s,workdir=%s", sanitize(cfg.Lower), sanitize(cfg.Upper), sanitize(cfg.Work), ) return label.FormatMountLabel(opts, cfg.Lbl) }
[ "func", "(", "cfg", "*", "MountCfg", ")", "Opts", "(", ")", "string", "{", "opts", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "sanitize", "(", "cfg", ".", "Lower", ")", ",", "sanitize", "(", "cfg", ".", "Upper", ")", ",", "sanitize", "(", "cfg", ".", "Work", ")", ",", ")", "\n\n", "return", "label", ".", "FormatMountLabel", "(", "opts", ",", "cfg", ".", "Lbl", ")", "\n", "}" ]
// Opts returns options for mount system call.
[ "Opts", "returns", "options", "for", "mount", "system", "call", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/overlay/overlay.go#L50-L57
167,157
rkt/rkt
common/overlay/overlay.go
Mount
func Mount(cfg *MountCfg) error { err := syscall.Mount("overlay", cfg.Dest, "overlay", 0, cfg.Opts()) if err != nil { const text = "error mounting overlay with options '%s' and dest '%s'" return errwrap.Wrap(fmt.Errorf(text, cfg.Opts(), cfg.Dest), err) } return nil }
go
func Mount(cfg *MountCfg) error { err := syscall.Mount("overlay", cfg.Dest, "overlay", 0, cfg.Opts()) if err != nil { const text = "error mounting overlay with options '%s' and dest '%s'" return errwrap.Wrap(fmt.Errorf(text, cfg.Opts(), cfg.Dest), err) } return nil }
[ "func", "Mount", "(", "cfg", "*", "MountCfg", ")", "error", "{", "err", ":=", "syscall", ".", "Mount", "(", "\"", "\"", ",", "cfg", ".", "Dest", ",", "\"", "\"", ",", "0", ",", "cfg", ".", "Opts", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "const", "text", "=", "\"", "\"", "\n", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "text", ",", "cfg", ".", "Opts", "(", ")", ",", "cfg", ".", "Dest", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Mount mounts the upper and lower directories to the destination directory. // The MountCfg struct supplies information required to build the mount system // call.
[ "Mount", "mounts", "the", "upper", "and", "lower", "directories", "to", "the", "destination", "directory", ".", "The", "MountCfg", "struct", "supplies", "information", "required", "to", "build", "the", "mount", "system", "call", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/overlay/overlay.go#L62-L70
167,158
rkt/rkt
pkg/lock/file.go
TryExclusiveLock
func (l *FileLock) TryExclusiveLock() error { err := syscall.Flock(l.fd, syscall.LOCK_EX|syscall.LOCK_NB) if err == syscall.EWOULDBLOCK { err = ErrLocked } return err }
go
func (l *FileLock) TryExclusiveLock() error { err := syscall.Flock(l.fd, syscall.LOCK_EX|syscall.LOCK_NB) if err == syscall.EWOULDBLOCK { err = ErrLocked } return err }
[ "func", "(", "l", "*", "FileLock", ")", "TryExclusiveLock", "(", ")", "error", "{", "err", ":=", "syscall", ".", "Flock", "(", "l", ".", "fd", ",", "syscall", ".", "LOCK_EX", "|", "syscall", ".", "LOCK_NB", ")", "\n", "if", "err", "==", "syscall", ".", "EWOULDBLOCK", "{", "err", "=", "ErrLocked", "\n", "}", "\n", "return", "err", "\n", "}" ]
// TryExclusiveLock takes an exclusive lock without blocking. // This is idempotent when the Lock already represents an exclusive lock, // and tries promote a shared lock to exclusive atomically. // It will return ErrLocked if any lock is already held.
[ "TryExclusiveLock", "takes", "an", "exclusive", "lock", "without", "blocking", ".", "This", "is", "idempotent", "when", "the", "Lock", "already", "represents", "an", "exclusive", "lock", "and", "tries", "promote", "a", "shared", "lock", "to", "exclusive", "atomically", ".", "It", "will", "return", "ErrLocked", "if", "any", "lock", "is", "already", "held", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L48-L54
167,159
rkt/rkt
pkg/lock/file.go
ExclusiveLock
func (l *FileLock) ExclusiveLock() error { return syscall.Flock(l.fd, syscall.LOCK_EX) }
go
func (l *FileLock) ExclusiveLock() error { return syscall.Flock(l.fd, syscall.LOCK_EX) }
[ "func", "(", "l", "*", "FileLock", ")", "ExclusiveLock", "(", ")", "error", "{", "return", "syscall", ".", "Flock", "(", "l", ".", "fd", ",", "syscall", ".", "LOCK_EX", ")", "\n", "}" ]
// ExclusiveLock takes an exclusive lock. // This is idempotent when the Lock already represents an exclusive lock, // and promotes a shared lock to exclusive atomically. // It will block if an exclusive lock is already held.
[ "ExclusiveLock", "takes", "an", "exclusive", "lock", ".", "This", "is", "idempotent", "when", "the", "Lock", "already", "represents", "an", "exclusive", "lock", "and", "promotes", "a", "shared", "lock", "to", "exclusive", "atomically", ".", "It", "will", "block", "if", "an", "exclusive", "lock", "is", "already", "held", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L74-L76
167,160
rkt/rkt
pkg/lock/file.go
Unlock
func (l *FileLock) Unlock() error { return syscall.Flock(l.fd, syscall.LOCK_UN) }
go
func (l *FileLock) Unlock() error { return syscall.Flock(l.fd, syscall.LOCK_UN) }
[ "func", "(", "l", "*", "FileLock", ")", "Unlock", "(", ")", "error", "{", "return", "syscall", ".", "Flock", "(", "l", ".", "fd", ",", "syscall", ".", "LOCK_UN", ")", "\n", "}" ]
// Unlock unlocks the lock
[ "Unlock", "unlocks", "the", "lock" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L140-L142
167,161
rkt/rkt
pkg/lock/file.go
Fd
func (l *FileLock) Fd() (int, error) { var err error if l.fd == -1 { err = errors.New("lock closed") } return l.fd, err }
go
func (l *FileLock) Fd() (int, error) { var err error if l.fd == -1 { err = errors.New("lock closed") } return l.fd, err }
[ "func", "(", "l", "*", "FileLock", ")", "Fd", "(", ")", "(", "int", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "l", ".", "fd", "==", "-", "1", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "l", ".", "fd", ",", "err", "\n", "}" ]
// Fd returns the lock's file descriptor, or an error if the lock is closed
[ "Fd", "returns", "the", "lock", "s", "file", "descriptor", "or", "an", "error", "if", "the", "lock", "is", "closed" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L145-L151
167,162
rkt/rkt
pkg/lock/file.go
Close
func (l *FileLock) Close() error { fd := l.fd l.fd = -1 return syscall.Close(fd) }
go
func (l *FileLock) Close() error { fd := l.fd l.fd = -1 return syscall.Close(fd) }
[ "func", "(", "l", "*", "FileLock", ")", "Close", "(", ")", "error", "{", "fd", ":=", "l", ".", "fd", "\n", "l", ".", "fd", "=", "-", "1", "\n", "return", "syscall", ".", "Close", "(", "fd", ")", "\n", "}" ]
// Close closes the lock which implicitly unlocks it as well
[ "Close", "closes", "the", "lock", "which", "implicitly", "unlocks", "it", "as", "well" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L154-L158
167,163
rkt/rkt
pkg/lock/file.go
NewLock
func NewLock(path string, lockType LockType) (*FileLock, error) { l := &FileLock{path: path, fd: -1} mode := syscall.O_RDONLY | syscall.O_CLOEXEC if lockType == Dir { mode |= syscall.O_DIRECTORY } lfd, err := syscall.Open(l.path, mode, 0) if err != nil { if err == syscall.ENOENT { err = ErrNotExist } else if err == syscall.EACCES { err = ErrPermission } return nil, err } l.fd = lfd var stat syscall.Stat_t err = syscall.Fstat(lfd, &stat) if err != nil { return nil, err } // Check if the file is a regular file if lockType == RegFile && !(stat.Mode&syscall.S_IFMT == syscall.S_IFREG) { return nil, ErrNotRegular } return l, nil }
go
func NewLock(path string, lockType LockType) (*FileLock, error) { l := &FileLock{path: path, fd: -1} mode := syscall.O_RDONLY | syscall.O_CLOEXEC if lockType == Dir { mode |= syscall.O_DIRECTORY } lfd, err := syscall.Open(l.path, mode, 0) if err != nil { if err == syscall.ENOENT { err = ErrNotExist } else if err == syscall.EACCES { err = ErrPermission } return nil, err } l.fd = lfd var stat syscall.Stat_t err = syscall.Fstat(lfd, &stat) if err != nil { return nil, err } // Check if the file is a regular file if lockType == RegFile && !(stat.Mode&syscall.S_IFMT == syscall.S_IFREG) { return nil, ErrNotRegular } return l, nil }
[ "func", "NewLock", "(", "path", "string", ",", "lockType", "LockType", ")", "(", "*", "FileLock", ",", "error", ")", "{", "l", ":=", "&", "FileLock", "{", "path", ":", "path", ",", "fd", ":", "-", "1", "}", "\n\n", "mode", ":=", "syscall", ".", "O_RDONLY", "|", "syscall", ".", "O_CLOEXEC", "\n", "if", "lockType", "==", "Dir", "{", "mode", "|=", "syscall", ".", "O_DIRECTORY", "\n", "}", "\n", "lfd", ",", "err", ":=", "syscall", ".", "Open", "(", "l", ".", "path", ",", "mode", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "syscall", ".", "ENOENT", "{", "err", "=", "ErrNotExist", "\n", "}", "else", "if", "err", "==", "syscall", ".", "EACCES", "{", "err", "=", "ErrPermission", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "l", ".", "fd", "=", "lfd", "\n\n", "var", "stat", "syscall", ".", "Stat_t", "\n", "err", "=", "syscall", ".", "Fstat", "(", "lfd", ",", "&", "stat", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Check if the file is a regular file", "if", "lockType", "==", "RegFile", "&&", "!", "(", "stat", ".", "Mode", "&", "syscall", ".", "S_IFMT", "==", "syscall", ".", "S_IFREG", ")", "{", "return", "nil", ",", "ErrNotRegular", "\n", "}", "\n\n", "return", "l", ",", "nil", "\n", "}" ]
// NewLock opens a new lock on a file without acquisition
[ "NewLock", "opens", "a", "new", "lock", "on", "a", "file", "without", "acquisition" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/file.go#L161-L190
167,164
rkt/rkt
tools/depsgen/gocmd.go
goGetArgs
func goGetArgs(args []string) (string, string, string, goDepsMode) { f, target := standardFlags(goCmd) repo := f.String("repo", "", "Go repo (example: github.com/rkt/rkt)") module := f.String("module", "", "Module inside Go repo (example: stage1)") mode := f.String("mode", "make", "Mode to use (make - print deps as makefile [default], files - print a list of files)") f.Parse(args) if *repo == "" { common.Die("--repo parameter must be specified and cannot be empty") } if *module == "" { common.Die("--module parameter must be specified and cannot be empty") } var dMode goDepsMode switch *mode { case "make": dMode = goMakeMode if *target == "" { common.Die("--target parameter must be specified and cannot be empty when using 'make' mode") } case "files": dMode = goFilesMode default: common.Die("unknown --mode parameter %q - expected either 'make' or 'files'", *mode) } return *target, *repo, *module, dMode }
go
func goGetArgs(args []string) (string, string, string, goDepsMode) { f, target := standardFlags(goCmd) repo := f.String("repo", "", "Go repo (example: github.com/rkt/rkt)") module := f.String("module", "", "Module inside Go repo (example: stage1)") mode := f.String("mode", "make", "Mode to use (make - print deps as makefile [default], files - print a list of files)") f.Parse(args) if *repo == "" { common.Die("--repo parameter must be specified and cannot be empty") } if *module == "" { common.Die("--module parameter must be specified and cannot be empty") } var dMode goDepsMode switch *mode { case "make": dMode = goMakeMode if *target == "" { common.Die("--target parameter must be specified and cannot be empty when using 'make' mode") } case "files": dMode = goFilesMode default: common.Die("unknown --mode parameter %q - expected either 'make' or 'files'", *mode) } return *target, *repo, *module, dMode }
[ "func", "goGetArgs", "(", "args", "[", "]", "string", ")", "(", "string", ",", "string", ",", "string", ",", "goDepsMode", ")", "{", "f", ",", "target", ":=", "standardFlags", "(", "goCmd", ")", "\n", "repo", ":=", "f", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "module", ":=", "f", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "mode", ":=", "f", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "f", ".", "Parse", "(", "args", ")", "\n", "if", "*", "repo", "==", "\"", "\"", "{", "common", ".", "Die", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "*", "module", "==", "\"", "\"", "{", "common", ".", "Die", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "dMode", "goDepsMode", "\n\n", "switch", "*", "mode", "{", "case", "\"", "\"", ":", "dMode", "=", "goMakeMode", "\n", "if", "*", "target", "==", "\"", "\"", "{", "common", ".", "Die", "(", "\"", "\"", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "dMode", "=", "goFilesMode", "\n", "default", ":", "common", ".", "Die", "(", "\"", "\"", ",", "*", "mode", ")", "\n", "}", "\n", "return", "*", "target", ",", "*", "repo", ",", "*", "module", ",", "dMode", "\n", "}" ]
// getArgs parses given parameters and returns target, repo, module and // mode. If mode is "files", then target is optional.
[ "getArgs", "parses", "given", "parameters", "and", "returns", "target", "repo", "module", "and", "mode", ".", "If", "mode", "is", "files", "then", "target", "is", "optional", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L69-L97
167,165
rkt/rkt
tools/depsgen/gocmd.go
goGetPackageDeps
func goGetPackageDeps(repo, module string) []string { dir, deps := goGetDeps(repo, module) return goGetFiles(dir, deps) }
go
func goGetPackageDeps(repo, module string) []string { dir, deps := goGetDeps(repo, module) return goGetFiles(dir, deps) }
[ "func", "goGetPackageDeps", "(", "repo", ",", "module", "string", ")", "[", "]", "string", "{", "dir", ",", "deps", ":=", "goGetDeps", "(", "repo", ",", "module", ")", "\n", "return", "goGetFiles", "(", "dir", ",", "deps", ")", "\n", "}" ]
// goGetPackageDeps returns a list of files that are used to build a // module in a given repo.
[ "goGetPackageDeps", "returns", "a", "list", "of", "files", "that", "are", "used", "to", "build", "a", "module", "in", "a", "given", "repo", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L101-L104
167,166
rkt/rkt
tools/depsgen/gocmd.go
goGetDeps
func goGetDeps(repo, module string) (string, []string) { pkg := path.Join(repo, module) rawTuples := goRun(goList([]string{"Dir", "Deps"}, []string{pkg})) if len(rawTuples) != 1 { common.Die("Expected to get only one line from go list for a single package") } tuple := goSliceRawTuple(rawTuples[0]) dir := tuple[0] if module != "." { dirsToStrip := 1 + strings.Count(module, "/") for i := 0; i < dirsToStrip; i++ { dir = filepath.Dir(dir) } } dir = filepath.Clean(dir) deps := goSliceRawSlice(tuple[1]) return dir, append([]string{pkg}, deps...) }
go
func goGetDeps(repo, module string) (string, []string) { pkg := path.Join(repo, module) rawTuples := goRun(goList([]string{"Dir", "Deps"}, []string{pkg})) if len(rawTuples) != 1 { common.Die("Expected to get only one line from go list for a single package") } tuple := goSliceRawTuple(rawTuples[0]) dir := tuple[0] if module != "." { dirsToStrip := 1 + strings.Count(module, "/") for i := 0; i < dirsToStrip; i++ { dir = filepath.Dir(dir) } } dir = filepath.Clean(dir) deps := goSliceRawSlice(tuple[1]) return dir, append([]string{pkg}, deps...) }
[ "func", "goGetDeps", "(", "repo", ",", "module", "string", ")", "(", "string", ",", "[", "]", "string", ")", "{", "pkg", ":=", "path", ".", "Join", "(", "repo", ",", "module", ")", "\n", "rawTuples", ":=", "goRun", "(", "goList", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "[", "]", "string", "{", "pkg", "}", ")", ")", "\n", "if", "len", "(", "rawTuples", ")", "!=", "1", "{", "common", ".", "Die", "(", "\"", "\"", ")", "\n", "}", "\n", "tuple", ":=", "goSliceRawTuple", "(", "rawTuples", "[", "0", "]", ")", "\n", "dir", ":=", "tuple", "[", "0", "]", "\n", "if", "module", "!=", "\"", "\"", "{", "dirsToStrip", ":=", "1", "+", "strings", ".", "Count", "(", "module", ",", "\"", "\"", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "dirsToStrip", ";", "i", "++", "{", "dir", "=", "filepath", ".", "Dir", "(", "dir", ")", "\n", "}", "\n", "}", "\n", "dir", "=", "filepath", ".", "Clean", "(", "dir", ")", "\n", "deps", ":=", "goSliceRawSlice", "(", "tuple", "[", "1", "]", ")", "\n", "return", "dir", ",", "append", "(", "[", "]", "string", "{", "pkg", "}", ",", "deps", "...", ")", "\n", "}" ]
// goGetDeps gets the directory of a given repo and the all // dependencies, direct or indirect, of a given module in the repo.
[ "goGetDeps", "gets", "the", "directory", "of", "a", "given", "repo", "and", "the", "all", "dependencies", "direct", "or", "indirect", "of", "a", "given", "module", "in", "the", "repo", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L108-L125
167,167
rkt/rkt
tools/depsgen/gocmd.go
goGetFiles
func goGetFiles(dir string, pkgs []string) []string { params := []string{ "Dir", "GoFiles", "CgoFiles", } var allFiles []string rawTuples := goRun(goList(params, pkgs)) for _, raw := range rawTuples { tuple := goSliceRawTuple(raw) moduleDir := filepath.Clean(tuple[0]) dirSep := fmt.Sprintf("%s%c", dir, filepath.Separator) moduleDirSep := fmt.Sprintf("%s%c", moduleDir, filepath.Separator) if !strings.HasPrefix(moduleDirSep, dirSep) { continue } relModuleDir, err := filepath.Rel(dir, moduleDir) if err != nil { common.Die("Could not make a relative path from %q to %q, even if they have the same prefix", moduleDir, dir) } files := append(goSliceRawSlice(tuple[1]), goSliceRawSlice(tuple[2])...) for i := 0; i < len(files); i++ { files[i] = filepath.Join(relModuleDir, files[i]) } allFiles = append(allFiles, files...) } return allFiles }
go
func goGetFiles(dir string, pkgs []string) []string { params := []string{ "Dir", "GoFiles", "CgoFiles", } var allFiles []string rawTuples := goRun(goList(params, pkgs)) for _, raw := range rawTuples { tuple := goSliceRawTuple(raw) moduleDir := filepath.Clean(tuple[0]) dirSep := fmt.Sprintf("%s%c", dir, filepath.Separator) moduleDirSep := fmt.Sprintf("%s%c", moduleDir, filepath.Separator) if !strings.HasPrefix(moduleDirSep, dirSep) { continue } relModuleDir, err := filepath.Rel(dir, moduleDir) if err != nil { common.Die("Could not make a relative path from %q to %q, even if they have the same prefix", moduleDir, dir) } files := append(goSliceRawSlice(tuple[1]), goSliceRawSlice(tuple[2])...) for i := 0; i < len(files); i++ { files[i] = filepath.Join(relModuleDir, files[i]) } allFiles = append(allFiles, files...) } return allFiles }
[ "func", "goGetFiles", "(", "dir", "string", ",", "pkgs", "[", "]", "string", ")", "[", "]", "string", "{", "params", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "var", "allFiles", "[", "]", "string", "\n", "rawTuples", ":=", "goRun", "(", "goList", "(", "params", ",", "pkgs", ")", ")", "\n", "for", "_", ",", "raw", ":=", "range", "rawTuples", "{", "tuple", ":=", "goSliceRawTuple", "(", "raw", ")", "\n", "moduleDir", ":=", "filepath", ".", "Clean", "(", "tuple", "[", "0", "]", ")", "\n", "dirSep", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dir", ",", "filepath", ".", "Separator", ")", "\n", "moduleDirSep", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "moduleDir", ",", "filepath", ".", "Separator", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "moduleDirSep", ",", "dirSep", ")", "{", "continue", "\n", "}", "\n", "relModuleDir", ",", "err", ":=", "filepath", ".", "Rel", "(", "dir", ",", "moduleDir", ")", "\n", "if", "err", "!=", "nil", "{", "common", ".", "Die", "(", "\"", "\"", ",", "moduleDir", ",", "dir", ")", "\n", "}", "\n", "files", ":=", "append", "(", "goSliceRawSlice", "(", "tuple", "[", "1", "]", ")", ",", "goSliceRawSlice", "(", "tuple", "[", "2", "]", ")", "...", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "files", ")", ";", "i", "++", "{", "files", "[", "i", "]", "=", "filepath", ".", "Join", "(", "relModuleDir", ",", "files", "[", "i", "]", ")", "\n", "}", "\n", "allFiles", "=", "append", "(", "allFiles", ",", "files", "...", ")", "\n", "}", "\n", "return", "allFiles", "\n", "}" ]
// goGetFiles returns a list of files that are in given packages. File // paths are relative to a given directory.
[ "goGetFiles", "returns", "a", "list", "of", "files", "that", "are", "in", "given", "packages", ".", "File", "paths", "are", "relative", "to", "a", "given", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L129-L156
167,168
rkt/rkt
tools/depsgen/gocmd.go
goRun
func goRun(argv []string) []string { cmd := exec.Command(argv[0], argv[1:]...) stdout := new(bytes.Buffer) stderr := new(bytes.Buffer) cmd.Stdout = stdout cmd.Stderr = stderr if err := cmd.Run(); err != nil { common.Die("Error running %s: %v: %s", strings.Join(argv, " "), err, stderr.String()) } rawLines := strings.Split(stdout.String(), "\n") lines := make([]string, 0, len(rawLines)) for _, line := range rawLines { if trimmed := strings.TrimSpace(line); trimmed != "" { lines = append(lines, trimmed) } } return lines }
go
func goRun(argv []string) []string { cmd := exec.Command(argv[0], argv[1:]...) stdout := new(bytes.Buffer) stderr := new(bytes.Buffer) cmd.Stdout = stdout cmd.Stderr = stderr if err := cmd.Run(); err != nil { common.Die("Error running %s: %v: %s", strings.Join(argv, " "), err, stderr.String()) } rawLines := strings.Split(stdout.String(), "\n") lines := make([]string, 0, len(rawLines)) for _, line := range rawLines { if trimmed := strings.TrimSpace(line); trimmed != "" { lines = append(lines, trimmed) } } return lines }
[ "func", "goRun", "(", "argv", "[", "]", "string", ")", "[", "]", "string", "{", "cmd", ":=", "exec", ".", "Command", "(", "argv", "[", "0", "]", ",", "argv", "[", "1", ":", "]", "...", ")", "\n", "stdout", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "stderr", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "cmd", ".", "Stdout", "=", "stdout", "\n", "cmd", ".", "Stderr", "=", "stderr", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "common", ".", "Die", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "argv", ",", "\"", "\"", ")", ",", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n", "rawLines", ":=", "strings", ".", "Split", "(", "stdout", ".", "String", "(", ")", ",", "\"", "\\n", "\"", ")", "\n", "lines", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "rawLines", ")", ")", "\n", "for", "_", ",", "line", ":=", "range", "rawLines", "{", "if", "trimmed", ":=", "strings", ".", "TrimSpace", "(", "line", ")", ";", "trimmed", "!=", "\"", "\"", "{", "lines", "=", "append", "(", "lines", ",", "trimmed", ")", "\n", "}", "\n", "}", "\n", "return", "lines", "\n", "}" ]
// goRun executes given argument list and captures its output. The // output is sliced into lines with empty lines being discarded.
[ "goRun", "executes", "given", "argument", "list", "and", "captures", "its", "output", ".", "The", "output", "is", "sliced", "into", "lines", "with", "empty", "lines", "being", "discarded", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L175-L192
167,169
rkt/rkt
tools/depsgen/gocmd.go
goSliceRawSlice
func goSliceRawSlice(s string) []string { s = strings.TrimPrefix(s, "[") s = strings.TrimSuffix(s, "]") s = strings.TrimSpace(s) if s == "" { return nil } a := strings.Split(s, " ") return a }
go
func goSliceRawSlice(s string) []string { s = strings.TrimPrefix(s, "[") s = strings.TrimSuffix(s, "]") s = strings.TrimSpace(s) if s == "" { return nil } a := strings.Split(s, " ") return a }
[ "func", "goSliceRawSlice", "(", "s", "string", ")", "[", "]", "string", "{", "s", "=", "strings", ".", "TrimPrefix", "(", "s", ",", "\"", "\"", ")", "\n", "s", "=", "strings", ".", "TrimSuffix", "(", "s", ",", "\"", "\"", ")", "\n", "s", "=", "strings", ".", "TrimSpace", "(", "s", ")", "\n", "if", "s", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "a", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\"", ")", "\n", "return", "a", "\n", "}" ]
// goSliceRawSlice slices given string representation of a slice into // slice of strings.
[ "goSliceRawSlice", "slices", "given", "string", "representation", "of", "a", "slice", "into", "slice", "of", "strings", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/gocmd.go#L196-L205
167,170
rkt/rkt
stage1/init/common/mount.go
ConvertedFromDocker
func ConvertedFromDocker(im *schema.ImageManifest) bool { if im == nil { // nil sometimes sneaks in here due to unit tests return false } ann := im.Annotations _, ok := ann.Get("appc.io/docker/repository") return ok }
go
func ConvertedFromDocker(im *schema.ImageManifest) bool { if im == nil { // nil sometimes sneaks in here due to unit tests return false } ann := im.Annotations _, ok := ann.Get("appc.io/docker/repository") return ok }
[ "func", "ConvertedFromDocker", "(", "im", "*", "schema", ".", "ImageManifest", ")", "bool", "{", "if", "im", "==", "nil", "{", "// nil sometimes sneaks in here due to unit tests", "return", "false", "\n", "}", "\n", "ann", ":=", "im", ".", "Annotations", "\n", "_", ",", "ok", ":=", "ann", ".", "Get", "(", "\"", "\"", ")", "\n", "return", "ok", "\n", "}" ]
// ConvertedFromDocker determines if an app's image has been converted // from docker. This is needed because implicit docker empty volumes have // different behavior from AppC
[ "ConvertedFromDocker", "determines", "if", "an", "app", "s", "image", "has", "been", "converted", "from", "docker", ".", "This", "is", "needed", "because", "implicit", "docker", "empty", "volumes", "have", "different", "behavior", "from", "AppC" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/mount.go#L53-L60
167,171
rkt/rkt
stage1/init/common/mount.go
Source
func (m *Mount) Source(podRoot string) string { switch m.Volume.Kind { case "host": return m.Volume.Source case "empty": return filepath.Join(common.SharedVolumesPath(podRoot), m.Volume.Name.String()) } return "" // We validate in GenerateMounts that it's valid }
go
func (m *Mount) Source(podRoot string) string { switch m.Volume.Kind { case "host": return m.Volume.Source case "empty": return filepath.Join(common.SharedVolumesPath(podRoot), m.Volume.Name.String()) } return "" // We validate in GenerateMounts that it's valid }
[ "func", "(", "m", "*", "Mount", ")", "Source", "(", "podRoot", "string", ")", "string", "{", "switch", "m", ".", "Volume", ".", "Kind", "{", "case", "\"", "\"", ":", "return", "m", ".", "Volume", ".", "Source", "\n", "case", "\"", "\"", ":", "return", "filepath", ".", "Join", "(", "common", ".", "SharedVolumesPath", "(", "podRoot", ")", ",", "m", ".", "Volume", ".", "Name", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "\"", "\"", "// We validate in GenerateMounts that it's valid", "\n", "}" ]
// Source computes the real volume source for a volume. // Volumes of type 'empty' use a workdir relative to podRoot
[ "Source", "computes", "the", "real", "volume", "source", "for", "a", "volume", ".", "Volumes", "of", "type", "empty", "use", "a", "workdir", "relative", "to", "podRoot" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/mount.go#L64-L72
167,172
rkt/rkt
stage1/init/common/mount.go
GenerateMounts
func GenerateMounts(ra *schema.RuntimeApp, podVolumes []types.Volume, convertedFromDocker bool) ([]Mount, error) { app := ra.App var genMnts []Mount vols := make(map[types.ACName]types.Volume) for _, v := range podVolumes { vols[v.Name] = v } // RuntimeApps have mounts, whereas Apps have mountPoints. mountPoints are partially for // Docker compat; since apps can declare mountpoints. However, if we just run with rkt run, // then we'll only have a Mount and no corresponding MountPoint. // Furthermore, Mounts can have embedded volumes in the case of the CRI. // So, we generate a pile of Mounts and their corresponding Volume // Map of hostpath -> Mount mnts := make(map[string]schema.Mount) // Check runtimeApp's Mounts for _, m := range ra.Mounts { mnts[m.Path] = m vol := m.AppVolume // Mounts can supply a volume if vol == nil { vv, ok := vols[m.Volume] if !ok { return nil, fmt.Errorf("could not find volume %s", m.Volume) } vol = &vv } // Find a corresponding MountPoint, which is optional ro := false for _, mp := range ra.App.MountPoints { if mp.Name == m.Volume { ro = mp.ReadOnly break } } if vol.ReadOnly != nil { ro = *vol.ReadOnly } switch vol.Kind { case "host": case "empty": default: return nil, fmt.Errorf("Volume %s has invalid kind %s", vol.Name, vol.Kind) } genMnts = append(genMnts, Mount{ Mount: m, DockerImplicit: false, ReadOnly: ro, Volume: *vol, }) } // Now, match up MountPoints with Mounts or Volumes // If there's no Mount and no Volume, generate an empty volume for _, mp := range app.MountPoints { // there's already a Mount for this MountPoint, stop if _, ok := mnts[mp.Path]; ok { continue } // No Mount, try to match based on volume name vol, ok := vols[mp.Name] // there is no volume for this mount point, creating an "empty" volume // implicitly if !ok { defaultMode := "0755" defaultUID := 0 defaultGID := 0 uniqName := ra.Name + "-" + mp.Name emptyVol := types.Volume{ Name: uniqName, Kind: "empty", Mode: &defaultMode, UID: &defaultUID, GID: &defaultGID, } log.Printf("warning: no volume specified for mount point %q, implicitly creating an \"empty\" volume. This volume will be removed when the pod is garbage-collected.", mp.Name) if convertedFromDocker { log.Printf("Docker converted image, initializing implicit volume with data contained at the mount point %q.", mp.Name) } vols[uniqName] = emptyVol genMnts = append(genMnts, Mount{ Mount: schema.Mount{ Volume: uniqName, Path: mp.Path, }, Volume: emptyVol, ReadOnly: mp.ReadOnly, DockerImplicit: convertedFromDocker, }) } else { ro := mp.ReadOnly if vol.ReadOnly != nil { ro = *vol.ReadOnly } genMnts = append(genMnts, Mount{ Mount: schema.Mount{ Volume: vol.Name, Path: mp.Path, }, Volume: vol, ReadOnly: ro, DockerImplicit: false, }) } } return genMnts, nil }
go
func GenerateMounts(ra *schema.RuntimeApp, podVolumes []types.Volume, convertedFromDocker bool) ([]Mount, error) { app := ra.App var genMnts []Mount vols := make(map[types.ACName]types.Volume) for _, v := range podVolumes { vols[v.Name] = v } // RuntimeApps have mounts, whereas Apps have mountPoints. mountPoints are partially for // Docker compat; since apps can declare mountpoints. However, if we just run with rkt run, // then we'll only have a Mount and no corresponding MountPoint. // Furthermore, Mounts can have embedded volumes in the case of the CRI. // So, we generate a pile of Mounts and their corresponding Volume // Map of hostpath -> Mount mnts := make(map[string]schema.Mount) // Check runtimeApp's Mounts for _, m := range ra.Mounts { mnts[m.Path] = m vol := m.AppVolume // Mounts can supply a volume if vol == nil { vv, ok := vols[m.Volume] if !ok { return nil, fmt.Errorf("could not find volume %s", m.Volume) } vol = &vv } // Find a corresponding MountPoint, which is optional ro := false for _, mp := range ra.App.MountPoints { if mp.Name == m.Volume { ro = mp.ReadOnly break } } if vol.ReadOnly != nil { ro = *vol.ReadOnly } switch vol.Kind { case "host": case "empty": default: return nil, fmt.Errorf("Volume %s has invalid kind %s", vol.Name, vol.Kind) } genMnts = append(genMnts, Mount{ Mount: m, DockerImplicit: false, ReadOnly: ro, Volume: *vol, }) } // Now, match up MountPoints with Mounts or Volumes // If there's no Mount and no Volume, generate an empty volume for _, mp := range app.MountPoints { // there's already a Mount for this MountPoint, stop if _, ok := mnts[mp.Path]; ok { continue } // No Mount, try to match based on volume name vol, ok := vols[mp.Name] // there is no volume for this mount point, creating an "empty" volume // implicitly if !ok { defaultMode := "0755" defaultUID := 0 defaultGID := 0 uniqName := ra.Name + "-" + mp.Name emptyVol := types.Volume{ Name: uniqName, Kind: "empty", Mode: &defaultMode, UID: &defaultUID, GID: &defaultGID, } log.Printf("warning: no volume specified for mount point %q, implicitly creating an \"empty\" volume. This volume will be removed when the pod is garbage-collected.", mp.Name) if convertedFromDocker { log.Printf("Docker converted image, initializing implicit volume with data contained at the mount point %q.", mp.Name) } vols[uniqName] = emptyVol genMnts = append(genMnts, Mount{ Mount: schema.Mount{ Volume: uniqName, Path: mp.Path, }, Volume: emptyVol, ReadOnly: mp.ReadOnly, DockerImplicit: convertedFromDocker, }) } else { ro := mp.ReadOnly if vol.ReadOnly != nil { ro = *vol.ReadOnly } genMnts = append(genMnts, Mount{ Mount: schema.Mount{ Volume: vol.Name, Path: mp.Path, }, Volume: vol, ReadOnly: ro, DockerImplicit: false, }) } } return genMnts, nil }
[ "func", "GenerateMounts", "(", "ra", "*", "schema", ".", "RuntimeApp", ",", "podVolumes", "[", "]", "types", ".", "Volume", ",", "convertedFromDocker", "bool", ")", "(", "[", "]", "Mount", ",", "error", ")", "{", "app", ":=", "ra", ".", "App", "\n\n", "var", "genMnts", "[", "]", "Mount", "\n\n", "vols", ":=", "make", "(", "map", "[", "types", ".", "ACName", "]", "types", ".", "Volume", ")", "\n", "for", "_", ",", "v", ":=", "range", "podVolumes", "{", "vols", "[", "v", ".", "Name", "]", "=", "v", "\n", "}", "\n\n", "// RuntimeApps have mounts, whereas Apps have mountPoints. mountPoints are partially for", "// Docker compat; since apps can declare mountpoints. However, if we just run with rkt run,", "// then we'll only have a Mount and no corresponding MountPoint.", "// Furthermore, Mounts can have embedded volumes in the case of the CRI.", "// So, we generate a pile of Mounts and their corresponding Volume", "// Map of hostpath -> Mount", "mnts", ":=", "make", "(", "map", "[", "string", "]", "schema", ".", "Mount", ")", "\n\n", "// Check runtimeApp's Mounts", "for", "_", ",", "m", ":=", "range", "ra", ".", "Mounts", "{", "mnts", "[", "m", ".", "Path", "]", "=", "m", "\n\n", "vol", ":=", "m", ".", "AppVolume", "// Mounts can supply a volume", "\n", "if", "vol", "==", "nil", "{", "vv", ",", "ok", ":=", "vols", "[", "m", ".", "Volume", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Volume", ")", "\n", "}", "\n", "vol", "=", "&", "vv", "\n", "}", "\n\n", "// Find a corresponding MountPoint, which is optional", "ro", ":=", "false", "\n", "for", "_", ",", "mp", ":=", "range", "ra", ".", "App", ".", "MountPoints", "{", "if", "mp", ".", "Name", "==", "m", ".", "Volume", "{", "ro", "=", "mp", ".", "ReadOnly", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "vol", ".", "ReadOnly", "!=", "nil", "{", "ro", "=", "*", "vol", ".", "ReadOnly", "\n", "}", "\n\n", "switch", "vol", ".", "Kind", "{", "case", "\"", "\"", ":", "case", "\"", "\"", ":", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vol", ".", "Name", ",", "vol", ".", "Kind", ")", "\n", "}", "\n", "genMnts", "=", "append", "(", "genMnts", ",", "Mount", "{", "Mount", ":", "m", ",", "DockerImplicit", ":", "false", ",", "ReadOnly", ":", "ro", ",", "Volume", ":", "*", "vol", ",", "}", ")", "\n", "}", "\n\n", "// Now, match up MountPoints with Mounts or Volumes", "// If there's no Mount and no Volume, generate an empty volume", "for", "_", ",", "mp", ":=", "range", "app", ".", "MountPoints", "{", "// there's already a Mount for this MountPoint, stop", "if", "_", ",", "ok", ":=", "mnts", "[", "mp", ".", "Path", "]", ";", "ok", "{", "continue", "\n", "}", "\n\n", "// No Mount, try to match based on volume name", "vol", ",", "ok", ":=", "vols", "[", "mp", ".", "Name", "]", "\n", "// there is no volume for this mount point, creating an \"empty\" volume", "// implicitly", "if", "!", "ok", "{", "defaultMode", ":=", "\"", "\"", "\n", "defaultUID", ":=", "0", "\n", "defaultGID", ":=", "0", "\n", "uniqName", ":=", "ra", ".", "Name", "+", "\"", "\"", "+", "mp", ".", "Name", "\n", "emptyVol", ":=", "types", ".", "Volume", "{", "Name", ":", "uniqName", ",", "Kind", ":", "\"", "\"", ",", "Mode", ":", "&", "defaultMode", ",", "UID", ":", "&", "defaultUID", ",", "GID", ":", "&", "defaultGID", ",", "}", "\n\n", "log", ".", "Printf", "(", "\"", "\\\"", "\\\"", "\"", ",", "mp", ".", "Name", ")", "\n", "if", "convertedFromDocker", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "mp", ".", "Name", ")", "\n", "}", "\n\n", "vols", "[", "uniqName", "]", "=", "emptyVol", "\n", "genMnts", "=", "append", "(", "genMnts", ",", "Mount", "{", "Mount", ":", "schema", ".", "Mount", "{", "Volume", ":", "uniqName", ",", "Path", ":", "mp", ".", "Path", ",", "}", ",", "Volume", ":", "emptyVol", ",", "ReadOnly", ":", "mp", ".", "ReadOnly", ",", "DockerImplicit", ":", "convertedFromDocker", ",", "}", ")", "\n", "}", "else", "{", "ro", ":=", "mp", ".", "ReadOnly", "\n", "if", "vol", ".", "ReadOnly", "!=", "nil", "{", "ro", "=", "*", "vol", ".", "ReadOnly", "\n", "}", "\n", "genMnts", "=", "append", "(", "genMnts", ",", "Mount", "{", "Mount", ":", "schema", ".", "Mount", "{", "Volume", ":", "vol", ".", "Name", ",", "Path", ":", "mp", ".", "Path", ",", "}", ",", "Volume", ":", "vol", ",", "ReadOnly", ":", "ro", ",", "DockerImplicit", ":", "false", ",", "}", ")", "\n", "}", "\n", "}", "\n\n", "return", "genMnts", ",", "nil", "\n", "}" ]
// GenerateMounts maps MountPoint paths to volumes, returning a list of mounts, // each with a parameter indicating if it's an implicit empty volume from a // Docker image.
[ "GenerateMounts", "maps", "MountPoint", "paths", "to", "volumes", "returning", "a", "list", "of", "mounts", "each", "with", "a", "parameter", "indicating", "if", "it", "s", "an", "implicit", "empty", "volume", "from", "a", "Docker", "image", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/mount.go#L77-L196
167,173
rkt/rkt
stage1/init/common/mount.go
EnsureTargetExists
func EnsureTargetExists(source, destination string) error { fileInfo, err := os.Stat(source) if err != nil { return errwrap.Wrap(fmt.Errorf("could not stat source location: %v", source), err) } targetPathParent, _ := filepath.Split(destination) if err := os.MkdirAll(targetPathParent, common.SharedVolumePerm); err != nil { return errwrap.Wrap(fmt.Errorf("could not create parent directory: %v", targetPathParent), err) } if fileInfo.IsDir() { if err := os.Mkdir(destination, common.SharedVolumePerm); err != nil && !os.IsExist(err) { return errwrap.Wrap(errors.New("could not create destination directory "+destination), err) } } else { if file, err := os.OpenFile(destination, os.O_CREATE, common.SharedVolumePerm); err != nil { return errwrap.Wrap(errors.New("could not create destination file"), err) } else { file.Close() } } return nil }
go
func EnsureTargetExists(source, destination string) error { fileInfo, err := os.Stat(source) if err != nil { return errwrap.Wrap(fmt.Errorf("could not stat source location: %v", source), err) } targetPathParent, _ := filepath.Split(destination) if err := os.MkdirAll(targetPathParent, common.SharedVolumePerm); err != nil { return errwrap.Wrap(fmt.Errorf("could not create parent directory: %v", targetPathParent), err) } if fileInfo.IsDir() { if err := os.Mkdir(destination, common.SharedVolumePerm); err != nil && !os.IsExist(err) { return errwrap.Wrap(errors.New("could not create destination directory "+destination), err) } } else { if file, err := os.OpenFile(destination, os.O_CREATE, common.SharedVolumePerm); err != nil { return errwrap.Wrap(errors.New("could not create destination file"), err) } else { file.Close() } } return nil }
[ "func", "EnsureTargetExists", "(", "source", ",", "destination", "string", ")", "error", "{", "fileInfo", ",", "err", ":=", "os", ".", "Stat", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "source", ")", ",", "err", ")", "\n", "}", "\n\n", "targetPathParent", ",", "_", ":=", "filepath", ".", "Split", "(", "destination", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "targetPathParent", ",", "common", ".", "SharedVolumePerm", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "targetPathParent", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "fileInfo", ".", "IsDir", "(", ")", "{", "if", "err", ":=", "os", ".", "Mkdir", "(", "destination", ",", "common", ".", "SharedVolumePerm", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsExist", "(", "err", ")", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", "+", "destination", ")", ",", "err", ")", "\n", "}", "\n", "}", "else", "{", "if", "file", ",", "err", ":=", "os", ".", "OpenFile", "(", "destination", ",", "os", ".", "O_CREATE", ",", "common", ".", "SharedVolumePerm", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "else", "{", "file", ".", "Close", "(", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// EnsureTargetExists will recursively create a given mountpoint. If directories // are created, their permissions are initialized to common.SharedVolumePerm
[ "EnsureTargetExists", "will", "recursively", "create", "a", "given", "mountpoint", ".", "If", "directories", "are", "created", "their", "permissions", "are", "initialized", "to", "common", ".", "SharedVolumePerm" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/mount.go#L274-L297
167,174
rkt/rkt
rkt/image/httpops.go
DownloadSignature
func (o *httpOps) DownloadSignature(a *asc) (readSeekCloser, bool, error) { ensureLogger(o.Debug) diag.Printf("downloading signature from %v", a.Location) ascFile, err := a.Get() if err == nil { return ascFile, false, nil } if _, ok := err.(*statusAcceptedError); ok { log.Printf("server requested deferring the signature download") return NopReadSeekCloser(nil), true, nil } return nil, false, errwrap.Wrap(errors.New("error downloading the signature file"), err) }
go
func (o *httpOps) DownloadSignature(a *asc) (readSeekCloser, bool, error) { ensureLogger(o.Debug) diag.Printf("downloading signature from %v", a.Location) ascFile, err := a.Get() if err == nil { return ascFile, false, nil } if _, ok := err.(*statusAcceptedError); ok { log.Printf("server requested deferring the signature download") return NopReadSeekCloser(nil), true, nil } return nil, false, errwrap.Wrap(errors.New("error downloading the signature file"), err) }
[ "func", "(", "o", "*", "httpOps", ")", "DownloadSignature", "(", "a", "*", "asc", ")", "(", "readSeekCloser", ",", "bool", ",", "error", ")", "{", "ensureLogger", "(", "o", ".", "Debug", ")", "\n", "diag", ".", "Printf", "(", "\"", "\"", ",", "a", ".", "Location", ")", "\n", "ascFile", ",", "err", ":=", "a", ".", "Get", "(", ")", "\n", "if", "err", "==", "nil", "{", "return", "ascFile", ",", "false", ",", "nil", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "statusAcceptedError", ")", ";", "ok", "{", "log", ".", "Printf", "(", "\"", "\"", ")", "\n", "return", "NopReadSeekCloser", "(", "nil", ")", ",", "true", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "false", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}" ]
// DownloadSignature takes an asc instance and tries to get the // signature. If the remote server asked to to defer the download, // this function will return true and no error and no file.
[ "DownloadSignature", "takes", "an", "asc", "instance", "and", "tries", "to", "get", "the", "signature", ".", "If", "the", "remote", "server", "asked", "to", "to", "defer", "the", "download", "this", "function", "will", "return", "true", "and", "no", "error", "and", "no", "file", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpops.go#L43-L55
167,175
rkt/rkt
rkt/image/httpops.go
DownloadSignatureAgain
func (o *httpOps) DownloadSignatureAgain(a *asc) (readSeekCloser, error) { ensureLogger(o.Debug) ascFile, retry, err := o.DownloadSignature(a) if err != nil { return nil, err } if retry { return nil, fmt.Errorf("error downloading the signature file: server asked to defer the download again") } return ascFile, nil }
go
func (o *httpOps) DownloadSignatureAgain(a *asc) (readSeekCloser, error) { ensureLogger(o.Debug) ascFile, retry, err := o.DownloadSignature(a) if err != nil { return nil, err } if retry { return nil, fmt.Errorf("error downloading the signature file: server asked to defer the download again") } return ascFile, nil }
[ "func", "(", "o", "*", "httpOps", ")", "DownloadSignatureAgain", "(", "a", "*", "asc", ")", "(", "readSeekCloser", ",", "error", ")", "{", "ensureLogger", "(", "o", ".", "Debug", ")", "\n", "ascFile", ",", "retry", ",", "err", ":=", "o", ".", "DownloadSignature", "(", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "retry", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "ascFile", ",", "nil", "\n", "}" ]
// DownloadSignatureAgain does a similar thing to DownloadSignature, // but it expects the signature to be actually provided, that is - no // deferring this time.
[ "DownloadSignatureAgain", "does", "a", "similar", "thing", "to", "DownloadSignature", "but", "it", "expects", "the", "signature", "to", "be", "actually", "provided", "that", "is", "-", "no", "deferring", "this", "time", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpops.go#L60-L70
167,176
rkt/rkt
rkt/image/httpops.go
DownloadImage
func (o *httpOps) DownloadImage(u *url.URL) (readSeekCloser, *cacheData, error) { ensureLogger(o.Debug) image, cd, err := o.DownloadImageWithETag(u, "") if err != nil { return nil, nil, err } if cd.UseCached { return nil, nil, fmt.Errorf("asked to use cached image even if not asked for that") } return image, cd, nil }
go
func (o *httpOps) DownloadImage(u *url.URL) (readSeekCloser, *cacheData, error) { ensureLogger(o.Debug) image, cd, err := o.DownloadImageWithETag(u, "") if err != nil { return nil, nil, err } if cd.UseCached { return nil, nil, fmt.Errorf("asked to use cached image even if not asked for that") } return image, cd, nil }
[ "func", "(", "o", "*", "httpOps", ")", "DownloadImage", "(", "u", "*", "url", ".", "URL", ")", "(", "readSeekCloser", ",", "*", "cacheData", ",", "error", ")", "{", "ensureLogger", "(", "o", ".", "Debug", ")", "\n", "image", ",", "cd", ",", "err", ":=", "o", ".", "DownloadImageWithETag", "(", "u", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "if", "cd", ".", "UseCached", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "image", ",", "cd", ",", "nil", "\n", "}" ]
// DownloadImage download the image, duh. It expects to actually // receive the file, instead of being asked to use the cached version.
[ "DownloadImage", "download", "the", "image", "duh", ".", "It", "expects", "to", "actually", "receive", "the", "file", "instead", "of", "being", "asked", "to", "use", "the", "cached", "version", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpops.go#L74-L84
167,177
rkt/rkt
rkt/image/httpops.go
DownloadImageWithETag
func (o *httpOps) DownloadImageWithETag(u *url.URL, etag string) (readSeekCloser, *cacheData, error) { var aciFile *removeOnClose // closed on error var errClose error // error signaling to close aciFile ensureLogger(o.Debug) aciFile, err := getTmpROC(o.S, u.String()) if err != nil { return nil, nil, err } defer func() { if errClose != nil { aciFile.Close() } }() session := o.getSession(u, aciFile.File, "ACI", etag) dl := o.getDownloader(session) errClose = dl.Download(u, aciFile.File) if errClose != nil { return nil, nil, errwrap.Wrap(errors.New("error downloading ACI"), errClose) } if session.Cd.UseCached { aciFile.Close() return NopReadSeekCloser(nil), session.Cd, nil } return aciFile, session.Cd, nil }
go
func (o *httpOps) DownloadImageWithETag(u *url.URL, etag string) (readSeekCloser, *cacheData, error) { var aciFile *removeOnClose // closed on error var errClose error // error signaling to close aciFile ensureLogger(o.Debug) aciFile, err := getTmpROC(o.S, u.String()) if err != nil { return nil, nil, err } defer func() { if errClose != nil { aciFile.Close() } }() session := o.getSession(u, aciFile.File, "ACI", etag) dl := o.getDownloader(session) errClose = dl.Download(u, aciFile.File) if errClose != nil { return nil, nil, errwrap.Wrap(errors.New("error downloading ACI"), errClose) } if session.Cd.UseCached { aciFile.Close() return NopReadSeekCloser(nil), session.Cd, nil } return aciFile, session.Cd, nil }
[ "func", "(", "o", "*", "httpOps", ")", "DownloadImageWithETag", "(", "u", "*", "url", ".", "URL", ",", "etag", "string", ")", "(", "readSeekCloser", ",", "*", "cacheData", ",", "error", ")", "{", "var", "aciFile", "*", "removeOnClose", "// closed on error", "\n", "var", "errClose", "error", "// error signaling to close aciFile", "\n\n", "ensureLogger", "(", "o", ".", "Debug", ")", "\n", "aciFile", ",", "err", ":=", "getTmpROC", "(", "o", ".", "S", ",", "u", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "if", "errClose", "!=", "nil", "{", "aciFile", ".", "Close", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "session", ":=", "o", ".", "getSession", "(", "u", ",", "aciFile", ".", "File", ",", "\"", "\"", ",", "etag", ")", "\n", "dl", ":=", "o", ".", "getDownloader", "(", "session", ")", "\n", "errClose", "=", "dl", ".", "Download", "(", "u", ",", "aciFile", ".", "File", ")", "\n", "if", "errClose", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "errClose", ")", "\n", "}", "\n\n", "if", "session", ".", "Cd", ".", "UseCached", "{", "aciFile", ".", "Close", "(", ")", "\n", "return", "NopReadSeekCloser", "(", "nil", ")", ",", "session", ".", "Cd", ",", "nil", "\n", "}", "\n\n", "return", "aciFile", ",", "session", ".", "Cd", ",", "nil", "\n", "}" ]
// DownloadImageWithETag might download an image or tell you to use // the cached image. In the latter case the returned file will be nil.
[ "DownloadImageWithETag", "might", "download", "an", "image", "or", "tell", "you", "to", "use", "the", "cached", "image", ".", "In", "the", "latter", "case", "the", "returned", "file", "will", "be", "nil", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpops.go#L88-L117
167,178
rkt/rkt
rkt/image/httpops.go
AscRemoteFetcher
func (o *httpOps) AscRemoteFetcher() *remoteAscFetcher { ensureLogger(o.Debug) f := func(u *url.URL, file *os.File) error { switch u.Scheme { case "http", "https": default: return fmt.Errorf("invalid signature location: expected %q scheme, got %q", "http(s)", u.Scheme) } session := o.getSession(u, file, "signature", "") dl := o.getDownloader(session) err := dl.Download(u, file) if err != nil { return err } if session.Cd.UseCached { return fmt.Errorf("unexpected cache reuse request for signature %q", u.String()) } return nil } return &remoteAscFetcher{ F: f, S: o.S, } }
go
func (o *httpOps) AscRemoteFetcher() *remoteAscFetcher { ensureLogger(o.Debug) f := func(u *url.URL, file *os.File) error { switch u.Scheme { case "http", "https": default: return fmt.Errorf("invalid signature location: expected %q scheme, got %q", "http(s)", u.Scheme) } session := o.getSession(u, file, "signature", "") dl := o.getDownloader(session) err := dl.Download(u, file) if err != nil { return err } if session.Cd.UseCached { return fmt.Errorf("unexpected cache reuse request for signature %q", u.String()) } return nil } return &remoteAscFetcher{ F: f, S: o.S, } }
[ "func", "(", "o", "*", "httpOps", ")", "AscRemoteFetcher", "(", ")", "*", "remoteAscFetcher", "{", "ensureLogger", "(", "o", ".", "Debug", ")", "\n", "f", ":=", "func", "(", "u", "*", "url", ".", "URL", ",", "file", "*", "os", ".", "File", ")", "error", "{", "switch", "u", ".", "Scheme", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "\"", "\"", ",", "u", ".", "Scheme", ")", "\n", "}", "\n", "session", ":=", "o", ".", "getSession", "(", "u", ",", "file", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "dl", ":=", "o", ".", "getDownloader", "(", "session", ")", "\n", "err", ":=", "dl", ".", "Download", "(", "u", ",", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "session", ".", "Cd", ".", "UseCached", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "return", "&", "remoteAscFetcher", "{", "F", ":", "f", ",", "S", ":", "o", ".", "S", ",", "}", "\n", "}" ]
// AscRemoteFetcher provides a remoteAscFetcher for asc.
[ "AscRemoteFetcher", "provides", "a", "remoteAscFetcher", "for", "asc", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/httpops.go#L120-L143
167,179
rkt/rkt
stage1/iottymux/iottymux.go
actionAttach
func actionAttach(statusPath string, autoMode bool) error { var endpoints Targets dialTimeout := 15 * time.Second // retrieve available endpoints statusFile, err := os.OpenFile(statusPath, os.O_RDONLY, os.ModePerm) if err != nil { return err } err = json.NewDecoder(statusFile).Decode(&endpoints) _ = statusFile.Close() if err != nil { return err } // retrieve custom attaching modes customTargets := struct { ttyIn bool ttyOut bool stdin bool stdout bool stderr bool }{} if !autoMode { customTargets.ttyIn, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_TTYIN")) customTargets.ttyOut, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_TTYOUT")) customTargets.stdin, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDIN")) customTargets.stdout, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDOUT")) customTargets.stderr, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDERR")) } // Proxy I/O between this process and the iottymux service: // - input (stdin, tty-in) copying routines can only be canceled by process killing (ie. user detaching) // - output (stdout, stderr, tty-out) copying routines are canceled by errors when reading from remote service c := make(chan error) copyOut := func(w io.Writer, conn net.Conn) { _, err := io.Copy(w, conn) c <- err } for _, ep := range endpoints.Targets { d := net.Dialer{Timeout: dialTimeout} conn, err := d.Dial(ep.Domain, ep.Address) if err != nil { return err } defer conn.Close() switch ep.Name { case "stdin": if autoMode || customTargets.stdin { go io.Copy(conn, os.Stdin) } case "stdout": if autoMode || customTargets.stdout { go copyOut(os.Stdout, conn) } case "stderr": if autoMode || customTargets.stderr { go copyOut(os.Stderr, conn) } case "tty": if autoMode || customTargets.ttyIn { go io.Copy(conn, os.Stdin) } if autoMode || customTargets.ttyOut { go copyOut(os.Stdout, conn) } else { go copyOut(ioutil.Discard, conn) } } } // as soon as one output copying routine fails, this unblocks and the whole process exits return <-c }
go
func actionAttach(statusPath string, autoMode bool) error { var endpoints Targets dialTimeout := 15 * time.Second // retrieve available endpoints statusFile, err := os.OpenFile(statusPath, os.O_RDONLY, os.ModePerm) if err != nil { return err } err = json.NewDecoder(statusFile).Decode(&endpoints) _ = statusFile.Close() if err != nil { return err } // retrieve custom attaching modes customTargets := struct { ttyIn bool ttyOut bool stdin bool stdout bool stderr bool }{} if !autoMode { customTargets.ttyIn, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_TTYIN")) customTargets.ttyOut, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_TTYOUT")) customTargets.stdin, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDIN")) customTargets.stdout, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDOUT")) customTargets.stderr, _ = strconv.ParseBool(os.Getenv("STAGE2_ATTACH_STDERR")) } // Proxy I/O between this process and the iottymux service: // - input (stdin, tty-in) copying routines can only be canceled by process killing (ie. user detaching) // - output (stdout, stderr, tty-out) copying routines are canceled by errors when reading from remote service c := make(chan error) copyOut := func(w io.Writer, conn net.Conn) { _, err := io.Copy(w, conn) c <- err } for _, ep := range endpoints.Targets { d := net.Dialer{Timeout: dialTimeout} conn, err := d.Dial(ep.Domain, ep.Address) if err != nil { return err } defer conn.Close() switch ep.Name { case "stdin": if autoMode || customTargets.stdin { go io.Copy(conn, os.Stdin) } case "stdout": if autoMode || customTargets.stdout { go copyOut(os.Stdout, conn) } case "stderr": if autoMode || customTargets.stderr { go copyOut(os.Stderr, conn) } case "tty": if autoMode || customTargets.ttyIn { go io.Copy(conn, os.Stdin) } if autoMode || customTargets.ttyOut { go copyOut(os.Stdout, conn) } else { go copyOut(ioutil.Discard, conn) } } } // as soon as one output copying routine fails, this unblocks and the whole process exits return <-c }
[ "func", "actionAttach", "(", "statusPath", "string", ",", "autoMode", "bool", ")", "error", "{", "var", "endpoints", "Targets", "\n", "dialTimeout", ":=", "15", "*", "time", ".", "Second", "\n\n", "// retrieve available endpoints", "statusFile", ",", "err", ":=", "os", ".", "OpenFile", "(", "statusPath", ",", "os", ".", "O_RDONLY", ",", "os", ".", "ModePerm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "json", ".", "NewDecoder", "(", "statusFile", ")", ".", "Decode", "(", "&", "endpoints", ")", "\n", "_", "=", "statusFile", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// retrieve custom attaching modes", "customTargets", ":=", "struct", "{", "ttyIn", "bool", "\n", "ttyOut", "bool", "\n", "stdin", "bool", "\n", "stdout", "bool", "\n", "stderr", "bool", "\n", "}", "{", "}", "\n", "if", "!", "autoMode", "{", "customTargets", ".", "ttyIn", ",", "_", "=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "customTargets", ".", "ttyOut", ",", "_", "=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "customTargets", ".", "stdin", ",", "_", "=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "customTargets", ".", "stdout", ",", "_", "=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "customTargets", ".", "stderr", ",", "_", "=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "// Proxy I/O between this process and the iottymux service:", "// - input (stdin, tty-in) copying routines can only be canceled by process killing (ie. user detaching)", "// - output (stdout, stderr, tty-out) copying routines are canceled by errors when reading from remote service", "c", ":=", "make", "(", "chan", "error", ")", "\n", "copyOut", ":=", "func", "(", "w", "io", ".", "Writer", ",", "conn", "net", ".", "Conn", ")", "{", "_", ",", "err", ":=", "io", ".", "Copy", "(", "w", ",", "conn", ")", "\n", "c", "<-", "err", "\n", "}", "\n\n", "for", "_", ",", "ep", ":=", "range", "endpoints", ".", "Targets", "{", "d", ":=", "net", ".", "Dialer", "{", "Timeout", ":", "dialTimeout", "}", "\n", "conn", ",", "err", ":=", "d", ".", "Dial", "(", "ep", ".", "Domain", ",", "ep", ".", "Address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "switch", "ep", ".", "Name", "{", "case", "\"", "\"", ":", "if", "autoMode", "||", "customTargets", ".", "stdin", "{", "go", "io", ".", "Copy", "(", "conn", ",", "os", ".", "Stdin", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "if", "autoMode", "||", "customTargets", ".", "stdout", "{", "go", "copyOut", "(", "os", ".", "Stdout", ",", "conn", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "if", "autoMode", "||", "customTargets", ".", "stderr", "{", "go", "copyOut", "(", "os", ".", "Stderr", ",", "conn", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "if", "autoMode", "||", "customTargets", ".", "ttyIn", "{", "go", "io", ".", "Copy", "(", "conn", ",", "os", ".", "Stdin", ")", "\n", "}", "\n\n", "if", "autoMode", "||", "customTargets", ".", "ttyOut", "{", "go", "copyOut", "(", "os", ".", "Stdout", ",", "conn", ")", "\n", "}", "else", "{", "go", "copyOut", "(", "ioutil", ".", "Discard", ",", "conn", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// as soon as one output copying routine fails, this unblocks and the whole process exits", "return", "<-", "c", "\n", "}" ]
// actionAttach handles the attach action, either in "automatic" or "custom endpoints" mode.
[ "actionAttach", "handles", "the", "attach", "action", "either", "in", "automatic", "or", "custom", "endpoints", "mode", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L137-L212
167,180
rkt/rkt
stage1/iottymux/iottymux.go
dispatchSig
func dispatchSig(stop chan<- error) { sigChan := make(chan os.Signal) signal.Notify( sigChan, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, ) go func() { diag.Println("Waiting for signal") sig := <-sigChan diag.Printf("Received signal %v\n", sig) close(stop) }() }
go
func dispatchSig(stop chan<- error) { sigChan := make(chan os.Signal) signal.Notify( sigChan, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, ) go func() { diag.Println("Waiting for signal") sig := <-sigChan diag.Printf("Received signal %v\n", sig) close(stop) }() }
[ "func", "dispatchSig", "(", "stop", "chan", "<-", "error", ")", "{", "sigChan", ":=", "make", "(", "chan", "os", ".", "Signal", ")", "\n", "signal", ".", "Notify", "(", "sigChan", ",", "syscall", ".", "SIGTERM", ",", "syscall", ".", "SIGHUP", ",", "syscall", ".", "SIGINT", ",", ")", "\n\n", "go", "func", "(", ")", "{", "diag", ".", "Println", "(", "\"", "\"", ")", "\n", "sig", ":=", "<-", "sigChan", "\n", "diag", ".", "Printf", "(", "\"", "\\n", "\"", ",", "sig", ")", "\n", "close", "(", "stop", ")", "\n", "}", "(", ")", "\n", "}" ]
// dispatchSig launches a goroutine and closes the given stop channel // when SIGTERM, SIGHUP, or SIGINT is received.
[ "dispatchSig", "launches", "a", "goroutine", "and", "closes", "the", "given", "stop", "channel", "when", "SIGTERM", "SIGHUP", "or", "SIGINT", "is", "received", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L475-L490
167,181
rkt/rkt
stage1/iottymux/iottymux.go
bufferLine
func bufferLine(src io.Reader, c chan<- []byte, ec chan<- error) { rd := bufio.NewReader(src) for { lineOut, err := rd.ReadBytes('\n') if len(lineOut) > 0 { c <- lineOut } if err != nil { ec <- err } } }
go
func bufferLine(src io.Reader, c chan<- []byte, ec chan<- error) { rd := bufio.NewReader(src) for { lineOut, err := rd.ReadBytes('\n') if len(lineOut) > 0 { c <- lineOut } if err != nil { ec <- err } } }
[ "func", "bufferLine", "(", "src", "io", ".", "Reader", ",", "c", "chan", "<-", "[", "]", "byte", ",", "ec", "chan", "<-", "error", ")", "{", "rd", ":=", "bufio", ".", "NewReader", "(", "src", ")", "\n", "for", "{", "lineOut", ",", "err", ":=", "rd", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "len", "(", "lineOut", ")", ">", "0", "{", "c", "<-", "lineOut", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "ec", "<-", "err", "\n", "}", "\n", "}", "\n", "}" ]
// bufferLine buffers and queues a single line from a Reader to a multiplexer // If reading from src fails, it hard-fails and propagates the error back.
[ "bufferLine", "buffers", "and", "queues", "a", "single", "line", "from", "a", "Reader", "to", "a", "multiplexer", "If", "reading", "from", "src", "fails", "it", "hard", "-", "fails", "and", "propagates", "the", "error", "back", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L494-L505
167,182
rkt/rkt
stage1/iottymux/iottymux.go
acceptConn
func acceptConn(socket net.Listener, c chan<- net.Conn, stream string) { for { conn, err := socket.Accept() if err == nil { diag.Printf("Accepted new connection for %s\n", stream) c <- conn } } }
go
func acceptConn(socket net.Listener, c chan<- net.Conn, stream string) { for { conn, err := socket.Accept() if err == nil { diag.Printf("Accepted new connection for %s\n", stream) c <- conn } } }
[ "func", "acceptConn", "(", "socket", "net", ".", "Listener", ",", "c", "chan", "<-", "net", ".", "Conn", ",", "stream", "string", ")", "{", "for", "{", "conn", ",", "err", ":=", "socket", ".", "Accept", "(", ")", "\n", "if", "err", "==", "nil", "{", "diag", ".", "Printf", "(", "\"", "\\n", "\"", ",", "stream", ")", "\n", "c", "<-", "conn", "\n", "}", "\n", "}", "\n", "}" ]
// acceptConn accepts a single client and queues it for further proxying // It is never canceled explicitly, as it is bound to the lifetime of the main process.
[ "acceptConn", "accepts", "a", "single", "client", "and", "queues", "it", "for", "further", "proxying", "It", "is", "never", "canceled", "explicitly", "as", "it", "is", "bound", "to", "the", "lifetime", "of", "the", "main", "process", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L509-L517
167,183
rkt/rkt
stage1/iottymux/iottymux.go
muxInput
func muxInput(clients <-chan net.Conn, stdin *os.File) { for { select { case c := <-clients: go bufferInput(c, stdin) } } }
go
func muxInput(clients <-chan net.Conn, stdin *os.File) { for { select { case c := <-clients: go bufferInput(c, stdin) } } }
[ "func", "muxInput", "(", "clients", "<-", "chan", "net", ".", "Conn", ",", "stdin", "*", "os", ".", "File", ")", "{", "for", "{", "select", "{", "case", "c", ":=", "<-", "clients", ":", "go", "bufferInput", "(", "c", ",", "stdin", ")", "\n", "}", "\n", "}", "\n", "}" ]
// muxInput accepts remote clients and multiplex input line from them
[ "muxInput", "accepts", "remote", "clients", "and", "multiplex", "input", "line", "from", "them" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L558-L565
167,184
rkt/rkt
stage1/iottymux/iottymux.go
bufferInput
func bufferInput(conn net.Conn, stdin *os.File) { rd := bufio.NewReader(conn) defer conn.Close() for { lineIn, err := rd.ReadBytes('\n') if len(lineIn) == 0 && err != nil { return } _, err = stdin.Write(lineIn) if err != nil { return } } }
go
func bufferInput(conn net.Conn, stdin *os.File) { rd := bufio.NewReader(conn) defer conn.Close() for { lineIn, err := rd.ReadBytes('\n') if len(lineIn) == 0 && err != nil { return } _, err = stdin.Write(lineIn) if err != nil { return } } }
[ "func", "bufferInput", "(", "conn", "net", ".", "Conn", ",", "stdin", "*", "os", ".", "File", ")", "{", "rd", ":=", "bufio", ".", "NewReader", "(", "conn", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "for", "{", "lineIn", ",", "err", ":=", "rd", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "len", "(", "lineIn", ")", "==", "0", "&&", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "stdin", ".", "Write", "(", "lineIn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "}" ]
// bufferInput buffers and write a single line from a remote client to the local app
[ "bufferInput", "buffers", "and", "write", "a", "single", "line", "from", "a", "remote", "client", "to", "the", "local", "app" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L568-L581
167,185
rkt/rkt
stage1/iottymux/iottymux.go
muxOutput
func muxOutput(streamLabel string, lines chan []byte, clients <-chan net.Conn, targets <-chan io.WriteCloser) { var logs []io.WriteCloser var conns []io.WriteCloser writeAndFilter := func(wc io.WriteCloser, line []byte) bool { _, err := wc.Write(line) if err != nil { wc.Close() } return err != nil } logsWriteAndFilter := func(wc io.WriteCloser, line []byte) bool { out := []byte(fmt.Sprintf("%s %s %s", time.Now().Format(time.RFC3339Nano), streamLabel, line)) return writeAndFilter(wc, out) } for { select { // an incoming output line to multiplex // TODO(lucab): ordered non-blocking writes case l := <-lines: conns = filterTargets(conns, l, writeAndFilter) logs = filterTargets(logs, l, logsWriteAndFilter) // a new remote client case c := <-clients: conns = append(conns, c) // a new local log target case t := <-targets: logs = append(logs, t) } } }
go
func muxOutput(streamLabel string, lines chan []byte, clients <-chan net.Conn, targets <-chan io.WriteCloser) { var logs []io.WriteCloser var conns []io.WriteCloser writeAndFilter := func(wc io.WriteCloser, line []byte) bool { _, err := wc.Write(line) if err != nil { wc.Close() } return err != nil } logsWriteAndFilter := func(wc io.WriteCloser, line []byte) bool { out := []byte(fmt.Sprintf("%s %s %s", time.Now().Format(time.RFC3339Nano), streamLabel, line)) return writeAndFilter(wc, out) } for { select { // an incoming output line to multiplex // TODO(lucab): ordered non-blocking writes case l := <-lines: conns = filterTargets(conns, l, writeAndFilter) logs = filterTargets(logs, l, logsWriteAndFilter) // a new remote client case c := <-clients: conns = append(conns, c) // a new local log target case t := <-targets: logs = append(logs, t) } } }
[ "func", "muxOutput", "(", "streamLabel", "string", ",", "lines", "chan", "[", "]", "byte", ",", "clients", "<-", "chan", "net", ".", "Conn", ",", "targets", "<-", "chan", "io", ".", "WriteCloser", ")", "{", "var", "logs", "[", "]", "io", ".", "WriteCloser", "\n", "var", "conns", "[", "]", "io", ".", "WriteCloser", "\n\n", "writeAndFilter", ":=", "func", "(", "wc", "io", ".", "WriteCloser", ",", "line", "[", "]", "byte", ")", "bool", "{", "_", ",", "err", ":=", "wc", ".", "Write", "(", "line", ")", "\n", "if", "err", "!=", "nil", "{", "wc", ".", "Close", "(", ")", "\n", "}", "\n", "return", "err", "!=", "nil", "\n", "}", "\n\n", "logsWriteAndFilter", ":=", "func", "(", "wc", "io", ".", "WriteCloser", ",", "line", "[", "]", "byte", ")", "bool", "{", "out", ":=", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "Format", "(", "time", ".", "RFC3339Nano", ")", ",", "streamLabel", ",", "line", ")", ")", "\n", "return", "writeAndFilter", "(", "wc", ",", "out", ")", "\n", "}", "\n\n", "for", "{", "select", "{", "// an incoming output line to multiplex", "// TODO(lucab): ordered non-blocking writes", "case", "l", ":=", "<-", "lines", ":", "conns", "=", "filterTargets", "(", "conns", ",", "l", ",", "writeAndFilter", ")", "\n", "logs", "=", "filterTargets", "(", "logs", ",", "l", ",", "logsWriteAndFilter", ")", "\n\n", "// a new remote client", "case", "c", ":=", "<-", "clients", ":", "conns", "=", "append", "(", "conns", ",", "c", ")", "\n\n", "// a new local log target", "case", "t", ":=", "<-", "targets", ":", "logs", "=", "append", "(", "logs", ",", "t", ")", "\n", "}", "\n", "}", "\n", "}" ]
// muxOutput receives remote clients and local log targets, // multiplexing output lines to them
[ "muxOutput", "receives", "remote", "clients", "and", "local", "log", "targets", "multiplexing", "output", "lines", "to", "them" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L585-L619
167,186
rkt/rkt
stage1/iottymux/iottymux.go
filterTargets
func filterTargets( wcs []io.WriteCloser, line []byte, filter func(io.WriteCloser, []byte) bool, ) []io.WriteCloser { var filteredTargets []io.WriteCloser for _, c := range wcs { if !filter(c, line) { filteredTargets = append(filteredTargets, c) } } return filteredTargets }
go
func filterTargets( wcs []io.WriteCloser, line []byte, filter func(io.WriteCloser, []byte) bool, ) []io.WriteCloser { var filteredTargets []io.WriteCloser for _, c := range wcs { if !filter(c, line) { filteredTargets = append(filteredTargets, c) } } return filteredTargets }
[ "func", "filterTargets", "(", "wcs", "[", "]", "io", ".", "WriteCloser", ",", "line", "[", "]", "byte", ",", "filter", "func", "(", "io", ".", "WriteCloser", ",", "[", "]", "byte", ")", "bool", ",", ")", "[", "]", "io", ".", "WriteCloser", "{", "var", "filteredTargets", "[", "]", "io", ".", "WriteCloser", "\n\n", "for", "_", ",", "c", ":=", "range", "wcs", "{", "if", "!", "filter", "(", "c", ",", "line", ")", "{", "filteredTargets", "=", "append", "(", "filteredTargets", ",", "c", ")", "\n", "}", "\n", "}", "\n", "return", "filteredTargets", "\n", "}" ]
// filterTargets passes line to each writer in wcs, // filtering out single writers if filter returns true.
[ "filterTargets", "passes", "line", "to", "each", "writer", "in", "wcs", "filtering", "out", "single", "writers", "if", "filter", "returns", "true", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/iottymux/iottymux.go#L623-L636
167,187
rkt/rkt
pkg/keystore/keystore.go
New
func New(config *Config) *Keystore { if config == nil { config = defaultConfig } return &Keystore{config} }
go
func New(config *Config) *Keystore { if config == nil { config = defaultConfig } return &Keystore{config} }
[ "func", "New", "(", "config", "*", "Config", ")", "*", "Keystore", "{", "if", "config", "==", "nil", "{", "config", "=", "defaultConfig", "\n", "}", "\n", "return", "&", "Keystore", "{", "config", "}", "\n", "}" ]
// New returns a new Keystore based on config.
[ "New", "returns", "a", "new", "Keystore", "based", "on", "config", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L50-L55
167,188
rkt/rkt
pkg/keystore/keystore.go
CheckSignature
func CheckSignature(prefix string, signed, signature io.ReadSeeker) (*openpgp.Entity, error) { ks := New(defaultConfig) return checkSignature(ks, prefix, signed, signature) }
go
func CheckSignature(prefix string, signed, signature io.ReadSeeker) (*openpgp.Entity, error) { ks := New(defaultConfig) return checkSignature(ks, prefix, signed, signature) }
[ "func", "CheckSignature", "(", "prefix", "string", ",", "signed", ",", "signature", "io", ".", "ReadSeeker", ")", "(", "*", "openpgp", ".", "Entity", ",", "error", ")", "{", "ks", ":=", "New", "(", "defaultConfig", ")", "\n", "return", "checkSignature", "(", "ks", ",", "prefix", ",", "signed", ",", "signature", ")", "\n", "}" ]
// CheckSignature is a convenience method for creating a Keystore with a default // configuration and invoking CheckSignature.
[ "CheckSignature", "is", "a", "convenience", "method", "for", "creating", "a", "Keystore", "with", "a", "default", "configuration", "and", "invoking", "CheckSignature", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L70-L73
167,189
rkt/rkt
pkg/keystore/keystore.go
DeleteTrustedKeyPrefix
func (ks *Keystore) DeleteTrustedKeyPrefix(prefix, fingerprint string) error { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return err } return os.Remove(path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint)) }
go
func (ks *Keystore) DeleteTrustedKeyPrefix(prefix, fingerprint string) error { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return err } return os.Remove(path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint)) }
[ "func", "(", "ks", "*", "Keystore", ")", "DeleteTrustedKeyPrefix", "(", "prefix", ",", "fingerprint", "string", ")", "error", "{", "acidentifier", ",", "err", ":=", "types", ".", "NewACIdentifier", "(", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "os", ".", "Remove", "(", "path", ".", "Join", "(", "ks", ".", "LocalPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ",", "fingerprint", ")", ")", "\n", "}" ]
// DeleteTrustedKeyPrefix deletes the prefix trusted key identified by fingerprint.
[ "DeleteTrustedKeyPrefix", "deletes", "the", "prefix", "trusted", "key", "identified", "by", "fingerprint", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L111-L117
167,190
rkt/rkt
pkg/keystore/keystore.go
MaskTrustedKeySystemPrefix
func (ks *Keystore) MaskTrustedKeySystemPrefix(prefix, fingerprint string) (string, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return "", err } dst := path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint) if err := ioutil.WriteFile(dst, []byte(""), 0644); err != nil { return "", err } if err := os.Chmod(dst, 0644); err != nil { return "", err } return dst, nil }
go
func (ks *Keystore) MaskTrustedKeySystemPrefix(prefix, fingerprint string) (string, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return "", err } dst := path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint) if err := ioutil.WriteFile(dst, []byte(""), 0644); err != nil { return "", err } if err := os.Chmod(dst, 0644); err != nil { return "", err } return dst, nil }
[ "func", "(", "ks", "*", "Keystore", ")", "MaskTrustedKeySystemPrefix", "(", "prefix", ",", "fingerprint", "string", ")", "(", "string", ",", "error", ")", "{", "acidentifier", ",", "err", ":=", "types", ".", "NewACIdentifier", "(", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "dst", ":=", "path", ".", "Join", "(", "ks", ".", "LocalPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ",", "fingerprint", ")", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "dst", ",", "[", "]", "byte", "(", "\"", "\"", ")", ",", "0644", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "err", ":=", "os", ".", "Chmod", "(", "dst", ",", "0644", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "dst", ",", "nil", "\n", "}" ]
// MaskTrustedKeySystemPrefix masks the system prefix trusted key identified by fingerprint.
[ "MaskTrustedKeySystemPrefix", "masks", "the", "system", "prefix", "trusted", "key", "identified", "by", "fingerprint", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L120-L133
167,191
rkt/rkt
pkg/keystore/keystore.go
DeleteTrustedKeyRoot
func (ks *Keystore) DeleteTrustedKeyRoot(fingerprint string) error { return os.Remove(path.Join(ks.LocalRootPath, fingerprint)) }
go
func (ks *Keystore) DeleteTrustedKeyRoot(fingerprint string) error { return os.Remove(path.Join(ks.LocalRootPath, fingerprint)) }
[ "func", "(", "ks", "*", "Keystore", ")", "DeleteTrustedKeyRoot", "(", "fingerprint", "string", ")", "error", "{", "return", "os", ".", "Remove", "(", "path", ".", "Join", "(", "ks", ".", "LocalRootPath", ",", "fingerprint", ")", ")", "\n", "}" ]
// DeleteTrustedKeyRoot deletes the root trusted key identified by fingerprint.
[ "DeleteTrustedKeyRoot", "deletes", "the", "root", "trusted", "key", "identified", "by", "fingerprint", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L136-L138
167,192
rkt/rkt
pkg/keystore/keystore.go
MaskTrustedKeySystemRoot
func (ks *Keystore) MaskTrustedKeySystemRoot(fingerprint string) (string, error) { dst := path.Join(ks.LocalRootPath, fingerprint) if err := ioutil.WriteFile(dst, []byte(""), 0644); err != nil { return "", err } if err := os.Chmod(dst, 0644); err != nil { return "", err } return dst, nil }
go
func (ks *Keystore) MaskTrustedKeySystemRoot(fingerprint string) (string, error) { dst := path.Join(ks.LocalRootPath, fingerprint) if err := ioutil.WriteFile(dst, []byte(""), 0644); err != nil { return "", err } if err := os.Chmod(dst, 0644); err != nil { return "", err } return dst, nil }
[ "func", "(", "ks", "*", "Keystore", ")", "MaskTrustedKeySystemRoot", "(", "fingerprint", "string", ")", "(", "string", ",", "error", ")", "{", "dst", ":=", "path", ".", "Join", "(", "ks", ".", "LocalRootPath", ",", "fingerprint", ")", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "dst", ",", "[", "]", "byte", "(", "\"", "\"", ")", ",", "0644", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "err", ":=", "os", ".", "Chmod", "(", "dst", ",", "0644", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "dst", ",", "nil", "\n", "}" ]
// MaskTrustedKeySystemRoot masks the system root trusted key identified by fingerprint.
[ "MaskTrustedKeySystemRoot", "masks", "the", "system", "root", "trusted", "key", "identified", "by", "fingerprint", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L141-L150
167,193
rkt/rkt
pkg/keystore/keystore.go
TrustedKeyPrefixExists
func (ks *Keystore) TrustedKeyPrefixExists(prefix string) (bool, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return false, err } pathNamesPrefix := []string{ // example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd path.Join(ks.LocalPrefixPath, acidentifier.String()), // example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd path.Join(ks.SystemPrefixPath, acidentifier.String()), } for _, p := range pathNamesPrefix { _, err := os.Stat(p) if os.IsNotExist(err) { continue } if err != nil { return false, errwrap.Wrap(fmt.Errorf("cannot check dir %q", p), err) } files, err := ioutil.ReadDir(p) if err != nil { return false, errwrap.Wrap(fmt.Errorf("cannot list files in dir %q", p), err) } for _, f := range files { if !f.IsDir() && f.Size() > 0 { return true, nil } } } parentPrefix, _ := path.Split(prefix) parentPrefix = strings.Trim(parentPrefix, "/") if parentPrefix != "" { return ks.TrustedKeyPrefixExists(parentPrefix) } return false, nil }
go
func (ks *Keystore) TrustedKeyPrefixExists(prefix string) (bool, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return false, err } pathNamesPrefix := []string{ // example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd path.Join(ks.LocalPrefixPath, acidentifier.String()), // example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd path.Join(ks.SystemPrefixPath, acidentifier.String()), } for _, p := range pathNamesPrefix { _, err := os.Stat(p) if os.IsNotExist(err) { continue } if err != nil { return false, errwrap.Wrap(fmt.Errorf("cannot check dir %q", p), err) } files, err := ioutil.ReadDir(p) if err != nil { return false, errwrap.Wrap(fmt.Errorf("cannot list files in dir %q", p), err) } for _, f := range files { if !f.IsDir() && f.Size() > 0 { return true, nil } } } parentPrefix, _ := path.Split(prefix) parentPrefix = strings.Trim(parentPrefix, "/") if parentPrefix != "" { return ks.TrustedKeyPrefixExists(parentPrefix) } return false, nil }
[ "func", "(", "ks", "*", "Keystore", ")", "TrustedKeyPrefixExists", "(", "prefix", "string", ")", "(", "bool", ",", "error", ")", "{", "acidentifier", ",", "err", ":=", "types", ".", "NewACIdentifier", "(", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "pathNamesPrefix", ":=", "[", "]", "string", "{", "// example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd", "path", ".", "Join", "(", "ks", ".", "LocalPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ")", ",", "// example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd", "path", ".", "Join", "(", "ks", ".", "SystemPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ")", ",", "}", "\n\n", "for", "_", ",", "p", ":=", "range", "pathNamesPrefix", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "p", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ")", ",", "err", ")", "\n", "}", "\n", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ")", ",", "err", ")", "\n", "}", "\n", "for", "_", ",", "f", ":=", "range", "files", "{", "if", "!", "f", ".", "IsDir", "(", ")", "&&", "f", ".", "Size", "(", ")", ">", "0", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "parentPrefix", ",", "_", ":=", "path", ".", "Split", "(", "prefix", ")", "\n", "parentPrefix", "=", "strings", ".", "Trim", "(", "parentPrefix", ",", "\"", "\"", ")", "\n\n", "if", "parentPrefix", "!=", "\"", "\"", "{", "return", "ks", ".", "TrustedKeyPrefixExists", "(", "parentPrefix", ")", "\n", "}", "\n\n", "return", "false", ",", "nil", "\n", "}" ]
// TrustKeyPrefixExists returns whether or not there exists 1 or more trusted // keys for a given prefix, or for any parent prefix.
[ "TrustKeyPrefixExists", "returns", "whether", "or", "not", "there", "exists", "1", "or", "more", "trusted", "keys", "for", "a", "given", "prefix", "or", "for", "any", "parent", "prefix", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L154-L194
167,194
rkt/rkt
pkg/keystore/keystore.go
TrustedKeyPrefixWithFingerprintExists
func (ks *Keystore) TrustedKeyPrefixWithFingerprintExists(prefix string, r io.ReadSeeker) (bool, error) { defer r.Seek(0, os.SEEK_SET) entityList, err := openpgp.ReadArmoredKeyRing(r) if err != nil { return false, err } if len(entityList) < 1 { return false, errors.New("missing opengpg entity") } pubKey := entityList[0].PrimaryKey fileName := fingerprintToFilename(pubKey.Fingerprint) pathNamesRoot := []string{ // example: /etc/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.LocalRootPath, fileName), // example: /usr/lib/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.SystemRootPath, fileName), } var pathNamesPrefix []string if prefix != "" { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return false, err } pathNamesPrefix = []string{ // example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.LocalPrefixPath, acidentifier.String(), fileName), // example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.SystemPrefixPath, acidentifier.String(), fileName), } } pathNames := append(pathNamesRoot, pathNamesPrefix...) for _, p := range pathNames { _, err := os.Stat(p) if err == nil { return true, nil } else if !os.IsNotExist(err) { return false, errwrap.Wrap(fmt.Errorf("cannot check file %q", p), err) } } return false, nil }
go
func (ks *Keystore) TrustedKeyPrefixWithFingerprintExists(prefix string, r io.ReadSeeker) (bool, error) { defer r.Seek(0, os.SEEK_SET) entityList, err := openpgp.ReadArmoredKeyRing(r) if err != nil { return false, err } if len(entityList) < 1 { return false, errors.New("missing opengpg entity") } pubKey := entityList[0].PrimaryKey fileName := fingerprintToFilename(pubKey.Fingerprint) pathNamesRoot := []string{ // example: /etc/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.LocalRootPath, fileName), // example: /usr/lib/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.SystemRootPath, fileName), } var pathNamesPrefix []string if prefix != "" { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return false, err } pathNamesPrefix = []string{ // example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.LocalPrefixPath, acidentifier.String(), fileName), // example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190 path.Join(ks.SystemPrefixPath, acidentifier.String(), fileName), } } pathNames := append(pathNamesRoot, pathNamesPrefix...) for _, p := range pathNames { _, err := os.Stat(p) if err == nil { return true, nil } else if !os.IsNotExist(err) { return false, errwrap.Wrap(fmt.Errorf("cannot check file %q", p), err) } } return false, nil }
[ "func", "(", "ks", "*", "Keystore", ")", "TrustedKeyPrefixWithFingerprintExists", "(", "prefix", "string", ",", "r", "io", ".", "ReadSeeker", ")", "(", "bool", ",", "error", ")", "{", "defer", "r", ".", "Seek", "(", "0", ",", "os", ".", "SEEK_SET", ")", "\n\n", "entityList", ",", "err", ":=", "openpgp", ".", "ReadArmoredKeyRing", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "len", "(", "entityList", ")", "<", "1", "{", "return", "false", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "pubKey", ":=", "entityList", "[", "0", "]", ".", "PrimaryKey", "\n", "fileName", ":=", "fingerprintToFilename", "(", "pubKey", ".", "Fingerprint", ")", "\n\n", "pathNamesRoot", ":=", "[", "]", "string", "{", "// example: /etc/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190", "path", ".", "Join", "(", "ks", ".", "LocalRootPath", ",", "fileName", ")", ",", "// example: /usr/lib/rkt/trustedkeys/root.d/8b86de38890ddb7291867b025210bd8888182190", "path", ".", "Join", "(", "ks", ".", "SystemRootPath", ",", "fileName", ")", ",", "}", "\n\n", "var", "pathNamesPrefix", "[", "]", "string", "\n", "if", "prefix", "!=", "\"", "\"", "{", "acidentifier", ",", "err", ":=", "types", ".", "NewACIdentifier", "(", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "pathNamesPrefix", "=", "[", "]", "string", "{", "// example: /etc/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190", "path", ".", "Join", "(", "ks", ".", "LocalPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ",", "fileName", ")", ",", "// example: /usr/lib/rkt/trustedkeys/prefix.d/coreos.com/etcd/8b86de38890ddb7291867b025210bd8888182190", "path", ".", "Join", "(", "ks", ".", "SystemPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ",", "fileName", ")", ",", "}", "\n", "}", "\n\n", "pathNames", ":=", "append", "(", "pathNamesRoot", ",", "pathNamesPrefix", "...", ")", "\n", "for", "_", ",", "p", ":=", "range", "pathNames", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "p", ")", "\n", "if", "err", "==", "nil", "{", "return", "true", ",", "nil", "\n", "}", "else", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "false", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "false", ",", "nil", "\n", "}" ]
// TrustedKeyPrefixWithFingerprintExists returns whether or not a trusted key with the fingerprint of the key accessible through r exists for the given prefix.
[ "TrustedKeyPrefixWithFingerprintExists", "returns", "whether", "or", "not", "a", "trusted", "key", "with", "the", "fingerprint", "of", "the", "key", "accessible", "through", "r", "exists", "for", "the", "given", "prefix", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L197-L242
167,195
rkt/rkt
pkg/keystore/keystore.go
StoreTrustedKeyPrefix
func (ks *Keystore) StoreTrustedKeyPrefix(prefix string, r io.Reader) (string, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return "", err } return storeTrustedKey(path.Join(ks.LocalPrefixPath, acidentifier.String()), r) }
go
func (ks *Keystore) StoreTrustedKeyPrefix(prefix string, r io.Reader) (string, error) { acidentifier, err := types.NewACIdentifier(prefix) if err != nil { return "", err } return storeTrustedKey(path.Join(ks.LocalPrefixPath, acidentifier.String()), r) }
[ "func", "(", "ks", "*", "Keystore", ")", "StoreTrustedKeyPrefix", "(", "prefix", "string", ",", "r", "io", ".", "Reader", ")", "(", "string", ",", "error", ")", "{", "acidentifier", ",", "err", ":=", "types", ".", "NewACIdentifier", "(", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "storeTrustedKey", "(", "path", ".", "Join", "(", "ks", ".", "LocalPrefixPath", ",", "acidentifier", ".", "String", "(", ")", ")", ",", "r", ")", "\n", "}" ]
// StoreTrustedKeyPrefix stores the contents of public key r as a prefix trusted key.
[ "StoreTrustedKeyPrefix", "stores", "the", "contents", "of", "public", "key", "r", "as", "a", "prefix", "trusted", "key", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L245-L251
167,196
rkt/rkt
pkg/keystore/keystore.go
StoreTrustedKeyRoot
func (ks *Keystore) StoreTrustedKeyRoot(r io.Reader) (string, error) { return storeTrustedKey(ks.LocalRootPath, r) }
go
func (ks *Keystore) StoreTrustedKeyRoot(r io.Reader) (string, error) { return storeTrustedKey(ks.LocalRootPath, r) }
[ "func", "(", "ks", "*", "Keystore", ")", "StoreTrustedKeyRoot", "(", "r", "io", ".", "Reader", ")", "(", "string", ",", "error", ")", "{", "return", "storeTrustedKey", "(", "ks", ".", "LocalRootPath", ",", "r", ")", "\n", "}" ]
// StoreTrustedKeyRoot stores the contents of public key r as a root trusted key.
[ "StoreTrustedKeyRoot", "stores", "the", "contents", "of", "public", "key", "r", "as", "a", "root", "trusted", "key", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/keystore/keystore.go#L254-L256
167,197
rkt/rkt
pkg/set/string.go
ConditionalHas
func (s String) ConditionalHas(conditionFunc func(source, item string) bool, item string) bool { for source := range s { if conditionFunc(source, item) { return true } } return false }
go
func (s String) ConditionalHas(conditionFunc func(source, item string) bool, item string) bool { for source := range s { if conditionFunc(source, item) { return true } } return false }
[ "func", "(", "s", "String", ")", "ConditionalHas", "(", "conditionFunc", "func", "(", "source", ",", "item", "string", ")", "bool", ",", "item", "string", ")", "bool", "{", "for", "source", ":=", "range", "s", "{", "if", "conditionFunc", "(", "source", ",", "item", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ConditionalHas returns true if and only if there is any item 'source' // in the set that satisfies the conditionFunc wrt 'item'.
[ "ConditionalHas", "returns", "true", "if", "and", "only", "if", "there", "is", "any", "item", "source", "in", "the", "set", "that", "satisfies", "the", "conditionFunc", "wrt", "item", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/set/string.go#L60-L67
167,198
rkt/rkt
stage1/init/common/path.go
RelEnvFilePath
func RelEnvFilePath(appName types.ACName) string { return filepath.Join(envDir, appName.String()) }
go
func RelEnvFilePath(appName types.ACName) string { return filepath.Join(envDir, appName.String()) }
[ "func", "RelEnvFilePath", "(", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "envDir", ",", "appName", ".", "String", "(", ")", ")", "\n", "}" ]
// RelEnvFilePath returns the path to the environment file for the given // app name relative to the pod's root.
[ "RelEnvFilePath", "returns", "the", "path", "to", "the", "environment", "file", "for", "the", "given", "app", "name", "relative", "to", "the", "pod", "s", "root", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L56-L58
167,199
rkt/rkt
stage1/init/common/path.go
EnvFilePath
func EnvFilePath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), RelEnvFilePath(appName)) }
go
func EnvFilePath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), RelEnvFilePath(appName)) }
[ "func", "EnvFilePath", "(", "root", "string", ",", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "RelEnvFilePath", "(", "appName", ")", ")", "\n", "}" ]
// EnvFilePath returns the path to the environment file for the given app name.
[ "EnvFilePath", "returns", "the", "path", "to", "the", "environment", "file", "for", "the", "given", "app", "name", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L61-L63