Skip to content

Commit

Permalink
made all constants private
Browse files Browse the repository at this point in the history
  • Loading branch information
davecheney committed Nov 6, 2013
1 parent a5056a6 commit 2a93daf
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 117 deletions.
66 changes: 33 additions & 33 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Client) Close() error { return c.w.Close() }
// it already exists. If successful, methods on the returned File can be
// used for I/O; the associated file descriptor has mode O_RDWR.
func (c *Client) Create(path string) (*File, error) {
return c.open(path, SSH_FXF_READ|SSH_FXF_WRITE|SSH_FXF_CREAT|SSH_FXF_TRUNC)
return c.open(path, ssh_FXF_READ|ssh_FXF_WRITE|ssh_FXF_CREAT|ssh_FXF_TRUNC)
}

func (c *Client) sendInit() error {
Expand All @@ -66,7 +66,7 @@ func (c *Client) sendInit() error {
}
}
return sendPacket(c.w, packet{
Type: SSH_FXP_INIT,
Type: ssh_FXP_INIT,
Version: 3, // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
})
}
Expand All @@ -84,8 +84,8 @@ func (c *Client) recvVersion() error {
if err != nil {
return err
}
if typ != SSH_FXP_VERSION {
return &unexpectedPacketErr{SSH_FXP_VERSION, typ}
if typ != ssh_FXP_VERSION {
return &unexpectedPacketErr{ssh_FXP_VERSION, typ}
}
return nil
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *Client) readDir(p string) ([]os.FileInfo, error) {
}
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_READDIR,
Type: ssh_FXP_READDIR,
Id: id,
Handle: handle,
}); err != nil {
Expand All @@ -124,7 +124,7 @@ func (c *Client) readDir(p string) ([]os.FileInfo, error) {
return nil, err
}
switch typ {
case SSH_FXP_NAME:
case ssh_FXP_NAME:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIdErr{id, sid}
Expand All @@ -142,7 +142,7 @@ func (c *Client) readDir(p string) ([]os.FileInfo, error) {
attr.name = path.Base(filename)
attrs = append(attrs, attr)
}
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIdErr{id, sid}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *Client) opendir(path string) (string, error) {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_OPENDIR,
Type: ssh_FXP_OPENDIR,
Id: id,
Path: path,
}); err != nil {
Expand All @@ -184,14 +184,14 @@ func (c *Client) opendir(path string) (string, error) {
return "", err
}
switch typ {
case SSH_FXP_HANDLE:
case ssh_FXP_HANDLE:
sid, data := unmarshalUint32(data)
if sid != id {
return "", &unexpectedIdErr{id, sid}
}
handle, _ := unmarshalString(data)
return handle, nil
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return "", unmarshalStatus(id, data)
default:
return "", unimplementedPacketErr(typ)
Expand All @@ -208,7 +208,7 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_LSTAT,
Type: ssh_FXP_LSTAT,
Id: id,
Path: p,
}); err != nil {
Expand All @@ -219,15 +219,15 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) {
return nil, err
}
switch typ {
case SSH_FXP_ATTRS:
case ssh_FXP_ATTRS:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIdErr{id, sid}
}
attr, _ := unmarshalAttrs(data)
attr.name = path.Base(p)
return attr, nil
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return nil, unmarshalStatus(id, data)
default:
return nil, unimplementedPacketErr(typ)
Expand All @@ -238,7 +238,7 @@ func (c *Client) Lstat(p string) (os.FileInfo, error) {
// returned file can be used for reading; the associated file descriptor
// has mode O_RDONLY.
func (c *Client) Open(path string) (*File, error) {
return c.open(path, SSH_FXF_READ)
return c.open(path, ssh_FXF_READ)
}

func (c *Client) open(path string, pflags uint32) (*File, error) {
Expand All @@ -254,7 +254,7 @@ func (c *Client) open(path string, pflags uint32) (*File, error) {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_OPEN,
Type: ssh_FXP_OPEN,
Id: id,
Path: path,
Pflags: pflags,
Expand All @@ -266,14 +266,14 @@ func (c *Client) open(path string, pflags uint32) (*File, error) {
return nil, err
}
switch typ {
case SSH_FXP_HANDLE:
case ssh_FXP_HANDLE:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIdErr{id, sid}
}
handle, _ := unmarshalString(data)
return &File{c: c, path: path, handle: handle}, nil
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return nil, unmarshalStatus(id, data)
default:
return nil, unimplementedPacketErr(typ)
Expand All @@ -294,7 +294,7 @@ func (c *Client) readAt(handle string, offset uint64, buf []byte) (uint32, error
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_READ,
Type: ssh_FXP_READ,
Id: id,
Handle: handle,
Offset: offset,
Expand All @@ -307,15 +307,15 @@ func (c *Client) readAt(handle string, offset uint64, buf []byte) (uint32, error
return 0, err
}
switch typ {
case SSH_FXP_DATA:
case ssh_FXP_DATA:
sid, data := unmarshalUint32(data)
if sid != id {
return 0, &unexpectedIdErr{id, sid}
}
l, data := unmarshalUint32(data)
n := copy(buf, data[:l])
return uint32(n), nil
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return 0, eofOrErr(unmarshalStatus(id, data))
default:
return 0, unimplementedPacketErr(typ)
Expand All @@ -335,7 +335,7 @@ func (c *Client) close(handle string) error {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_CLOSE,
Type: ssh_FXP_CLOSE,
Id: id,
Handle: handle,
}); err != nil {
Expand All @@ -346,7 +346,7 @@ func (c *Client) close(handle string) error {
return err
}
switch typ {
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return okOrErr(unmarshalStatus(id, data))
default:
return unimplementedPacketErr(typ)
Expand All @@ -363,7 +363,7 @@ func (c *Client) fstat(handle string) (*attr, error) {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_FSTAT,
Type: ssh_FXP_FSTAT,
Id: id,
Handle: handle,
}); err != nil {
Expand All @@ -374,14 +374,14 @@ func (c *Client) fstat(handle string) (*attr, error) {
return nil, err
}
switch typ {
case SSH_FXP_ATTRS:
case ssh_FXP_ATTRS:
sid, data := unmarshalUint32(data)
if sid != id {
return nil, &unexpectedIdErr{id, sid}
}
attr, _ := unmarshalAttrs(data)
return attr, nil
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return nil, unmarshalStatus(id, data)
default:
return nil, unimplementedPacketErr(typ)
Expand All @@ -400,7 +400,7 @@ func (c *Client) Remove(path string) error {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_REMOVE,
Type: ssh_FXP_REMOVE,
Id: id,
Filename: path,
}); err != nil {
Expand All @@ -411,7 +411,7 @@ func (c *Client) Remove(path string) error {
return err
}
switch typ {
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return okOrErr(unmarshalStatus(id, data))
default:
return unimplementedPacketErr(typ)
Expand All @@ -429,7 +429,7 @@ func (c *Client) Rename(oldname, newname string) error {
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_RENAME,
Type: ssh_FXP_RENAME,
Id: id,
Oldpath: oldname,
Newpath: newname,
Expand All @@ -441,7 +441,7 @@ func (c *Client) Rename(oldname, newname string) error {
return err
}
switch typ {
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
return okOrErr(unmarshalStatus(id, data))
default:
return unimplementedPacketErr(typ)
Expand All @@ -463,7 +463,7 @@ func (c *Client) writeAt(handle string, offset uint64, buf []byte) (uint32, erro
defer c.mu.Unlock()
id := c.nextId()
if err := sendPacket(c.w, packet{
Type: SSH_FXP_WRITE,
Type: ssh_FXP_WRITE,
Id: id,
Handle: handle,
Offset: offset,
Expand All @@ -477,7 +477,7 @@ func (c *Client) writeAt(handle string, offset uint64, buf []byte) (uint32, erro
return 0, err
}
switch typ {
case SSH_FXP_STATUS:
case ssh_FXP_STATUS:
if err := okOrErr(unmarshalStatus(id, data)); err != nil {
return 0, nil
}
Expand Down Expand Up @@ -615,14 +615,14 @@ type item struct {

// okOrErr returns nil if Err.Code is SSH_FX_OK, otherwise it returns the error.
func okOrErr(err error) error {
if err, ok := err.(*StatusError); ok && err.Code == SSH_FX_OK {
if err, ok := err.(*StatusError); ok && err.Code == ssh_FX_OK {
return nil
}
return err
}

func eofOrErr(err error) error {
if err, ok := err.(*StatusError); ok && err.Code == SSH_FX_EOF {
if err, ok := err.(*StatusError); ok && err.Code == ssh_FX_EOF {
return io.EOF
}
return err
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package sftp
import "io"
import "testing"

var ok = &StatusError{Code: SSH_FX_OK}
var eof = &StatusError{Code: SSH_FX_EOF}
var fail = &StatusError{Code: SSH_FX_FAILURE}
var ok = &StatusError{Code: ssh_FX_OK}
var eof = &StatusError{Code: ssh_FX_EOF}
var fail = &StatusError{Code: ssh_FX_FAILURE}

var eofOrErrTests = []struct {
err, want error
Expand Down
6 changes: 3 additions & 3 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var sendPacketTests = []struct {
want []byte
}{
{ssh_fx_init{
Type: SSH_FXP_INIT,
Type: ssh_FXP_INIT,
Version: 3,
Extensions: []struct{ Name, Data string }{
{"[email protected]", "1"},
Expand Down Expand Up @@ -195,12 +195,12 @@ var recvPacketTests = []struct {
rest []byte
}{
{sp(ssh_fx_init{
Type: SSH_FXP_INIT,
Type: ssh_FXP_INIT,
Version: 3,
Extensions: []struct{ Name, Data string }{
{"[email protected]", "1"},
},
}), SSH_FXP_INIT, []byte{0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x18, 0x70, 0x6f, 0x73, 0x69, 0x78, 0x2d, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x0, 0x1, 0x31}},
}), ssh_FXP_INIT, []byte{0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x18, 0x70, 0x6f, 0x73, 0x69, 0x78, 0x2d, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x0, 0x1, 0x31}},
}

func TestRecvPacket(t *testing.T) {
Expand Down
Loading

0 comments on commit 2a93daf

Please sign in to comment.