repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
coreos/go-systemd | sdjournal/journal.go | GetUsage | func (j *Journal) GetUsage() (uint64, error) {
var out C.uint64_t
sd_journal_get_usage, err := getFunction("sd_journal_get_usage")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_get_usage(sd_journal_get_usage, j.cjournal, &out)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to ge... | go | func (j *Journal) GetUsage() (uint64, error) {
var out C.uint64_t
sd_journal_get_usage, err := getFunction("sd_journal_get_usage")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_get_usage(sd_journal_get_usage, j.cjournal, &out)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to ge... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"GetUsage",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"out",
"C",
".",
"uint64_t",
"\n\n",
"sd_journal_get_usage",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
... | // GetUsage returns the journal disk space usage, in bytes. | [
"GetUsage",
"returns",
"the",
"journal",
"disk",
"space",
"usage",
"in",
"bytes",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L1021-L1038 | train |
coreos/go-systemd | sdjournal/journal.go | GetUniqueValues | func (j *Journal) GetUniqueValues(field string) ([]string, error) {
var result []string
sd_journal_query_unique, err := getFunction("sd_journal_query_unique")
if err != nil {
return nil, err
}
sd_journal_enumerate_unique, err := getFunction("sd_journal_enumerate_unique")
if err != nil {
return nil, err
}
... | go | func (j *Journal) GetUniqueValues(field string) ([]string, error) {
var result []string
sd_journal_query_unique, err := getFunction("sd_journal_query_unique")
if err != nil {
return nil, err
}
sd_journal_enumerate_unique, err := getFunction("sd_journal_enumerate_unique")
if err != nil {
return nil, err
}
... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"GetUniqueValues",
"(",
"field",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"string",
"\n\n",
"sd_journal_query_unique",
",",
"err",
":=",
"getFunction",
"(",
"\"",
... | // GetUniqueValues returns all unique values for a given field. | [
"GetUniqueValues",
"returns",
"all",
"unique",
"values",
"for",
"a",
"given",
"field",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L1041-L1095 | train |
coreos/go-systemd | activation/files.go | Files | func Files(unsetEnv bool) []*os.File {
if unsetEnv {
defer os.Unsetenv("LISTEN_PID")
defer os.Unsetenv("LISTEN_FDS")
defer os.Unsetenv("LISTEN_FDNAMES")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
}
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"... | go | func Files(unsetEnv bool) []*os.File {
if unsetEnv {
defer os.Unsetenv("LISTEN_PID")
defer os.Unsetenv("LISTEN_FDS")
defer os.Unsetenv("LISTEN_FDNAMES")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
}
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"... | [
"func",
"Files",
"(",
"unsetEnv",
"bool",
")",
"[",
"]",
"*",
"os",
".",
"File",
"{",
"if",
"unsetEnv",
"{",
"defer",
"os",
".",
"Unsetenv",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"os",
".",
"Unsetenv",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"os",
... | // Files returns a slice containing a `os.File` object for each
// file descriptor passed to this process via systemd fd-passing protocol.
//
// The order of the file descriptors is preserved in the returned slice.
// `unsetEnv` is typically set to `true` in order to avoid clashes in
// fd usage and to avoid leaking en... | [
"Files",
"returns",
"a",
"slice",
"containing",
"a",
"os",
".",
"File",
"object",
"for",
"each",
"file",
"descriptor",
"passed",
"to",
"this",
"process",
"via",
"systemd",
"fd",
"-",
"passing",
"protocol",
".",
"The",
"order",
"of",
"the",
"file",
"descrip... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/files.go#L36-L67 | train |
coreos/go-systemd | journal/journal.go | Enabled | func Enabled() bool {
onceConn.Do(initConn)
if (*net.UnixConn)(atomic.LoadPointer(&unixConnPtr)) == nil {
return false
}
if _, err := net.Dial("unixgram", journalSocket); err != nil {
return false
}
return true
} | go | func Enabled() bool {
onceConn.Do(initConn)
if (*net.UnixConn)(atomic.LoadPointer(&unixConnPtr)) == nil {
return false
}
if _, err := net.Dial("unixgram", journalSocket); err != nil {
return false
}
return true
} | [
"func",
"Enabled",
"(",
")",
"bool",
"{",
"onceConn",
".",
"Do",
"(",
"initConn",
")",
"\n\n",
"if",
"(",
"*",
"net",
".",
"UnixConn",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"unixConnPtr",
")",
")",
"==",
"nil",
"{",
"return",
"false",
"... | // Enabled checks whether the local systemd journal is available for logging. | [
"Enabled",
"checks",
"whether",
"the",
"local",
"systemd",
"journal",
"is",
"available",
"for",
"logging",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L73-L85 | train |
coreos/go-systemd | journal/journal.go | isSocketSpaceError | func isSocketSpaceError(err error) bool {
opErr, ok := err.(*net.OpError)
if !ok || opErr == nil {
return false
}
sysErr, ok := opErr.Err.(*os.SyscallError)
if !ok || sysErr == nil {
return false
}
return sysErr.Err == syscall.EMSGSIZE || sysErr.Err == syscall.ENOBUFS
} | go | func isSocketSpaceError(err error) bool {
opErr, ok := err.(*net.OpError)
if !ok || opErr == nil {
return false
}
sysErr, ok := opErr.Err.(*os.SyscallError)
if !ok || sysErr == nil {
return false
}
return sysErr.Err == syscall.EMSGSIZE || sysErr.Err == syscall.ENOBUFS
} | [
"func",
"isSocketSpaceError",
"(",
"err",
"error",
")",
"bool",
"{",
"opErr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"net",
".",
"OpError",
")",
"\n",
"if",
"!",
"ok",
"||",
"opErr",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"sysErr",... | // isSocketSpaceError checks whether the error is signaling
// an "overlarge message" condition. | [
"isSocketSpaceError",
"checks",
"whether",
"the",
"error",
"is",
"signaling",
"an",
"overlarge",
"message",
"condition",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L184-L196 | train |
coreos/go-systemd | journal/journal.go | initConn | func initConn() {
autobind, err := net.ResolveUnixAddr("unixgram", "")
if err != nil {
return
}
sock, err := net.ListenUnixgram("unixgram", autobind)
if err != nil {
return
}
atomic.StorePointer(&unixConnPtr, unsafe.Pointer(sock))
} | go | func initConn() {
autobind, err := net.ResolveUnixAddr("unixgram", "")
if err != nil {
return
}
sock, err := net.ListenUnixgram("unixgram", autobind)
if err != nil {
return
}
atomic.StorePointer(&unixConnPtr, unsafe.Pointer(sock))
} | [
"func",
"initConn",
"(",
")",
"{",
"autobind",
",",
"err",
":=",
"net",
".",
"ResolveUnixAddr",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"sock",
",",
"err",
":=",
"net",
".",
"Listen... | // initConn initializes the global `unixConnPtr` socket.
// It is meant to be called exactly once, at program startup. | [
"initConn",
"initializes",
"the",
"global",
"unixConnPtr",
"socket",
".",
"It",
"is",
"meant",
"to",
"be",
"called",
"exactly",
"once",
"at",
"program",
"startup",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L213-L225 | train |
coreos/go-systemd | machine1/dbus.go | GetMachine | func (c *Conn) GetMachine(name string) (dbus.ObjectPath, error) {
return c.getPath("GetMachine", name)
} | go | func (c *Conn) GetMachine(name string) (dbus.ObjectPath, error) {
return c.getPath("GetMachine", name)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetMachine",
"(",
"name",
"string",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPath",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // GetMachine gets a specific container with systemd-machined | [
"GetMachine",
"gets",
"a",
"specific",
"container",
"with",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L114-L116 | train |
coreos/go-systemd | machine1/dbus.go | GetMachineByPID | func (c *Conn) GetMachineByPID(pid uint) (dbus.ObjectPath, error) {
return c.getPath("GetMachineByPID", pid)
} | go | func (c *Conn) GetMachineByPID(pid uint) (dbus.ObjectPath, error) {
return c.getPath("GetMachineByPID", pid)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetMachineByPID",
"(",
"pid",
"uint",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPath",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"}"
] | // GetMachineByPID gets a machine specified by a PID from systemd-machined | [
"GetMachineByPID",
"gets",
"a",
"machine",
"specified",
"by",
"a",
"PID",
"from",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L124-L126 | train |
coreos/go-systemd | machine1/dbus.go | DescribeMachine | func (c *Conn) DescribeMachine(name string) (machineProps map[string]interface{}, err error) {
var dbusProps map[string]dbus.Variant
path, pathErr := c.GetMachine(name)
if pathErr != nil {
return nil, pathErr
}
obj := c.conn.Object("org.freedesktop.machine1", path)
err = obj.Call("org.freedesktop.DBus.Propertie... | go | func (c *Conn) DescribeMachine(name string) (machineProps map[string]interface{}, err error) {
var dbusProps map[string]dbus.Variant
path, pathErr := c.GetMachine(name)
if pathErr != nil {
return nil, pathErr
}
obj := c.conn.Object("org.freedesktop.machine1", path)
err = obj.Call("org.freedesktop.DBus.Propertie... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"DescribeMachine",
"(",
"name",
"string",
")",
"(",
"machineProps",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"var",
"dbusProps",
"map",
"[",
"string",
"]",
"dbus",
".",
"Vari... | // DescribeMachine gets the properties of a machine | [
"DescribeMachine",
"gets",
"the",
"properties",
"of",
"a",
"machine"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L134-L150 | train |
coreos/go-systemd | machine1/dbus.go | KillMachine | func (c *Conn) KillMachine(name, who string, sig syscall.Signal) error {
return c.object.Call(dbusInterface+".KillMachine", 0, name, who, sig).Err
} | go | func (c *Conn) KillMachine(name, who string, sig syscall.Signal) error {
return c.object.Call(dbusInterface+".KillMachine", 0, name, who, sig).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"KillMachine",
"(",
"name",
",",
"who",
"string",
",",
"sig",
"syscall",
".",
"Signal",
")",
"error",
"{",
"return",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"name",
... | // KillMachine sends a signal to a machine | [
"KillMachine",
"sends",
"a",
"signal",
"to",
"a",
"machine"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L153-L155 | train |
coreos/go-systemd | machine1/dbus.go | TerminateMachine | func (c *Conn) TerminateMachine(name string) error {
return c.object.Call(dbusInterface+".TerminateMachine", 0, name).Err
} | go | func (c *Conn) TerminateMachine(name string) error {
return c.object.Call(dbusInterface+".TerminateMachine", 0, name).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateMachine",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"name",
")",
".",
"Err",
"\n",
"}"
] | // TerminateMachine causes systemd-machined to terminate a machine, killing its processes | [
"TerminateMachine",
"causes",
"systemd",
"-",
"machined",
"to",
"terminate",
"a",
"machine",
"killing",
"its",
"processes"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L158-L160 | train |
coreos/go-systemd | machine1/dbus.go | RegisterMachine | func (c *Conn) RegisterMachine(name string, id []byte, service string, class string, pid int, root_directory string) error {
return c.object.Call(dbusInterface+".RegisterMachine", 0, name, id, service, class, uint32(pid), root_directory).Err
} | go | func (c *Conn) RegisterMachine(name string, id []byte, service string, class string, pid int, root_directory string) error {
return c.object.Call(dbusInterface+".RegisterMachine", 0, name, id, service, class, uint32(pid), root_directory).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RegisterMachine",
"(",
"name",
"string",
",",
"id",
"[",
"]",
"byte",
",",
"service",
"string",
",",
"class",
"string",
",",
"pid",
"int",
",",
"root_directory",
"string",
")",
"error",
"{",
"return",
"c",
".",
"o... | // RegisterMachine registers the container with the systemd-machined | [
"RegisterMachine",
"registers",
"the",
"container",
"with",
"the",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L163-L165 | train |
coreos/go-systemd | machine1/dbus.go | ListMachines | func (c *Conn) ListMachines() ([]MachineStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListMachines", 0).Store(&result); err != nil {
return nil, err
}
machs := []MachineStatus{}
for _, i := range result {
machine, err := machineFromInterfaces(i)
if err != nil {
... | go | func (c *Conn) ListMachines() ([]MachineStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListMachines", 0).Store(&result); err != nil {
return nil, err
}
machs := []MachineStatus{}
for _, i := range result {
machine, err := machineFromInterfaces(i)
if err != nil {
... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListMachines",
"(",
")",
"(",
"[",
"]",
"MachineStatus",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"o... | // ListMachines returns an array of all currently running machines. | [
"ListMachines",
"returns",
"an",
"array",
"of",
"all",
"currently",
"running",
"machines",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L193-L209 | train |
coreos/go-systemd | machine1/dbus.go | ListImages | func (c *Conn) ListImages() ([]ImageStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListImages", 0).Store(&result); err != nil {
return nil, err
}
images := []ImageStatus{}
for _, i := range result {
image, err := imageFromInterfaces(i)
if err != nil {
return n... | go | func (c *Conn) ListImages() ([]ImageStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListImages", 0).Store(&result); err != nil {
return nil, err
}
images := []ImageStatus{}
for _, i := range result {
image, err := imageFromInterfaces(i)
if err != nil {
return n... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListImages",
"(",
")",
"(",
"[",
"]",
"ImageStatus",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"objec... | // ListImages returns an array of all currently available images. | [
"ListImages",
"returns",
"an",
"array",
"of",
"all",
"currently",
"available",
"images",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L249-L265 | train |
coreos/go-systemd | unit/deserialize.go | Deserialize | func Deserialize(f io.Reader) (opts []*UnitOption, err error) {
lexer, optchan, errchan := newLexer(f)
go lexer.lex()
for opt := range optchan {
opts = append(opts, &(*opt))
}
err = <-errchan
return opts, err
} | go | func Deserialize(f io.Reader) (opts []*UnitOption, err error) {
lexer, optchan, errchan := newLexer(f)
go lexer.lex()
for opt := range optchan {
opts = append(opts, &(*opt))
}
err = <-errchan
return opts, err
} | [
"func",
"Deserialize",
"(",
"f",
"io",
".",
"Reader",
")",
"(",
"opts",
"[",
"]",
"*",
"UnitOption",
",",
"err",
"error",
")",
"{",
"lexer",
",",
"optchan",
",",
"errchan",
":=",
"newLexer",
"(",
"f",
")",
"\n",
"go",
"lexer",
".",
"lex",
"(",
")... | // Deserialize parses a systemd unit file into a list of UnitOption objects. | [
"Deserialize",
"parses",
"a",
"systemd",
"unit",
"file",
"into",
"a",
"list",
"of",
"UnitOption",
"objects",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/deserialize.go#L47-L57 | train |
coreos/go-systemd | login1/dbus.go | Close | func (c *Conn) Close() {
if c == nil {
return
}
if c.conn != nil {
c.conn.Close()
}
} | go | func (c *Conn) Close() {
if c == nil {
return
}
if c.conn != nil {
c.conn.Close()
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"conn",
"!=",
"nil",
"{",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close closes the dbus connection | [
"Close",
"closes",
"the",
"dbus",
"connection"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L49-L57 | train |
coreos/go-systemd | login1/dbus.go | GetSession | func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
var out interface{}
if err := c.object.Call(dbusInterface+".GetSession", 0, id).Store(&out); err != nil {
return "", err
}
ret, ok := out.(dbus.ObjectPath)
if !ok {
return "", fmt.Errorf("failed to typecast session to ObjectPath")
}
return ret... | go | func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
var out interface{}
if err := c.object.Call(dbusInterface+".GetSession", 0, id).Store(&out); err != nil {
return "", err
}
ret, ok := out.(dbus.ObjectPath)
if !ok {
return "", fmt.Errorf("failed to typecast session to ObjectPath")
}
return ret... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetSession",
"(",
"id",
"string",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"var",
"out",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",... | // GetSession may be used to get the session object path for the session with the specified ID. | [
"GetSession",
"may",
"be",
"used",
"to",
"get",
"the",
"session",
"object",
"path",
"for",
"the",
"session",
"with",
"the",
"specified",
"ID",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L159-L171 | train |
coreos/go-systemd | login1/dbus.go | ListSessions | func (c *Conn) ListSessions() ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}
ret := []Session{}
for _, el := range out {
session, err := sessionFromInterfaces(el)
if err != nil {
return nil, err
}
ret... | go | func (c *Conn) ListSessions() ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}
ret := []Session{}
for _, el := range out {
session, err := sessionFromInterfaces(el)
if err != nil {
return nil, err
}
ret... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListSessions",
"(",
")",
"(",
"[",
"]",
"Session",
",",
"error",
")",
"{",
"out",
":=",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
... | // ListSessions returns an array with all current sessions. | [
"ListSessions",
"returns",
"an",
"array",
"with",
"all",
"current",
"sessions",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L174-L189 | train |
coreos/go-systemd | login1/dbus.go | ListUsers | func (c *Conn) ListUsers() ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}
ret := []User{}
for _, el := range out {
user, err := userFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *us... | go | func (c *Conn) ListUsers() ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}
ret := []User{}
for _, el := range out {
user, err := userFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *us... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUsers",
"(",
")",
"(",
"[",
"]",
"User",
",",
"error",
")",
"{",
"out",
":=",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
"dbus... | // ListUsers returns an array with all currently logged in users. | [
"ListUsers",
"returns",
"an",
"array",
"with",
"all",
"currently",
"logged",
"in",
"users",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L192-L207 | train |
coreos/go-systemd | login1/dbus.go | LockSession | func (c *Conn) LockSession(id string) {
c.object.Call(dbusInterface+".LockSession", 0, id)
} | go | func (c *Conn) LockSession(id string) {
c.object.Call(dbusInterface+".LockSession", 0, id)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"LockSession",
"(",
"id",
"string",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"id",
")",
"\n",
"}"
] | // LockSession asks the session with the specified ID to activate the screen lock. | [
"LockSession",
"asks",
"the",
"session",
"with",
"the",
"specified",
"ID",
"to",
"activate",
"the",
"screen",
"lock",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L210-L212 | train |
coreos/go-systemd | login1/dbus.go | TerminateSession | func (c *Conn) TerminateSession(id string) {
c.object.Call(dbusInterface+".TerminateSession", 0, id)
} | go | func (c *Conn) TerminateSession(id string) {
c.object.Call(dbusInterface+".TerminateSession", 0, id)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateSession",
"(",
"id",
"string",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"id",
")",
"\n",
"}"
] | // TerminateSession forcibly terminate one specific session. | [
"TerminateSession",
"forcibly",
"terminate",
"one",
"specific",
"session",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L220-L222 | train |
coreos/go-systemd | login1/dbus.go | TerminateUser | func (c *Conn) TerminateUser(uid uint32) {
c.object.Call(dbusInterface+".TerminateUser", 0, uid)
} | go | func (c *Conn) TerminateUser(uid uint32) {
c.object.Call(dbusInterface+".TerminateUser", 0, uid)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateUser",
"(",
"uid",
"uint32",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"uid",
")",
"\n",
"}"
] | // TerminateUser forcibly terminates all processes of a user. | [
"TerminateUser",
"forcibly",
"terminates",
"all",
"processes",
"of",
"a",
"user",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L225-L227 | train |
coreos/go-systemd | login1/dbus.go | Reboot | func (c *Conn) Reboot(askForAuth bool) {
c.object.Call(dbusInterface+".Reboot", 0, askForAuth)
} | go | func (c *Conn) Reboot(askForAuth bool) {
c.object.Call(dbusInterface+".Reboot", 0, askForAuth)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Reboot",
"(",
"askForAuth",
"bool",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"askForAuth",
")",
"\n",
"}"
] | // Reboot asks logind for a reboot optionally asking for auth. | [
"Reboot",
"asks",
"logind",
"for",
"a",
"reboot",
"optionally",
"asking",
"for",
"auth",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L230-L232 | train |
coreos/go-systemd | login1/dbus.go | Inhibit | func (c *Conn) Inhibit(what, who, why, mode string) (*os.File, error) {
var fd dbus.UnixFD
err := c.object.Call(dbusInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(fd), "inhibit"), nil
} | go | func (c *Conn) Inhibit(what, who, why, mode string) (*os.File, error) {
var fd dbus.UnixFD
err := c.object.Call(dbusInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(fd), "inhibit"), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Inhibit",
"(",
"what",
",",
"who",
",",
"why",
",",
"mode",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"var",
"fd",
"dbus",
".",
"UnixFD",
"\n\n",
"err",
":=",
"c",
".",
"object",
... | // Inhibit takes inhibition lock in logind. | [
"Inhibit",
"takes",
"inhibition",
"lock",
"in",
"logind",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L235-L244 | train |
coreos/go-systemd | login1/dbus.go | Subscribe | func (c *Conn) Subscribe(members ...string) chan *dbus.Signal {
for _, member := range members {
c.conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
fmt.Sprintf("type='signal',interface='org.freedesktop.login1.Manager',member='%s'", member))
}
ch := make(chan *dbus.Signal, 10)
c.conn.Signal(ch)
return... | go | func (c *Conn) Subscribe(members ...string) chan *dbus.Signal {
for _, member := range members {
c.conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
fmt.Sprintf("type='signal',interface='org.freedesktop.login1.Manager',member='%s'", member))
}
ch := make(chan *dbus.Signal, 10)
c.conn.Signal(ch)
return... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Subscribe",
"(",
"members",
"...",
"string",
")",
"chan",
"*",
"dbus",
".",
"Signal",
"{",
"for",
"_",
",",
"member",
":=",
"range",
"members",
"{",
"c",
".",
"conn",
".",
"BusObject",
"(",
")",
".",
"Call",
"... | // Subscribe to signals on the logind dbus | [
"Subscribe",
"to",
"signals",
"on",
"the",
"logind",
"dbus"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L247-L255 | train |
coreos/go-systemd | login1/dbus.go | PowerOff | func (c *Conn) PowerOff(askForAuth bool) {
c.object.Call(dbusInterface+".PowerOff", 0, askForAuth)
} | go | func (c *Conn) PowerOff(askForAuth bool) {
c.object.Call(dbusInterface+".PowerOff", 0, askForAuth)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"PowerOff",
"(",
"askForAuth",
"bool",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"askForAuth",
")",
"\n",
"}"
] | // PowerOff asks logind for a power off optionally asking for auth. | [
"PowerOff",
"asks",
"logind",
"for",
"a",
"power",
"off",
"optionally",
"asking",
"for",
"auth",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L258-L260 | train |
coreos/go-systemd | activation/listeners.go | ListenersWithNames | func ListenersWithNames() (map[string][]net.Listener, error) {
files := Files(true)
listeners := map[string][]net.Listener{}
for _, f := range files {
if pc, err := net.FileListener(f); err == nil {
current, ok := listeners[f.Name()]
if !ok {
listeners[f.Name()] = []net.Listener{pc}
} else {
list... | go | func ListenersWithNames() (map[string][]net.Listener, error) {
files := Files(true)
listeners := map[string][]net.Listener{}
for _, f := range files {
if pc, err := net.FileListener(f); err == nil {
current, ok := listeners[f.Name()]
if !ok {
listeners[f.Name()] = []net.Listener{pc}
} else {
list... | [
"func",
"ListenersWithNames",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"files",
":=",
"Files",
"(",
"true",
")",
"\n",
"listeners",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
... | // ListenersWithNames maps a listener name to a set of net.Listener instances. | [
"ListenersWithNames",
"maps",
"a",
"listener",
"name",
"to",
"a",
"set",
"of",
"net",
".",
"Listener",
"instances",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L42-L58 | train |
coreos/go-systemd | activation/listeners.go | TLSListeners | func TLSListeners(tlsConfig *tls.Config) ([]net.Listener, error) {
listeners, err := Listeners()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for i, l := range listeners {
// Activate TLS only for TCP sockets
if l.Addr().Network() == "tcp" {
listeners[i] ... | go | func TLSListeners(tlsConfig *tls.Config) ([]net.Listener, error) {
listeners, err := Listeners()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for i, l := range listeners {
// Activate TLS only for TCP sockets
if l.Addr().Network() == "tcp" {
listeners[i] ... | [
"func",
"TLSListeners",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"listeners",
",",
"err",
":=",
"Listeners",
"(",
")",
"\n\n",
"if",
"listeners",
"==",
"nil",
"||",
"err",
"!=",
... | // TLSListeners returns a slice containing a net.listener for each matching TCP socket type
// passed to this process.
// It uses default Listeners func and forces TCP sockets handlers to use TLS based on tlsConfig. | [
"TLSListeners",
"returns",
"a",
"slice",
"containing",
"a",
"net",
".",
"listener",
"for",
"each",
"matching",
"TCP",
"socket",
"type",
"passed",
"to",
"this",
"process",
".",
"It",
"uses",
"default",
"Listeners",
"func",
"and",
"forces",
"TCP",
"sockets",
"... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L63-L80 | train |
coreos/go-systemd | activation/listeners.go | TLSListenersWithNames | func TLSListenersWithNames(tlsConfig *tls.Config) (map[string][]net.Listener, error) {
listeners, err := ListenersWithNames()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for _, ll := range listeners {
// Activate TLS only for TCP sockets
for i, l := range ll... | go | func TLSListenersWithNames(tlsConfig *tls.Config) (map[string][]net.Listener, error) {
listeners, err := ListenersWithNames()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for _, ll := range listeners {
// Activate TLS only for TCP sockets
for i, l := range ll... | [
"func",
"TLSListenersWithNames",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"listeners",
",",
"err",
":=",
"ListenersWithNames",
"(",
")",
"\n\n",
"if",
"l... | // TLSListenersWithNames maps a listener name to a net.Listener with
// the associated TLS configuration. | [
"TLSListenersWithNames",
"maps",
"a",
"listener",
"name",
"to",
"a",
"net",
".",
"Listener",
"with",
"the",
"associated",
"TLS",
"configuration",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L84-L103 | train |
pkg/sftp | request-example.go | InMemHandler | func InMemHandler() Handlers {
root := &root{
files: make(map[string]*memFile),
}
root.memFile = newMemFile("/", true)
return Handlers{root, root, root, root}
} | go | func InMemHandler() Handlers {
root := &root{
files: make(map[string]*memFile),
}
root.memFile = newMemFile("/", true)
return Handlers{root, root, root, root}
} | [
"func",
"InMemHandler",
"(",
")",
"Handlers",
"{",
"root",
":=",
"&",
"root",
"{",
"files",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"memFile",
")",
",",
"}",
"\n",
"root",
".",
"memFile",
"=",
"newMemFile",
"(",
"\"",
"\"",
",",
"true",
... | // InMemHandler returns a Hanlders object with the test handlers. | [
"InMemHandler",
"returns",
"a",
"Hanlders",
"object",
"with",
"the",
"test",
"handlers",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-example.go#L20-L26 | train |
pkg/sftp | request-example.go | newMemFile | func newMemFile(name string, isdir bool) *memFile {
return &memFile{
name: name,
modtime: time.Now(),
isdir: isdir,
}
} | go | func newMemFile(name string, isdir bool) *memFile {
return &memFile{
name: name,
modtime: time.Now(),
isdir: isdir,
}
} | [
"func",
"newMemFile",
"(",
"name",
"string",
",",
"isdir",
"bool",
")",
"*",
"memFile",
"{",
"return",
"&",
"memFile",
"{",
"name",
":",
"name",
",",
"modtime",
":",
"time",
".",
"Now",
"(",
")",
",",
"isdir",
":",
"isdir",
",",
"}",
"\n",
"}"
] | // factory to make sure modtime is set | [
"factory",
"to",
"make",
"sure",
"modtime",
"is",
"set"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-example.go#L212-L218 | train |
pkg/sftp | request.go | requestFromPacket | func requestFromPacket(ctx context.Context, pkt hasPath) *Request {
method := requestMethod(pkt)
request := NewRequest(method, pkt.getPath())
request.ctx, request.cancelCtx = context.WithCancel(ctx)
switch p := pkt.(type) {
case *sshFxpOpenPacket:
request.Flags = p.Pflags
case *sshFxpSetstatPacket:
request.F... | go | func requestFromPacket(ctx context.Context, pkt hasPath) *Request {
method := requestMethod(pkt)
request := NewRequest(method, pkt.getPath())
request.ctx, request.cancelCtx = context.WithCancel(ctx)
switch p := pkt.(type) {
case *sshFxpOpenPacket:
request.Flags = p.Pflags
case *sshFxpSetstatPacket:
request.F... | [
"func",
"requestFromPacket",
"(",
"ctx",
"context",
".",
"Context",
",",
"pkt",
"hasPath",
")",
"*",
"Request",
"{",
"method",
":=",
"requestMethod",
"(",
"pkt",
")",
"\n",
"request",
":=",
"NewRequest",
"(",
"method",
",",
"pkt",
".",
"getPath",
"(",
")... | // New Request initialized based on packet data | [
"New",
"Request",
"initialized",
"based",
"on",
"packet",
"data"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L44-L61 | train |
pkg/sftp | request.go | NewRequest | func NewRequest(method, path string) *Request {
return &Request{Method: method, Filepath: cleanPath(path),
state: state{RWMutex: new(sync.RWMutex)}}
} | go | func NewRequest(method, path string) *Request {
return &Request{Method: method, Filepath: cleanPath(path),
state: state{RWMutex: new(sync.RWMutex)}}
} | [
"func",
"NewRequest",
"(",
"method",
",",
"path",
"string",
")",
"*",
"Request",
"{",
"return",
"&",
"Request",
"{",
"Method",
":",
"method",
",",
"Filepath",
":",
"cleanPath",
"(",
"path",
")",
",",
"state",
":",
"state",
"{",
"RWMutex",
":",
"new",
... | // NewRequest creates a new Request object. | [
"NewRequest",
"creates",
"a",
"new",
"Request",
"object",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L64-L67 | train |
pkg/sftp | request.go | copy | func (r *Request) copy() *Request {
r.state.Lock()
defer r.state.Unlock()
r2 := new(Request)
*r2 = *r
return r2
} | go | func (r *Request) copy() *Request {
r.state.Lock()
defer r.state.Unlock()
r2 := new(Request)
*r2 = *r
return r2
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"copy",
"(",
")",
"*",
"Request",
"{",
"r",
".",
"state",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"Unlock",
"(",
")",
"\n",
"r2",
":=",
"new",
"(",
"Request",
")",
"\n",
"*",
"r2",
... | // shallow copy of existing request | [
"shallow",
"copy",
"of",
"existing",
"request"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L70-L76 | train |
pkg/sftp | request.go | Context | func (r *Request) Context() context.Context {
if r.ctx != nil {
return r.ctx
}
return context.Background()
} | go | func (r *Request) Context() context.Context {
if r.ctx != nil {
return r.ctx
}
return context.Background()
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Context",
"(",
")",
"context",
".",
"Context",
"{",
"if",
"r",
".",
"ctx",
"!=",
"nil",
"{",
"return",
"r",
".",
"ctx",
"\n",
"}",
"\n",
"return",
"context",
".",
"Background",
"(",
")",
"\n",
"}"
] | // Context returns the request's context. To change the context,
// use WithContext.
//
// The returned context is always non-nil; it defaults to the
// background context.
//
// For incoming server requests, the context is canceled when the
// request is complete or the client's connection closes. | [
"Context",
"returns",
"the",
"request",
"s",
"context",
".",
"To",
"change",
"the",
"context",
"use",
"WithContext",
".",
"The",
"returned",
"context",
"is",
"always",
"non",
"-",
"nil",
";",
"it",
"defaults",
"to",
"the",
"background",
"context",
".",
"Fo... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L86-L91 | train |
pkg/sftp | request.go | WithContext | func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r2 := r.copy()
r2.ctx = ctx
r2.cancelCtx = nil
return r2
} | go | func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r2 := r.copy()
r2.ctx = ctx
r2.cancelCtx = nil
return r2
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"Request",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"r2",
":=",
"r",
".",
"copy",
"(",
")",
"\n",
... | // WithContext returns a copy of r with its context changed to ctx.
// The provided ctx must be non-nil. | [
"WithContext",
"returns",
"a",
"copy",
"of",
"r",
"with",
"its",
"context",
"changed",
"to",
"ctx",
".",
"The",
"provided",
"ctx",
"must",
"be",
"non",
"-",
"nil",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L95-L103 | train |
pkg/sftp | request.go | lsNext | func (r *Request) lsNext() int64 {
r.state.RLock()
defer r.state.RUnlock()
return r.state.lsoffset
} | go | func (r *Request) lsNext() int64 {
r.state.RLock()
defer r.state.RUnlock()
return r.state.lsoffset
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"lsNext",
"(",
")",
"int64",
"{",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"r",
".",
"state",
".",
"lsoffset",
"\n",
"}"
] | // Returns current offset for file list | [
"Returns",
"current",
"offset",
"for",
"file",
"list"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L106-L110 | train |
pkg/sftp | request.go | lsInc | func (r *Request) lsInc(offset int64) {
r.state.Lock()
defer r.state.Unlock()
r.state.lsoffset = r.state.lsoffset + offset
} | go | func (r *Request) lsInc(offset int64) {
r.state.Lock()
defer r.state.Unlock()
r.state.lsoffset = r.state.lsoffset + offset
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"lsInc",
"(",
"offset",
"int64",
")",
"{",
"r",
".",
"state",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"state",
".",
"lsoffset",
"=",
"r",
".",
"s... | // Increases next offset | [
"Increases",
"next",
"offset"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L113-L117 | train |
pkg/sftp | request.go | open | func (r *Request) open(h Handlers, pkt requestPacket) responsePacket {
flags := r.Pflags()
var err error
switch {
case flags.Write, flags.Append, flags.Creat, flags.Trunc:
r.Method = "Put"
r.state.writerAt, err = h.FilePut.Filewrite(r)
case flags.Read:
r.Method = "Get"
r.state.readerAt, err = h.FileGet.Fil... | go | func (r *Request) open(h Handlers, pkt requestPacket) responsePacket {
flags := r.Pflags()
var err error
switch {
case flags.Write, flags.Append, flags.Creat, flags.Trunc:
r.Method = "Put"
r.state.writerAt, err = h.FilePut.Filewrite(r)
case flags.Read:
r.Method = "Get"
r.state.readerAt, err = h.FileGet.Fil... | [
"func",
"(",
"r",
"*",
"Request",
")",
"open",
"(",
"h",
"Handlers",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"flags",
":=",
"r",
".",
"Pflags",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"{",
"case",
"flags",
".",
"Write"... | // Additional initialization for Open packets | [
"Additional",
"initialization",
"for",
"Open",
"packets"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L174-L191 | train |
pkg/sftp | request.go | fileget | func fileget(h FileReader, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileget", r)
r.state.RLock()
reader := r.state.readerAt
r.state.RUnlock()
if reader == nil {
return statusFromError(pkt, errors.New("unexpected read packet"))
}
_, offset, length := packetData(pkt)
data := make([]byte, ... | go | func fileget(h FileReader, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileget", r)
r.state.RLock()
reader := r.state.readerAt
r.state.RUnlock()
if reader == nil {
return statusFromError(pkt, errors.New("unexpected read packet"))
}
_, offset, length := packetData(pkt)
data := make([]byte, ... | [
"func",
"fileget",
"(",
"h",
"FileReader",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"//fmt.Println(\"fileget\", r)",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"reader",
":=",
"r",
".",
"state",
".",
"readerA... | // wrap FileReader handler | [
"wrap",
"FileReader",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L207-L228 | train |
pkg/sftp | request.go | fileput | func fileput(h FileWriter, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileput", r)
r.state.RLock()
writer := r.state.writerAt
r.state.RUnlock()
if writer == nil {
return statusFromError(pkt, errors.New("unexpected write packet"))
}
data, offset, _ := packetData(pkt)
_, err := writer.Write... | go | func fileput(h FileWriter, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileput", r)
r.state.RLock()
writer := r.state.writerAt
r.state.RUnlock()
if writer == nil {
return statusFromError(pkt, errors.New("unexpected write packet"))
}
data, offset, _ := packetData(pkt)
_, err := writer.Write... | [
"func",
"fileput",
"(",
"h",
"FileWriter",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"//fmt.Println(\"fileput\", r)",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"writer",
":=",
"r",
".",
"state",
".",
"writerA... | // wrap FileWriter handler | [
"wrap",
"FileWriter",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L231-L243 | train |
pkg/sftp | request.go | filecmd | func filecmd(h FileCmder, r *Request, pkt requestPacket) responsePacket {
switch p := pkt.(type) {
case *sshFxpFsetstatPacket:
r.Flags = p.Flags
r.Attrs = p.Attrs.([]byte)
}
err := h.Filecmd(r)
return statusFromError(pkt, err)
} | go | func filecmd(h FileCmder, r *Request, pkt requestPacket) responsePacket {
switch p := pkt.(type) {
case *sshFxpFsetstatPacket:
r.Flags = p.Flags
r.Attrs = p.Attrs.([]byte)
}
err := h.Filecmd(r)
return statusFromError(pkt, err)
} | [
"func",
"filecmd",
"(",
"h",
"FileCmder",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"switch",
"p",
":=",
"pkt",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sshFxpFsetstatPacket",
":",
"r",
".",
"Flags",
"=",
"p",
... | // wrap FileCmder handler | [
"wrap",
"FileCmder",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L260-L269 | train |
pkg/sftp | request.go | filelist | func filelist(h FileLister, r *Request, pkt requestPacket) responsePacket {
var err error
lister := r.getLister()
if lister == nil {
return statusFromError(pkt, errors.New("unexpected dir packet"))
}
offset := r.lsNext()
finfo := make([]os.FileInfo, MaxFilelist)
n, err := lister.ListAt(finfo, offset)
r.lsInc... | go | func filelist(h FileLister, r *Request, pkt requestPacket) responsePacket {
var err error
lister := r.getLister()
if lister == nil {
return statusFromError(pkt, errors.New("unexpected dir packet"))
}
offset := r.lsNext()
finfo := make([]os.FileInfo, MaxFilelist)
n, err := lister.ListAt(finfo, offset)
r.lsInc... | [
"func",
"filelist",
"(",
"h",
"FileLister",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"var",
"err",
"error",
"\n",
"lister",
":=",
"r",
".",
"getLister",
"(",
")",
"\n",
"if",
"lister",
"==",
"nil",
"{",
"return... | // wrap FileLister handler | [
"wrap",
"FileLister",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L272-L309 | train |
pkg/sftp | request.go | requestMethod | func requestMethod(p requestPacket) (method string) {
switch p.(type) {
case *sshFxpReadPacket, *sshFxpWritePacket, *sshFxpOpenPacket:
// set in open() above
case *sshFxpOpendirPacket, *sshFxpReaddirPacket:
// set in opendir() above
case *sshFxpSetstatPacket, *sshFxpFsetstatPacket:
method = "Setstat"
case *s... | go | func requestMethod(p requestPacket) (method string) {
switch p.(type) {
case *sshFxpReadPacket, *sshFxpWritePacket, *sshFxpOpenPacket:
// set in open() above
case *sshFxpOpendirPacket, *sshFxpReaddirPacket:
// set in opendir() above
case *sshFxpSetstatPacket, *sshFxpFsetstatPacket:
method = "Setstat"
case *s... | [
"func",
"requestMethod",
"(",
"p",
"requestPacket",
")",
"(",
"method",
"string",
")",
"{",
"switch",
"p",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sshFxpReadPacket",
",",
"*",
"sshFxpWritePacket",
",",
"*",
"sshFxpOpenPacket",
":",
"// set in open() above",
... | // init attributes of request object from packet data | [
"init",
"attributes",
"of",
"request",
"object",
"from",
"packet",
"data"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L359-L383 | train |
pkg/sftp | client.go | MaxConcurrentRequestsPerFile | func MaxConcurrentRequestsPerFile(n int) ClientOption {
return func(c *Client) error {
if n < 1 {
return errors.Errorf("n must be greater or equal to 1")
}
c.maxConcurrentRequests = n
return nil
}
} | go | func MaxConcurrentRequestsPerFile(n int) ClientOption {
return func(c *Client) error {
if n < 1 {
return errors.Errorf("n must be greater or equal to 1")
}
c.maxConcurrentRequests = n
return nil
}
} | [
"func",
"MaxConcurrentRequestsPerFile",
"(",
"n",
"int",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"if",
"n",
"<",
"1",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
... | // MaxConcurrentRequestsPerFile sets the maximum concurrent requests allowed for a single file.
//
// The default maximum concurrent requests is 64. | [
"MaxConcurrentRequestsPerFile",
"sets",
"the",
"maximum",
"concurrent",
"requests",
"allowed",
"for",
"a",
"single",
"file",
".",
"The",
"default",
"maximum",
"concurrent",
"requests",
"is",
"64",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L82-L90 | train |
pkg/sftp | client.go | NewClient | func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) {
s, err := conn.NewSession()
if err != nil {
return nil, err
}
if err := s.RequestSubsystem("sftp"); err != nil {
return nil, err
}
pw, err := s.StdinPipe()
if err != nil {
return nil, err
}
pr, err := s.StdoutPipe()
if err != nil ... | go | func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) {
s, err := conn.NewSession()
if err != nil {
return nil, err
}
if err := s.RequestSubsystem("sftp"); err != nil {
return nil, err
}
pw, err := s.StdinPipe()
if err != nil {
return nil, err
}
pr, err := s.StdoutPipe()
if err != nil ... | [
"func",
"NewClient",
"(",
"conn",
"*",
"ssh",
".",
"Client",
",",
"opts",
"...",
"ClientOption",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"conn",
".",
"NewSession",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // NewClient creates a new SFTP client on conn, using zero or more option
// functions. | [
"NewClient",
"creates",
"a",
"new",
"SFTP",
"client",
"on",
"conn",
"using",
"zero",
"or",
"more",
"option",
"functions",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L94-L112 | train |
pkg/sftp | client.go | Walk | func (c *Client) Walk(root string) *fs.Walker {
return fs.WalkFS(root, c)
} | go | func (c *Client) Walk(root string) *fs.Walker {
return fs.WalkFS(root, c)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Walk",
"(",
"root",
"string",
")",
"*",
"fs",
".",
"Walker",
"{",
"return",
"fs",
".",
"WalkFS",
"(",
"root",
",",
"c",
")",
"\n",
"}"
] | // Walk returns a new Walker rooted at root. | [
"Walk",
"returns",
"a",
"new",
"Walker",
"rooted",
"at",
"root",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L199-L201 | train |
pkg/sftp | client.go | ReadDir | func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
handle, err := c.opendir(p)
if err != nil {
return nil, err
}
defer c.close(handle) // this has to defer earlier than the lock below
var attrs []os.FileInfo
var done = false
for !done {
id := c.nextID()
typ, data, err1 := c.sendPacket(sshFxpReaddi... | go | func (c *Client) ReadDir(p string) ([]os.FileInfo, error) {
handle, err := c.opendir(p)
if err != nil {
return nil, err
}
defer c.close(handle) // this has to defer earlier than the lock below
var attrs []os.FileInfo
var done = false
for !done {
id := c.nextID()
typ, data, err1 := c.sendPacket(sshFxpReaddi... | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReadDir",
"(",
"p",
"string",
")",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"handle",
",",
"err",
":=",
"c",
".",
"opendir",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // ReadDir reads the directory named by dirname and returns a list of
// directory entries. | [
"ReadDir",
"reads",
"the",
"directory",
"named",
"by",
"dirname",
"and",
"returns",
"a",
"list",
"of",
"directory",
"entries",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L205-L254 | train |
pkg/sftp | client.go | Stat | func (c *Client) Stat(p string) (os.FileInfo, error) {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpStatPacket{
ID: id,
Path: p,
})
if err != nil {
return nil, err
}
switch typ {
case ssh_FXP_ATTRS:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIDErr{id, sid}
... | go | func (c *Client) Stat(p string) (os.FileInfo, error) {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpStatPacket{
ID: id,
Path: p,
})
if err != nil {
return nil, err
}
switch typ {
case ssh_FXP_ATTRS:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIDErr{id, sid}
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Stat",
"(",
"p",
"string",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
".",
"sendPacket",
"(",
"ssh... | // Stat returns a FileInfo structure describing the file specified by path 'p'.
// If 'p' is a symbolic link, the returned FileInfo structure describes the referent file. | [
"Stat",
"returns",
"a",
"FileInfo",
"structure",
"describing",
"the",
"file",
"specified",
"by",
"path",
"p",
".",
"If",
"p",
"is",
"a",
"symbolic",
"link",
"the",
"returned",
"FileInfo",
"structure",
"describes",
"the",
"referent",
"file",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L282-L304 | train |
pkg/sftp | client.go | ReadLink | func (c *Client) ReadLink(p string) (string, error) {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpReadlinkPacket{
ID: id,
Path: p,
})
if err != nil {
return "", err
}
switch typ {
case ssh_FXP_NAME:
sid, data := unmarshalUint32(data)
if sid != id {
return "", &unexpectedIDErr{id, sid}
... | go | func (c *Client) ReadLink(p string) (string, error) {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpReadlinkPacket{
ID: id,
Path: p,
})
if err != nil {
return "", err
}
switch typ {
case ssh_FXP_NAME:
sid, data := unmarshalUint32(data)
if sid != id {
return "", &unexpectedIDErr{id, sid}
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReadLink",
"(",
"p",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
".",
"sendPacket",
"(",
"sshFxpReadlinkPa... | // ReadLink reads the target of a symbolic link. | [
"ReadLink",
"reads",
"the",
"target",
"of",
"a",
"symbolic",
"link",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L333-L359 | train |
pkg/sftp | client.go | Symlink | func (c *Client) Symlink(oldname, newname string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpSymlinkPacket{
ID: id,
Linkpath: newname,
Targetpath: oldname,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
de... | go | func (c *Client) Symlink(oldname, newname string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpSymlinkPacket{
ID: id,
Linkpath: newname,
Targetpath: oldname,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
de... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Symlink",
"(",
"oldname",
",",
"newname",
"string",
")",
"error",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
".",
"sendPacket",
"(",
"sshFxpSymlinkPacket",
... | // Symlink creates a symbolic link at 'newname', pointing at target 'oldname' | [
"Symlink",
"creates",
"a",
"symbolic",
"link",
"at",
"newname",
"pointing",
"at",
"target",
"oldname"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L362-L378 | train |
pkg/sftp | client.go | setstat | func (c *Client) setstat(path string, flags uint32, attrs interface{}) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpSetstatPacket{
ID: id,
Path: path,
Flags: flags,
Attrs: attrs,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStat... | go | func (c *Client) setstat(path string, flags uint32, attrs interface{}) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpSetstatPacket{
ID: id,
Path: path,
Flags: flags,
Attrs: attrs,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStat... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setstat",
"(",
"path",
"string",
",",
"flags",
"uint32",
",",
"attrs",
"interface",
"{",
"}",
")",
"error",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
"... | // setstat is a convience wrapper to allow for changing of various parts of the file descriptor. | [
"setstat",
"is",
"a",
"convience",
"wrapper",
"to",
"allow",
"for",
"changing",
"of",
"various",
"parts",
"of",
"the",
"file",
"descriptor",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L381-L398 | train |
pkg/sftp | client.go | Chown | func (c *Client) Chown(path string, uid, gid int) error {
type owner struct {
UID uint32
GID uint32
}
attrs := owner{uint32(uid), uint32(gid)}
return c.setstat(path, ssh_FILEXFER_ATTR_UIDGID, attrs)
} | go | func (c *Client) Chown(path string, uid, gid int) error {
type owner struct {
UID uint32
GID uint32
}
attrs := owner{uint32(uid), uint32(gid)}
return c.setstat(path, ssh_FILEXFER_ATTR_UIDGID, attrs)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Chown",
"(",
"path",
"string",
",",
"uid",
",",
"gid",
"int",
")",
"error",
"{",
"type",
"owner",
"struct",
"{",
"UID",
"uint32",
"\n",
"GID",
"uint32",
"\n",
"}",
"\n",
"attrs",
":=",
"owner",
"{",
"uint32",
... | // Chown changes the user and group owners of the named file. | [
"Chown",
"changes",
"the",
"user",
"and",
"group",
"owners",
"of",
"the",
"named",
"file",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L411-L418 | train |
pkg/sftp | client.go | Chmod | func (c *Client) Chmod(path string, mode os.FileMode) error {
return c.setstat(path, ssh_FILEXFER_ATTR_PERMISSIONS, uint32(mode))
} | go | func (c *Client) Chmod(path string, mode os.FileMode) error {
return c.setstat(path, ssh_FILEXFER_ATTR_PERMISSIONS, uint32(mode))
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Chmod",
"(",
"path",
"string",
",",
"mode",
"os",
".",
"FileMode",
")",
"error",
"{",
"return",
"c",
".",
"setstat",
"(",
"path",
",",
"ssh_FILEXFER_ATTR_PERMISSIONS",
",",
"uint32",
"(",
"mode",
")",
")",
"\n",
... | // Chmod changes the permissions of the named file. | [
"Chmod",
"changes",
"the",
"permissions",
"of",
"the",
"named",
"file",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L421-L423 | train |
pkg/sftp | client.go | Truncate | func (c *Client) Truncate(path string, size int64) error {
return c.setstat(path, ssh_FILEXFER_ATTR_SIZE, uint64(size))
} | go | func (c *Client) Truncate(path string, size int64) error {
return c.setstat(path, ssh_FILEXFER_ATTR_SIZE, uint64(size))
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Truncate",
"(",
"path",
"string",
",",
"size",
"int64",
")",
"error",
"{",
"return",
"c",
".",
"setstat",
"(",
"path",
",",
"ssh_FILEXFER_ATTR_SIZE",
",",
"uint64",
"(",
"size",
")",
")",
"\n",
"}"
] | // Truncate sets the size of the named file. Although it may be safely assumed
// that if the size is less than its current size it will be truncated to fit,
// the SFTP protocol does not specify what behavior the server should do when setting
// size greater than the current size. | [
"Truncate",
"sets",
"the",
"size",
"of",
"the",
"named",
"file",
".",
"Although",
"it",
"may",
"be",
"safely",
"assumed",
"that",
"if",
"the",
"size",
"is",
"less",
"than",
"its",
"current",
"size",
"it",
"will",
"be",
"truncated",
"to",
"fit",
"the",
... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L429-L431 | train |
pkg/sftp | client.go | Open | func (c *Client) Open(path string) (*File, error) {
return c.open(path, flags(os.O_RDONLY))
} | go | func (c *Client) Open(path string) (*File, error) {
return c.open(path, flags(os.O_RDONLY))
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Open",
"(",
"path",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"return",
"c",
".",
"open",
"(",
"path",
",",
"flags",
"(",
"os",
".",
"O_RDONLY",
")",
")",
"\n",
"}"
] | // Open opens the named file for reading. If successful, methods on the
// returned file can be used for reading; the associated file descriptor
// has mode O_RDONLY. | [
"Open",
"opens",
"the",
"named",
"file",
"for",
"reading",
".",
"If",
"successful",
"methods",
"on",
"the",
"returned",
"file",
"can",
"be",
"used",
"for",
"reading",
";",
"the",
"associated",
"file",
"descriptor",
"has",
"mode",
"O_RDONLY",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L436-L438 | train |
pkg/sftp | client.go | close | func (c *Client) close(handle string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpClosePacket{
ID: id,
Handle: handle,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
default:
return unimplementedPacketErr(typ)
}... | go | func (c *Client) close(handle string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpClosePacket{
ID: id,
Handle: handle,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
default:
return unimplementedPacketErr(typ)
}... | [
"func",
"(",
"c",
"*",
"Client",
")",
"close",
"(",
"handle",
"string",
")",
"error",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
".",
"sendPacket",
"(",
"sshFxpClosePacket",
"{",
"ID",
":",
"id... | // close closes a handle handle previously returned in the response
// to SSH_FXP_OPEN or SSH_FXP_OPENDIR. The handle becomes invalid
// immediately after this request has been sent. | [
"close",
"closes",
"a",
"handle",
"handle",
"previously",
"returned",
"in",
"the",
"response",
"to",
"SSH_FXP_OPEN",
"or",
"SSH_FXP_OPENDIR",
".",
"The",
"handle",
"becomes",
"invalid",
"immediately",
"after",
"this",
"request",
"has",
"been",
"sent",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L475-L490 | train |
pkg/sftp | client.go | StatVFS | func (c *Client) StatVFS(path string) (*StatVFS, error) {
// send the StatVFS packet to the server
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpStatvfsPacket{
ID: id,
Path: path,
})
if err != nil {
return nil, err
}
switch typ {
// server responded with valid data
case ssh_FXP_EXTENDED_REPLY:... | go | func (c *Client) StatVFS(path string) (*StatVFS, error) {
// send the StatVFS packet to the server
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpStatvfsPacket{
ID: id,
Path: path,
})
if err != nil {
return nil, err
}
switch typ {
// server responded with valid data
case ssh_FXP_EXTENDED_REPLY:... | [
"func",
"(",
"c",
"*",
"Client",
")",
"StatVFS",
"(",
"path",
"string",
")",
"(",
"*",
"StatVFS",
",",
"error",
")",
"{",
"// send the StatVFS packet to the server",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
... | // StatVFS retrieves VFS statistics from a remote host.
//
// It implements the statvfs@openssh.com SSH_FXP_EXTENDED feature
// from http://www.opensource.apple.com/source/OpenSSH/OpenSSH-175/openssh/PROTOCOL?txt. | [
"StatVFS",
"retrieves",
"VFS",
"statistics",
"from",
"a",
"remote",
"host",
".",
"It",
"implements",
"the",
"statvfs"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L520-L549 | train |
pkg/sftp | client.go | Remove | func (c *Client) Remove(path string) error {
err := c.removeFile(path)
if err, ok := err.(*StatusError); ok {
switch err.Code {
// some servers, *cough* osx *cough*, return EPERM, not ENODIR.
// serv-u returns ssh_FX_FILE_IS_A_DIRECTORY
case ssh_FX_PERMISSION_DENIED, ssh_FX_FAILURE, ssh_FX_FILE_IS_A_DIRECTORY... | go | func (c *Client) Remove(path string) error {
err := c.removeFile(path)
if err, ok := err.(*StatusError); ok {
switch err.Code {
// some servers, *cough* osx *cough*, return EPERM, not ENODIR.
// serv-u returns ssh_FX_FILE_IS_A_DIRECTORY
case ssh_FX_PERMISSION_DENIED, ssh_FX_FAILURE, ssh_FX_FILE_IS_A_DIRECTORY... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Remove",
"(",
"path",
"string",
")",
"error",
"{",
"err",
":=",
"c",
".",
"removeFile",
"(",
"path",
")",
"\n",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"StatusError",
")",
";",
"ok",
"{",
"swit... | // Remove removes the specified file or directory. An error will be returned if no
// file or directory with the specified path exists, or if the specified directory
// is not empty. | [
"Remove",
"removes",
"the",
"specified",
"file",
"or",
"directory",
".",
"An",
"error",
"will",
"be",
"returned",
"if",
"no",
"file",
"or",
"directory",
"with",
"the",
"specified",
"path",
"exists",
"or",
"if",
"the",
"specified",
"directory",
"is",
"not",
... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L559-L570 | train |
pkg/sftp | client.go | Rename | func (c *Client) Rename(oldname, newname string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpRenamePacket{
ID: id,
Oldpath: oldname,
Newpath: newname,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
default:
re... | go | func (c *Client) Rename(oldname, newname string) error {
id := c.nextID()
typ, data, err := c.sendPacket(sshFxpRenamePacket{
ID: id,
Oldpath: oldname,
Newpath: newname,
})
if err != nil {
return err
}
switch typ {
case ssh_FXP_STATUS:
return normaliseError(unmarshalStatus(id, data))
default:
re... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Rename",
"(",
"oldname",
",",
"newname",
"string",
")",
"error",
"{",
"id",
":=",
"c",
".",
"nextID",
"(",
")",
"\n",
"typ",
",",
"data",
",",
"err",
":=",
"c",
".",
"sendPacket",
"(",
"sshFxpRenamePacket",
"{... | // Rename renames a file. | [
"Rename",
"renames",
"a",
"file",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L608-L624 | train |
pkg/sftp | client.go | MkdirAll | func (c *Client) MkdirAll(path string) error {
// Most of this code mimics https://golang.org/src/os/path.go?s=514:561#L13
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := c.Stat(path)
if err == nil {
if dir.IsDir() {
return nil
}
return &os.PathErro... | go | func (c *Client) MkdirAll(path string) error {
// Most of this code mimics https://golang.org/src/os/path.go?s=514:561#L13
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := c.Stat(path)
if err == nil {
if dir.IsDir() {
return nil
}
return &os.PathErro... | [
"func",
"(",
"c",
"*",
"Client",
")",
"MkdirAll",
"(",
"path",
"string",
")",
"error",
"{",
"// Most of this code mimics https://golang.org/src/os/path.go?s=514:561#L13",
"// Fast path: if we can tell whether path is a directory or file, stop with success or error.",
"dir",
",",
"e... | // MkdirAll creates a directory named path, along with any necessary parents,
// and returns nil, or else returns an error.
// If path is already a directory, MkdirAll does nothing and returns nil.
// If path contains a regular file, an error is returned | [
"MkdirAll",
"creates",
"a",
"directory",
"named",
"path",
"along",
"with",
"any",
"necessary",
"parents",
"and",
"returns",
"nil",
"or",
"else",
"returns",
"an",
"error",
".",
"If",
"path",
"is",
"already",
"a",
"directory",
"MkdirAll",
"does",
"nothing",
"a... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L704-L746 | train |
pkg/sftp | client.go | applyOptions | func (c *Client) applyOptions(opts ...ClientOption) error {
for _, f := range opts {
if err := f(c); err != nil {
return err
}
}
return nil
} | go | func (c *Client) applyOptions(opts ...ClientOption) error {
for _, f := range opts {
if err := f(c); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"applyOptions",
"(",
"opts",
"...",
"ClientOption",
")",
"error",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"opts",
"{",
"if",
"err",
":=",
"f",
"(",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
... | // applyOptions applies options functions to the Client.
// If an error is encountered, option processing ceases. | [
"applyOptions",
"applies",
"options",
"functions",
"to",
"the",
"Client",
".",
"If",
"an",
"error",
"is",
"encountered",
"option",
"processing",
"ceases",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L750-L757 | train |
pkg/sftp | client.go | Stat | func (f *File) Stat() (os.FileInfo, error) {
fs, err := f.c.fstat(f.handle)
if err != nil {
return nil, err
}
return fileInfoFromStat(fs, path.Base(f.path)), nil
} | go | func (f *File) Stat() (os.FileInfo, error) {
fs, err := f.c.fstat(f.handle)
if err != nil {
return nil, err
}
return fileInfoFromStat(fs, path.Base(f.path)), nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Stat",
"(",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"f",
".",
"c",
".",
"fstat",
"(",
"f",
".",
"handle",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil... | // Stat returns the FileInfo structure describing file. If there is an
// error. | [
"Stat",
"returns",
"the",
"FileInfo",
"structure",
"describing",
"file",
".",
"If",
"there",
"is",
"an",
"error",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1020-L1026 | train |
pkg/sftp | client.go | Seek | func (f *File) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
f.offset = uint64(offset)
case io.SeekCurrent:
f.offset = uint64(int64(f.offset) + offset)
case io.SeekEnd:
fi, err := f.Stat()
if err != nil {
return int64(f.offset), err
}
f.offset = uint64(fi.Size() +... | go | func (f *File) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
f.offset = uint64(offset)
case io.SeekCurrent:
f.offset = uint64(int64(f.offset) + offset)
case io.SeekEnd:
fi, err := f.Stat()
if err != nil {
return int64(f.offset), err
}
f.offset = uint64(fi.Size() +... | [
"func",
"(",
"f",
"*",
"File",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"switch",
"whence",
"{",
"case",
"io",
".",
"SeekStart",
":",
"f",
".",
"offset",
"=",
"uint64",
"(",
"offset",
"... | // Seek implements io.Seeker by setting the client offset for the next Read or
// Write. It returns the next offset read. Seeking before or after the end of
// the file is undefined. Seeking relative to the end calls Stat. | [
"Seek",
"implements",
"io",
".",
"Seeker",
"by",
"setting",
"the",
"client",
"offset",
"for",
"the",
"next",
"Read",
"or",
"Write",
".",
"It",
"returns",
"the",
"next",
"offset",
"read",
".",
"Seeking",
"before",
"or",
"after",
"the",
"end",
"of",
"the",... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1172-L1188 | train |
pkg/sftp | client.go | Chmod | func (f *File) Chmod(mode os.FileMode) error {
return f.c.Chmod(f.path, mode)
} | go | func (f *File) Chmod(mode os.FileMode) error {
return f.c.Chmod(f.path, mode)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Chmod",
"(",
"mode",
"os",
".",
"FileMode",
")",
"error",
"{",
"return",
"f",
".",
"c",
".",
"Chmod",
"(",
"f",
".",
"path",
",",
"mode",
")",
"\n",
"}"
] | // Chmod changes the permissions of the current file. | [
"Chmod",
"changes",
"the",
"permissions",
"of",
"the",
"current",
"file",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1196-L1198 | train |
pkg/sftp | client.go | Truncate | func (f *File) Truncate(size int64) error {
return f.c.Truncate(f.path, size)
} | go | func (f *File) Truncate(size int64) error {
return f.c.Truncate(f.path, size)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Truncate",
"(",
"size",
"int64",
")",
"error",
"{",
"return",
"f",
".",
"c",
".",
"Truncate",
"(",
"f",
".",
"path",
",",
"size",
")",
"\n",
"}"
] | // Truncate sets the size of the current file. Although it may be safely assumed
// that if the size is less than its current size it will be truncated to fit,
// the SFTP protocol does not specify what behavior the server should do when setting
// size greater than the current size. | [
"Truncate",
"sets",
"the",
"size",
"of",
"the",
"current",
"file",
".",
"Although",
"it",
"may",
"be",
"safely",
"assumed",
"that",
"if",
"the",
"size",
"is",
"less",
"than",
"its",
"current",
"size",
"it",
"will",
"be",
"truncated",
"to",
"fit",
"the",
... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1204-L1206 | train |
pkg/sftp | client.go | normaliseError | func normaliseError(err error) error {
switch err := err.(type) {
case *StatusError:
switch err.Code {
case ssh_FX_EOF:
return io.EOF
case ssh_FX_NO_SUCH_FILE:
return os.ErrNotExist
case ssh_FX_OK:
return nil
default:
return err
}
default:
return err
}
} | go | func normaliseError(err error) error {
switch err := err.(type) {
case *StatusError:
switch err.Code {
case ssh_FX_EOF:
return io.EOF
case ssh_FX_NO_SUCH_FILE:
return os.ErrNotExist
case ssh_FX_OK:
return nil
default:
return err
}
default:
return err
}
} | [
"func",
"normaliseError",
"(",
"err",
"error",
")",
"error",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"StatusError",
":",
"switch",
"err",
".",
"Code",
"{",
"case",
"ssh_FX_EOF",
":",
"return",
"io",
".",
"EOF",
"\n... | // normaliseError normalises an error into a more standard form that can be
// checked against stdlib errors like io.EOF or os.ErrNotExist. | [
"normaliseError",
"normalises",
"an",
"error",
"into",
"a",
"more",
"standard",
"form",
"that",
"can",
"be",
"checked",
"against",
"stdlib",
"errors",
"like",
"io",
".",
"EOF",
"or",
"os",
".",
"ErrNotExist",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1217-L1233 | train |
pkg/sftp | client.go | flags | func flags(f int) uint32 {
var out uint32
switch f & os.O_WRONLY {
case os.O_WRONLY:
out |= ssh_FXF_WRITE
case os.O_RDONLY:
out |= ssh_FXF_READ
}
if f&os.O_RDWR == os.O_RDWR {
out |= ssh_FXF_READ | ssh_FXF_WRITE
}
if f&os.O_APPEND == os.O_APPEND {
out |= ssh_FXF_APPEND
}
if f&os.O_CREATE == os.O_CREAT... | go | func flags(f int) uint32 {
var out uint32
switch f & os.O_WRONLY {
case os.O_WRONLY:
out |= ssh_FXF_WRITE
case os.O_RDONLY:
out |= ssh_FXF_READ
}
if f&os.O_RDWR == os.O_RDWR {
out |= ssh_FXF_READ | ssh_FXF_WRITE
}
if f&os.O_APPEND == os.O_APPEND {
out |= ssh_FXF_APPEND
}
if f&os.O_CREATE == os.O_CREAT... | [
"func",
"flags",
"(",
"f",
"int",
")",
"uint32",
"{",
"var",
"out",
"uint32",
"\n",
"switch",
"f",
"&",
"os",
".",
"O_WRONLY",
"{",
"case",
"os",
".",
"O_WRONLY",
":",
"out",
"|=",
"ssh_FXF_WRITE",
"\n",
"case",
"os",
".",
"O_RDONLY",
":",
"out",
"... | // flags converts the flags passed to OpenFile into ssh flags.
// Unsupported flags are ignored. | [
"flags",
"converts",
"the",
"flags",
"passed",
"to",
"OpenFile",
"into",
"ssh",
"flags",
".",
"Unsupported",
"flags",
"are",
"ignored",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/client.go#L1259-L1283 | train |
pkg/sftp | attrs.go | toFileMode | func toFileMode(mode uint32) os.FileMode {
var fm = os.FileMode(mode & 0777)
switch mode & syscall.S_IFMT {
case syscall.S_IFBLK:
fm |= os.ModeDevice
case syscall.S_IFCHR:
fm |= os.ModeDevice | os.ModeCharDevice
case syscall.S_IFDIR:
fm |= os.ModeDir
case syscall.S_IFIFO:
fm |= os.ModeNamedPipe
case sysc... | go | func toFileMode(mode uint32) os.FileMode {
var fm = os.FileMode(mode & 0777)
switch mode & syscall.S_IFMT {
case syscall.S_IFBLK:
fm |= os.ModeDevice
case syscall.S_IFCHR:
fm |= os.ModeDevice | os.ModeCharDevice
case syscall.S_IFDIR:
fm |= os.ModeDir
case syscall.S_IFIFO:
fm |= os.ModeNamedPipe
case sysc... | [
"func",
"toFileMode",
"(",
"mode",
"uint32",
")",
"os",
".",
"FileMode",
"{",
"var",
"fm",
"=",
"os",
".",
"FileMode",
"(",
"mode",
"&",
"0777",
")",
"\n",
"switch",
"mode",
"&",
"syscall",
".",
"S_IFMT",
"{",
"case",
"syscall",
".",
"S_IFBLK",
":",
... | // toFileMode converts sftp filemode bits to the os.FileMode specification | [
"toFileMode",
"converts",
"sftp",
"filemode",
"bits",
"to",
"the",
"os",
".",
"FileMode",
"specification"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/attrs.go#L174-L202 | train |
pkg/sftp | attrs.go | fromFileMode | func fromFileMode(mode os.FileMode) uint32 {
ret := uint32(0)
if mode&os.ModeDevice != 0 {
if mode&os.ModeCharDevice != 0 {
ret |= syscall.S_IFCHR
} else {
ret |= syscall.S_IFBLK
}
}
if mode&os.ModeDir != 0 {
ret |= syscall.S_IFDIR
}
if mode&os.ModeSymlink != 0 {
ret |= syscall.S_IFLNK
}
if mod... | go | func fromFileMode(mode os.FileMode) uint32 {
ret := uint32(0)
if mode&os.ModeDevice != 0 {
if mode&os.ModeCharDevice != 0 {
ret |= syscall.S_IFCHR
} else {
ret |= syscall.S_IFBLK
}
}
if mode&os.ModeDir != 0 {
ret |= syscall.S_IFDIR
}
if mode&os.ModeSymlink != 0 {
ret |= syscall.S_IFLNK
}
if mod... | [
"func",
"fromFileMode",
"(",
"mode",
"os",
".",
"FileMode",
")",
"uint32",
"{",
"ret",
":=",
"uint32",
"(",
"0",
")",
"\n\n",
"if",
"mode",
"&",
"os",
".",
"ModeDevice",
"!=",
"0",
"{",
"if",
"mode",
"&",
"os",
".",
"ModeCharDevice",
"!=",
"0",
"{"... | // fromFileMode converts from the os.FileMode specification to sftp filemode bits | [
"fromFileMode",
"converts",
"from",
"the",
"os",
".",
"FileMode",
"specification",
"to",
"sftp",
"filemode",
"bits"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/attrs.go#L205-L243 | train |
pkg/sftp | server.go | WithDebug | func WithDebug(w io.Writer) ServerOption {
return func(s *Server) error {
s.debugStream = w
return nil
}
} | go | func WithDebug(w io.Writer) ServerOption {
return func(s *Server) error {
s.debugStream = w
return nil
}
} | [
"func",
"WithDebug",
"(",
"w",
"io",
".",
"Writer",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"debugStream",
"=",
"w",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithDebug enables Server debugging output to the supplied io.Writer. | [
"WithDebug",
"enables",
"Server",
"debugging",
"output",
"to",
"the",
"supplied",
"io",
".",
"Writer",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/server.go#L105-L110 | train |
pkg/sftp | server.go | sftpServerWorker | func (svr *Server) sftpServerWorker(pktChan chan orderedRequest) error {
for pkt := range pktChan {
// readonly checks
readonly := true
switch pkt := pkt.requestPacket.(type) {
case notReadOnly:
readonly = false
case *sshFxpOpenPacket:
readonly = pkt.readonly()
case *sshFxpExtendedPacket:
readonly... | go | func (svr *Server) sftpServerWorker(pktChan chan orderedRequest) error {
for pkt := range pktChan {
// readonly checks
readonly := true
switch pkt := pkt.requestPacket.(type) {
case notReadOnly:
readonly = false
case *sshFxpOpenPacket:
readonly = pkt.readonly()
case *sshFxpExtendedPacket:
readonly... | [
"func",
"(",
"svr",
"*",
"Server",
")",
"sftpServerWorker",
"(",
"pktChan",
"chan",
"orderedRequest",
")",
"error",
"{",
"for",
"pkt",
":=",
"range",
"pktChan",
"{",
"// readonly checks",
"readonly",
":=",
"true",
"\n",
"switch",
"pkt",
":=",
"pkt",
".",
"... | // Up to N parallel servers | [
"Up",
"to",
"N",
"parallel",
"servers"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/server.go#L126-L153 | train |
pkg/sftp | server.go | Serve | func (svr *Server) Serve() error {
var wg sync.WaitGroup
runWorker := func(ch chan orderedRequest) {
wg.Add(1)
go func() {
defer wg.Done()
if err := svr.sftpServerWorker(ch); err != nil {
svr.conn.Close() // shuts down recvPacket
}
}()
}
pktChan := svr.pktMgr.workerChan(runWorker)
var err error... | go | func (svr *Server) Serve() error {
var wg sync.WaitGroup
runWorker := func(ch chan orderedRequest) {
wg.Add(1)
go func() {
defer wg.Done()
if err := svr.sftpServerWorker(ch); err != nil {
svr.conn.Close() // shuts down recvPacket
}
}()
}
pktChan := svr.pktMgr.workerChan(runWorker)
var err error... | [
"func",
"(",
"svr",
"*",
"Server",
")",
"Serve",
"(",
")",
"error",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"runWorker",
":=",
"func",
"(",
"ch",
"chan",
"orderedRequest",
")",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"... | // Serve serves SFTP connections until the streams stop or the SFTP subsystem
// is stopped. | [
"Serve",
"serves",
"SFTP",
"connections",
"until",
"the",
"streams",
"stop",
"or",
"the",
"SFTP",
"subsystem",
"is",
"stopped",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/server.go#L291-L342 | train |
pkg/sftp | server.go | translateErrno | func translateErrno(errno syscall.Errno) uint32 {
switch errno {
case 0:
return ssh_FX_OK
case syscall.ENOENT:
return ssh_FX_NO_SUCH_FILE
case syscall.EPERM:
return ssh_FX_PERMISSION_DENIED
}
return ssh_FX_FAILURE
} | go | func translateErrno(errno syscall.Errno) uint32 {
switch errno {
case 0:
return ssh_FX_OK
case syscall.ENOENT:
return ssh_FX_NO_SUCH_FILE
case syscall.EPERM:
return ssh_FX_PERMISSION_DENIED
}
return ssh_FX_FAILURE
} | [
"func",
"translateErrno",
"(",
"errno",
"syscall",
".",
"Errno",
")",
"uint32",
"{",
"switch",
"errno",
"{",
"case",
"0",
":",
"return",
"ssh_FX_OK",
"\n",
"case",
"syscall",
".",
"ENOENT",
":",
"return",
"ssh_FX_NO_SUCH_FILE",
"\n",
"case",
"syscall",
".",
... | // translateErrno translates a syscall error number to a SFTP error code. | [
"translateErrno",
"translates",
"a",
"syscall",
"error",
"number",
"to",
"a",
"SFTP",
"error",
"code",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/server.go#L526-L537 | train |
pkg/sftp | match.go | Split | func Split(path string) (dir, file string) {
i := len(path) - 1
for i >= 0 && !isPathSeparator(path[i]) {
i--
}
return path[:i+1], path[i+1:]
} | go | func Split(path string) (dir, file string) {
i := len(path) - 1
for i >= 0 && !isPathSeparator(path[i]) {
i--
}
return path[:i+1], path[i+1:]
} | [
"func",
"Split",
"(",
"path",
"string",
")",
"(",
"dir",
",",
"file",
"string",
")",
"{",
"i",
":=",
"len",
"(",
"path",
")",
"-",
"1",
"\n",
"for",
"i",
">=",
"0",
"&&",
"!",
"isPathSeparator",
"(",
"path",
"[",
"i",
"]",
")",
"{",
"i",
"--"... | // Split splits path immediately following the final Separator,
// separating it into a directory and file name component.
// If there is no Separator in path, Split returns an empty dir
// and file set to path.
// The returned values have the property that path = dir+file. | [
"Split",
"splits",
"path",
"immediately",
"following",
"the",
"final",
"Separator",
"separating",
"it",
"into",
"a",
"directory",
"and",
"file",
"name",
"component",
".",
"If",
"there",
"is",
"no",
"Separator",
"in",
"path",
"Split",
"returns",
"an",
"empty",
... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/match.go#L186-L192 | train |
pkg/sftp | match.go | cleanGlobPath | func cleanGlobPath(path string) string {
switch path {
case "":
return "."
case string(separator):
// do nothing to the path
return path
default:
return path[0 : len(path)-1] // chop off trailing separator
}
} | go | func cleanGlobPath(path string) string {
switch path {
case "":
return "."
case string(separator):
// do nothing to the path
return path
default:
return path[0 : len(path)-1] // chop off trailing separator
}
} | [
"func",
"cleanGlobPath",
"(",
"path",
"string",
")",
"string",
"{",
"switch",
"path",
"{",
"case",
"\"",
"\"",
":",
"return",
"\"",
"\"",
"\n",
"case",
"string",
"(",
"separator",
")",
":",
"// do nothing to the path",
"return",
"path",
"\n",
"default",
":... | // cleanGlobPath prepares path for glob matching. | [
"cleanGlobPath",
"prepares",
"path",
"for",
"glob",
"matching",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/match.go#L240-L250 | train |
pkg/sftp | packet-typing.go | makePacket | func makePacket(p rxPacket) (requestPacket, error) {
var pkt requestPacket
switch p.pktType {
case ssh_FXP_INIT:
pkt = &sshFxInitPacket{}
case ssh_FXP_LSTAT:
pkt = &sshFxpLstatPacket{}
case ssh_FXP_OPEN:
pkt = &sshFxpOpenPacket{}
case ssh_FXP_CLOSE:
pkt = &sshFxpClosePacket{}
case ssh_FXP_READ:
pkt = &... | go | func makePacket(p rxPacket) (requestPacket, error) {
var pkt requestPacket
switch p.pktType {
case ssh_FXP_INIT:
pkt = &sshFxInitPacket{}
case ssh_FXP_LSTAT:
pkt = &sshFxpLstatPacket{}
case ssh_FXP_OPEN:
pkt = &sshFxpOpenPacket{}
case ssh_FXP_CLOSE:
pkt = &sshFxpClosePacket{}
case ssh_FXP_READ:
pkt = &... | [
"func",
"makePacket",
"(",
"p",
"rxPacket",
")",
"(",
"requestPacket",
",",
"error",
")",
"{",
"var",
"pkt",
"requestPacket",
"\n",
"switch",
"p",
".",
"pktType",
"{",
"case",
"ssh_FXP_INIT",
":",
"pkt",
"=",
"&",
"sshFxInitPacket",
"{",
"}",
"\n",
"case... | // take raw incoming packet data and build packet objects | [
"take",
"raw",
"incoming",
"packet",
"data",
"and",
"build",
"packet",
"objects"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet-typing.go#L82-L134 | train |
pkg/sftp | packet.go | sendPacket | func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error {
bb, err := m.MarshalBinary()
if err != nil {
return errors.Errorf("binary marshaller failed: %v", err)
}
if debugDumpTxPacketBytes {
debug("send packet: %s %d bytes %x", fxp(bb[0]), len(bb), bb[1:])
} else if debugDumpTxPacket {
debug("send pac... | go | func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error {
bb, err := m.MarshalBinary()
if err != nil {
return errors.Errorf("binary marshaller failed: %v", err)
}
if debugDumpTxPacketBytes {
debug("send packet: %s %d bytes %x", fxp(bb[0]), len(bb), bb[1:])
} else if debugDumpTxPacket {
debug("send pac... | [
"func",
"sendPacket",
"(",
"w",
"io",
".",
"Writer",
",",
"m",
"encoding",
".",
"BinaryMarshaler",
")",
"error",
"{",
"bb",
",",
"err",
":=",
"m",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",... | // sendPacket marshals p according to RFC 4234. | [
"sendPacket",
"marshals",
"p",
"according",
"to",
"RFC",
"4234",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet.go#L118-L138 | train |
pkg/sftp | packet.go | MarshalBinary | func (p *StatVFS) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer
buf.Write([]byte{ssh_FXP_EXTENDED_REPLY})
err := binary.Write(&buf, binary.BigEndian, p)
return buf.Bytes(), err
} | go | func (p *StatVFS) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer
buf.Write([]byte{ssh_FXP_EXTENDED_REPLY})
err := binary.Write(&buf, binary.BigEndian, p)
return buf.Bytes(), err
} | [
"func",
"(",
"p",
"*",
"StatVFS",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"buf",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"ssh_FXP_EXTENDED_REPLY",
"}",
")",
"\n",
... | // Convert to ssh_FXP_EXTENDED_REPLY packet binary format | [
"Convert",
"to",
"ssh_FXP_EXTENDED_REPLY",
"packet",
"binary",
"format"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet.go#L860-L865 | train |
pkg/sftp | packet-manager.go | readyPacket | func (s *packetManager) readyPacket(pkt orderedResponse) {
s.responses <- pkt
s.working.Done()
} | go | func (s *packetManager) readyPacket(pkt orderedResponse) {
s.responses <- pkt
s.working.Done()
} | [
"func",
"(",
"s",
"*",
"packetManager",
")",
"readyPacket",
"(",
"pkt",
"orderedResponse",
")",
"{",
"s",
".",
"responses",
"<-",
"pkt",
"\n",
"s",
".",
"working",
".",
"Done",
"(",
")",
"\n",
"}"
] | // register outgoing packets as being ready | [
"register",
"outgoing",
"packets",
"as",
"being",
"ready"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet-manager.go#L90-L93 | train |
pkg/sftp | packet-manager.go | workerChan | func (s *packetManager) workerChan(runWorker func(chan orderedRequest),
) chan orderedRequest {
// multiple workers for faster read/writes
rwChan := make(chan orderedRequest, SftpServerWorkerCount)
for i := 0; i < SftpServerWorkerCount; i++ {
runWorker(rwChan)
}
// single worker to enforce sequential processin... | go | func (s *packetManager) workerChan(runWorker func(chan orderedRequest),
) chan orderedRequest {
// multiple workers for faster read/writes
rwChan := make(chan orderedRequest, SftpServerWorkerCount)
for i := 0; i < SftpServerWorkerCount; i++ {
runWorker(rwChan)
}
// single worker to enforce sequential processin... | [
"func",
"(",
"s",
"*",
"packetManager",
")",
"workerChan",
"(",
"runWorker",
"func",
"(",
"chan",
"orderedRequest",
")",
",",
")",
"chan",
"orderedRequest",
"{",
"// multiple workers for faster read/writes",
"rwChan",
":=",
"make",
"(",
"chan",
"orderedRequest",
"... | // Passed a worker function, returns a channel for incoming packets.
// Keep process packet responses in the order they are received while
// maximizing throughput of file transfers. | [
"Passed",
"a",
"worker",
"function",
"returns",
"a",
"channel",
"for",
"incoming",
"packets",
".",
"Keep",
"process",
"packet",
"responses",
"in",
"the",
"order",
"they",
"are",
"received",
"while",
"maximizing",
"throughput",
"of",
"file",
"transfers",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet-manager.go#L105-L141 | train |
pkg/sftp | packet-manager.go | maybeSendPackets | func (s *packetManager) maybeSendPackets() {
for {
if len(s.outgoing) == 0 || len(s.incoming) == 0 {
debug("break! -- outgoing: %v; incoming: %v",
len(s.outgoing), len(s.incoming))
break
}
out := s.outgoing[0]
in := s.incoming[0]
// debug("incoming: %v", ids(s.incoming))
// debug("outgoing: %v", ... | go | func (s *packetManager) maybeSendPackets() {
for {
if len(s.outgoing) == 0 || len(s.incoming) == 0 {
debug("break! -- outgoing: %v; incoming: %v",
len(s.outgoing), len(s.incoming))
break
}
out := s.outgoing[0]
in := s.incoming[0]
// debug("incoming: %v", ids(s.incoming))
// debug("outgoing: %v", ... | [
"func",
"(",
"s",
"*",
"packetManager",
")",
"maybeSendPackets",
"(",
")",
"{",
"for",
"{",
"if",
"len",
"(",
"s",
".",
"outgoing",
")",
"==",
"0",
"||",
"len",
"(",
"s",
".",
"incoming",
")",
"==",
"0",
"{",
"debug",
"(",
"\"",
"\"",
",",
"len... | // send as many packets as are ready | [
"send",
"as",
"many",
"packets",
"as",
"are",
"ready"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/packet-manager.go#L163-L188 | train |
pkg/sftp | conn.go | Close | func (c *clientConn) Close() error {
defer c.wg.Wait()
return c.conn.Close()
} | go | func (c *clientConn) Close() error {
defer c.wg.Wait()
return c.conn.Close()
} | [
"func",
"(",
"c",
"*",
"clientConn",
")",
"Close",
"(",
")",
"error",
"{",
"defer",
"c",
".",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close closes the SFTP session. | [
"Close",
"closes",
"the",
"SFTP",
"session",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/conn.go#L53-L56 | train |
pkg/sftp | conn.go | recv | func (c *clientConn) recv() error {
defer func() {
c.conn.Lock()
c.conn.Close()
c.conn.Unlock()
}()
for {
typ, data, err := c.recvPacket()
if err != nil {
return err
}
sid, _ := unmarshalUint32(data)
c.Lock()
ch, ok := c.inflight[sid]
delete(c.inflight, sid)
c.Unlock()
if !ok {
// This ... | go | func (c *clientConn) recv() error {
defer func() {
c.conn.Lock()
c.conn.Close()
c.conn.Unlock()
}()
for {
typ, data, err := c.recvPacket()
if err != nil {
return err
}
sid, _ := unmarshalUint32(data)
c.Lock()
ch, ok := c.inflight[sid]
delete(c.inflight, sid)
c.Unlock()
if !ok {
// This ... | [
"func",
"(",
"c",
"*",
"clientConn",
")",
"recv",
"(",
")",
"error",
"{",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"conn",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"conn",
".",
"Unlock",
"(",
"... | // recv continuously reads from the server and forwards responses to the
// appropriate channel. | [
"recv",
"continuously",
"reads",
"from",
"the",
"server",
"and",
"forwards",
"responses",
"to",
"the",
"appropriate",
"channel",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/conn.go#L68-L92 | train |
pkg/sftp | conn.go | broadcastErr | func (c *clientConn) broadcastErr(err error) {
c.Lock()
listeners := make([]chan<- result, 0, len(c.inflight))
for _, ch := range c.inflight {
listeners = append(listeners, ch)
}
c.Unlock()
for _, ch := range listeners {
ch <- result{err: err}
}
c.err = err
close(c.closed)
} | go | func (c *clientConn) broadcastErr(err error) {
c.Lock()
listeners := make([]chan<- result, 0, len(c.inflight))
for _, ch := range c.inflight {
listeners = append(listeners, ch)
}
c.Unlock()
for _, ch := range listeners {
ch <- result{err: err}
}
c.err = err
close(c.closed)
} | [
"func",
"(",
"c",
"*",
"clientConn",
")",
"broadcastErr",
"(",
"err",
"error",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"listeners",
":=",
"make",
"(",
"[",
"]",
"chan",
"<-",
"result",
",",
"0",
",",
"len",
"(",
"c",
".",
"inflight",
")",
"... | // broadcastErr sends an error to all goroutines waiting for a response. | [
"broadcastErr",
"sends",
"an",
"error",
"to",
"all",
"goroutines",
"waiting",
"for",
"a",
"response",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/conn.go#L126-L138 | train |
pkg/sftp | request-server.go | closeRequest | func (rs *RequestServer) closeRequest(handle string) error {
rs.openRequestLock.Lock()
defer rs.openRequestLock.Unlock()
if r, ok := rs.openRequests[handle]; ok {
delete(rs.openRequests, handle)
return r.close()
}
return syscall.EBADF
} | go | func (rs *RequestServer) closeRequest(handle string) error {
rs.openRequestLock.Lock()
defer rs.openRequestLock.Unlock()
if r, ok := rs.openRequests[handle]; ok {
delete(rs.openRequests, handle)
return r.close()
}
return syscall.EBADF
} | [
"func",
"(",
"rs",
"*",
"RequestServer",
")",
"closeRequest",
"(",
"handle",
"string",
")",
"error",
"{",
"rs",
".",
"openRequestLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rs",
".",
"openRequestLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
",",
... | // Close the Request and clear from openRequests map | [
"Close",
"the",
"Request",
"and",
"clear",
"from",
"openRequests",
"map"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-server.go#L76-L84 | train |
pkg/sftp | request-server.go | Serve | func (rs *RequestServer) Serve() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
runWorker := func(ch chan orderedRequest) {
wg.Add(1)
go func() {
defer wg.Done()
if err := rs.packetWorker(ctx, ch); err != nil {
rs.conn.Close() // shuts down recvPac... | go | func (rs *RequestServer) Serve() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
runWorker := func(ch chan orderedRequest) {
wg.Add(1)
go func() {
defer wg.Done()
if err := rs.packetWorker(ctx, ch); err != nil {
rs.conn.Close() // shuts down recvPac... | [
"func",
"(",
"rs",
"*",
"RequestServer",
")",
"Serve",
"(",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"var",
"wg",
"sync",
... | // Serve requests for user session | [
"Serve",
"requests",
"for",
"user",
"session"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-server.go#L90-L145 | train |
pkg/sftp | request-server.go | cleanPacketPath | func cleanPacketPath(pkt *sshFxpRealpathPacket) responsePacket {
path := cleanPath(pkt.getPath())
return &sshFxpNamePacket{
ID: pkt.id(),
NameAttrs: []sshFxpNameAttr{{
Name: path,
LongName: path,
Attrs: emptyFileStat,
}},
}
} | go | func cleanPacketPath(pkt *sshFxpRealpathPacket) responsePacket {
path := cleanPath(pkt.getPath())
return &sshFxpNamePacket{
ID: pkt.id(),
NameAttrs: []sshFxpNameAttr{{
Name: path,
LongName: path,
Attrs: emptyFileStat,
}},
}
} | [
"func",
"cleanPacketPath",
"(",
"pkt",
"*",
"sshFxpRealpathPacket",
")",
"responsePacket",
"{",
"path",
":=",
"cleanPath",
"(",
"pkt",
".",
"getPath",
"(",
")",
")",
"\n",
"return",
"&",
"sshFxpNamePacket",
"{",
"ID",
":",
"pkt",
".",
"id",
"(",
")",
","... | // clean and return name packet for file | [
"clean",
"and",
"return",
"name",
"packet",
"for",
"file"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-server.go#L200-L210 | train |
pkg/sftp | request-attrs.go | Attributes | func (r *Request) Attributes() *FileStat {
fs, _ := getFileStat(r.Flags, r.Attrs)
return fs
} | go | func (r *Request) Attributes() *FileStat {
fs, _ := getFileStat(r.Flags, r.Attrs)
return fs
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Attributes",
"(",
")",
"*",
"FileStat",
"{",
"fs",
",",
"_",
":=",
"getFileStat",
"(",
"r",
".",
"Flags",
",",
"r",
".",
"Attrs",
")",
"\n",
"return",
"fs",
"\n",
"}"
] | // Attributres parses file attributes byte blob and return them in a
// FileStat object. | [
"Attributres",
"parses",
"file",
"attributes",
"byte",
"blob",
"and",
"return",
"them",
"in",
"a",
"FileStat",
"object",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-attrs.go#L60-L63 | train |
shurcooL/graphql | ident/ident.go | ToMixedCaps | func (n Name) ToMixedCaps() string {
for i, word := range n {
if strings.EqualFold(word, "IDs") { // Special case, plural form of ID initialism.
n[i] = "IDs"
continue
}
if initialism, ok := isInitialism(word); ok {
n[i] = initialism
continue
}
if brand, ok := isBrand(word); ok {
n[i] = brand
... | go | func (n Name) ToMixedCaps() string {
for i, word := range n {
if strings.EqualFold(word, "IDs") { // Special case, plural form of ID initialism.
n[i] = "IDs"
continue
}
if initialism, ok := isInitialism(word); ok {
n[i] = initialism
continue
}
if brand, ok := isBrand(word); ok {
n[i] = brand
... | [
"func",
"(",
"n",
"Name",
")",
"ToMixedCaps",
"(",
")",
"string",
"{",
"for",
"i",
",",
"word",
":=",
"range",
"n",
"{",
"if",
"strings",
".",
"EqualFold",
"(",
"word",
",",
"\"",
"\"",
")",
"{",
"// Special case, plural form of ID initialism.",
"n",
"["... | // ToMixedCaps expresses identifer name in MixedCaps naming convention.
//
// E.g., "ClientMutationID". | [
"ToMixedCaps",
"expresses",
"identifer",
"name",
"in",
"MixedCaps",
"naming",
"convention",
".",
"E",
".",
"g",
".",
"ClientMutationID",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/ident/ident.go#L124-L142 | train |
shurcooL/graphql | ident/ident.go | ToLowerCamelCase | func (n Name) ToLowerCamelCase() string {
for i, word := range n {
if i == 0 {
n[i] = strings.ToLower(word)
continue
}
r, size := utf8.DecodeRuneInString(word)
n[i] = string(unicode.ToUpper(r)) + strings.ToLower(word[size:])
}
return strings.Join(n, "")
} | go | func (n Name) ToLowerCamelCase() string {
for i, word := range n {
if i == 0 {
n[i] = strings.ToLower(word)
continue
}
r, size := utf8.DecodeRuneInString(word)
n[i] = string(unicode.ToUpper(r)) + strings.ToLower(word[size:])
}
return strings.Join(n, "")
} | [
"func",
"(",
"n",
"Name",
")",
"ToLowerCamelCase",
"(",
")",
"string",
"{",
"for",
"i",
",",
"word",
":=",
"range",
"n",
"{",
"if",
"i",
"==",
"0",
"{",
"n",
"[",
"i",
"]",
"=",
"strings",
".",
"ToLower",
"(",
"word",
")",
"\n",
"continue",
"\n... | // ToLowerCamelCase expresses identifer name in lowerCamelCase naming convention.
//
// E.g., "clientMutationId". | [
"ToLowerCamelCase",
"expresses",
"identifer",
"name",
"in",
"lowerCamelCase",
"naming",
"convention",
".",
"E",
".",
"g",
".",
"clientMutationId",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/ident/ident.go#L147-L157 | train |
shurcooL/graphql | ident/ident.go | isInitialism | func isInitialism(word string) (string, bool) {
initialism := strings.ToUpper(word)
_, ok := initialisms[initialism]
return initialism, ok
} | go | func isInitialism(word string) (string, bool) {
initialism := strings.ToUpper(word)
_, ok := initialisms[initialism]
return initialism, ok
} | [
"func",
"isInitialism",
"(",
"word",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"initialism",
":=",
"strings",
".",
"ToUpper",
"(",
"word",
")",
"\n",
"_",
",",
"ok",
":=",
"initialisms",
"[",
"initialism",
"]",
"\n",
"return",
"initialism",
... | // isInitialism reports whether word is an initialism. | [
"isInitialism",
"reports",
"whether",
"word",
"is",
"an",
"initialism",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/ident/ident.go#L160-L164 | train |
shurcooL/graphql | ident/ident.go | isTwoInitialisms | func isTwoInitialisms(word string) (string, string, bool) {
word = strings.ToUpper(word)
for i := 2; i <= len(word)-2; i++ { // Shortest initialism is 2 characters long.
_, ok1 := initialisms[word[:i]]
_, ok2 := initialisms[word[i:]]
if ok1 && ok2 {
return word[:i], word[i:], true
}
}
return "", "", fals... | go | func isTwoInitialisms(word string) (string, string, bool) {
word = strings.ToUpper(word)
for i := 2; i <= len(word)-2; i++ { // Shortest initialism is 2 characters long.
_, ok1 := initialisms[word[:i]]
_, ok2 := initialisms[word[i:]]
if ok1 && ok2 {
return word[:i], word[i:], true
}
}
return "", "", fals... | [
"func",
"isTwoInitialisms",
"(",
"word",
"string",
")",
"(",
"string",
",",
"string",
",",
"bool",
")",
"{",
"word",
"=",
"strings",
".",
"ToUpper",
"(",
"word",
")",
"\n",
"for",
"i",
":=",
"2",
";",
"i",
"<=",
"len",
"(",
"word",
")",
"-",
"2",... | // isTwoInitialisms reports whether word is two initialisms. | [
"isTwoInitialisms",
"reports",
"whether",
"word",
"is",
"two",
"initialisms",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/ident/ident.go#L167-L177 | train |
shurcooL/graphql | ident/ident.go | isBrand | func isBrand(word string) (string, bool) {
brand, ok := brands[strings.ToLower(word)]
return brand, ok
} | go | func isBrand(word string) (string, bool) {
brand, ok := brands[strings.ToLower(word)]
return brand, ok
} | [
"func",
"isBrand",
"(",
"word",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"brand",
",",
"ok",
":=",
"brands",
"[",
"strings",
".",
"ToLower",
"(",
"word",
")",
"]",
"\n",
"return",
"brand",
",",
"ok",
"\n",
"}"
] | // isBrand reports whether word is a brand. | [
"isBrand",
"reports",
"whether",
"word",
"is",
"a",
"brand",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/ident/ident.go#L229-L232 | train |
shurcooL/graphql | query.go | writeQuery | func writeQuery(w io.Writer, t reflect.Type, inline bool) {
switch t.Kind() {
case reflect.Ptr, reflect.Slice:
writeQuery(w, t.Elem(), false)
case reflect.Struct:
// If the type implements json.Unmarshaler, it's a scalar. Don't expand it.
if reflect.PtrTo(t).Implements(jsonUnmarshaler) {
return
}
if !in... | go | func writeQuery(w io.Writer, t reflect.Type, inline bool) {
switch t.Kind() {
case reflect.Ptr, reflect.Slice:
writeQuery(w, t.Elem(), false)
case reflect.Struct:
// If the type implements json.Unmarshaler, it's a scalar. Don't expand it.
if reflect.PtrTo(t).Implements(jsonUnmarshaler) {
return
}
if !in... | [
"func",
"writeQuery",
"(",
"w",
"io",
".",
"Writer",
",",
"t",
"reflect",
".",
"Type",
",",
"inline",
"bool",
")",
"{",
"switch",
"t",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Slice",
":",
"writeQuery",
"(",
... | // writeQuery writes a minified query for t to w.
// If inline is true, the struct fields of t are inlined into parent struct. | [
"writeQuery",
"writes",
"a",
"minified",
"query",
"for",
"t",
"to",
"w",
".",
"If",
"inline",
"is",
"true",
"the",
"struct",
"fields",
"of",
"t",
"are",
"inlined",
"into",
"parent",
"struct",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/query.go#L97-L129 | train |
shurcooL/graphql | graphql.go | NewClient | func NewClient(url string, httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &Client{
url: url,
httpClient: httpClient,
}
} | go | func NewClient(url string, httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &Client{
url: url,
httpClient: httpClient,
}
} | [
"func",
"NewClient",
"(",
"url",
"string",
",",
"httpClient",
"*",
"http",
".",
"Client",
")",
"*",
"Client",
"{",
"if",
"httpClient",
"==",
"nil",
"{",
"httpClient",
"=",
"http",
".",
"DefaultClient",
"\n",
"}",
"\n",
"return",
"&",
"Client",
"{",
"ur... | // NewClient creates a GraphQL client targeting the specified GraphQL server URL.
// If httpClient is nil, then http.DefaultClient is used. | [
"NewClient",
"creates",
"a",
"GraphQL",
"client",
"targeting",
"the",
"specified",
"GraphQL",
"server",
"URL",
".",
"If",
"httpClient",
"is",
"nil",
"then",
"http",
".",
"DefaultClient",
"is",
"used",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/graphql.go#L23-L31 | train |
shurcooL/graphql | graphql.go | Query | func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error {
return c.do(ctx, queryOperation, q, variables)
} | go | func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error {
return c.do(ctx, queryOperation, q, variables)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"interface",
"{",
"}",
",",
"variables",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"c",
".",
"do",
"(",
"ctx",
",... | // Query executes a single GraphQL query request,
// with a query derived from q, populating the response into it.
// q should be a pointer to struct that corresponds to the GraphQL schema. | [
"Query",
"executes",
"a",
"single",
"GraphQL",
"query",
"request",
"with",
"a",
"query",
"derived",
"from",
"q",
"populating",
"the",
"response",
"into",
"it",
".",
"q",
"should",
"be",
"a",
"pointer",
"to",
"struct",
"that",
"corresponds",
"to",
"the",
"G... | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/graphql.go#L36-L38 | train |
shurcooL/graphql | graphql.go | Mutate | func (c *Client) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}) error {
return c.do(ctx, mutationOperation, m, variables)
} | go | func (c *Client) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}) error {
return c.do(ctx, mutationOperation, m, variables)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Mutate",
"(",
"ctx",
"context",
".",
"Context",
",",
"m",
"interface",
"{",
"}",
",",
"variables",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"c",
".",
"do",
"(",
"ctx",
"... | // Mutate executes a single GraphQL mutation request,
// with a mutation derived from m, populating the response into it.
// m should be a pointer to struct that corresponds to the GraphQL schema. | [
"Mutate",
"executes",
"a",
"single",
"GraphQL",
"mutation",
"request",
"with",
"a",
"mutation",
"derived",
"from",
"m",
"populating",
"the",
"response",
"into",
"it",
".",
"m",
"should",
"be",
"a",
"pointer",
"to",
"struct",
"that",
"corresponds",
"to",
"the... | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/graphql.go#L43-L45 | train |
shurcooL/graphql | graphql.go | do | func (c *Client) do(ctx context.Context, op operationType, v interface{}, variables map[string]interface{}) error {
var query string
switch op {
case queryOperation:
query = constructQuery(v, variables)
case mutationOperation:
query = constructMutation(v, variables)
}
in := struct {
Query string ... | go | func (c *Client) do(ctx context.Context, op operationType, v interface{}, variables map[string]interface{}) error {
var query string
switch op {
case queryOperation:
query = constructQuery(v, variables)
case mutationOperation:
query = constructMutation(v, variables)
}
in := struct {
Query string ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"do",
"(",
"ctx",
"context",
".",
"Context",
",",
"op",
"operationType",
",",
"v",
"interface",
"{",
"}",
",",
"variables",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"query",
"... | // do executes a single GraphQL operation. | [
"do",
"executes",
"a",
"single",
"GraphQL",
"operation",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/graphql.go#L48-L98 | train |
shurcooL/graphql | internal/jsonutil/graphql.go | Decode | func (d *decoder) Decode(v interface{}) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr {
return fmt.Errorf("cannot decode into non-pointer %T", v)
}
d.vs = [][]reflect.Value{{rv.Elem()}}
return d.decode()
} | go | func (d *decoder) Decode(v interface{}) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr {
return fmt.Errorf("cannot decode into non-pointer %T", v)
}
d.vs = [][]reflect.Value{{rv.Elem()}}
return d.decode()
} | [
"func",
"(",
"d",
"*",
"decoder",
")",
"Decode",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"rv",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return",
"fmt... | // Decode decodes a single JSON value from d.tokenizer into v. | [
"Decode",
"decodes",
"a",
"single",
"JSON",
"value",
"from",
"d",
".",
"tokenizer",
"into",
"v",
"."
] | d48a9a75455f6af30244670bc0c9d0e38e7392b5 | https://github.com/shurcooL/graphql/blob/d48a9a75455f6af30244670bc0c9d0e38e7392b5/internal/jsonutil/graphql.go#L60-L67 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.