change readonly checks to interface type checks
diff --git a/request-packet.go b/request-packet.go
index fe76c43..c5d4792 100644
--- a/request-packet.go
+++ b/request-packet.go
@@ -32,6 +32,10 @@
isOpener()
}
+type notReadOnly interface {
+ notReadOnly()
+}
+
//// define types by adding methods
// hasPath
func (p sshFxpLstatPacket) getPath() string { return p.Path }
@@ -59,6 +63,16 @@
func (p sshFxpWritePacket) getHandle() string { return p.Handle }
func (p sshFxpReaddirPacket) getHandle() string { return p.Handle }
+// notReadOnly
+func (p sshFxpWritePacket) notReadOnly() {}
+func (p sshFxpSetstatPacket) notReadOnly() {}
+func (p sshFxpFsetstatPacket) notReadOnly() {}
+func (p sshFxpRemovePacket) notReadOnly() {}
+func (p sshFxpMkdirPacket) notReadOnly() {}
+func (p sshFxpRmdirPacket) notReadOnly() {}
+func (p sshFxpRenamePacket) notReadOnly() {}
+func (p sshFxpSymlinkPacket) notReadOnly() {}
+
// this has a handle, but is only used for close
func (p sshFxpClosePacket) getHandle() string { return p.Handle }
diff --git a/server.go b/server.go
index 3d0f4ac..99b89b1 100644
--- a/server.go
+++ b/server.go
@@ -143,40 +143,32 @@
pkt = &sshFxpReadPacket{}
case ssh_FXP_WRITE:
pkt = &sshFxpWritePacket{}
- readonly = false
case ssh_FXP_FSTAT:
pkt = &sshFxpFstatPacket{}
case ssh_FXP_SETSTAT:
pkt = &sshFxpSetstatPacket{}
- readonly = false
case ssh_FXP_FSETSTAT:
pkt = &sshFxpFsetstatPacket{}
- readonly = false
case ssh_FXP_OPENDIR:
pkt = &sshFxpOpendirPacket{}
case ssh_FXP_READDIR:
pkt = &sshFxpReaddirPacket{}
case ssh_FXP_REMOVE:
pkt = &sshFxpRemovePacket{}
- readonly = false
case ssh_FXP_MKDIR:
pkt = &sshFxpMkdirPacket{}
- readonly = false
case ssh_FXP_RMDIR:
pkt = &sshFxpRmdirPacket{}
- readonly = false
case ssh_FXP_REALPATH:
pkt = &sshFxpRealpathPacket{}
case ssh_FXP_STAT:
pkt = &sshFxpStatPacket{}
case ssh_FXP_RENAME:
pkt = &sshFxpRenamePacket{}
- readonly = false
case ssh_FXP_READLINK:
pkt = &sshFxpReadlinkPacket{}
case ssh_FXP_SYMLINK:
pkt = &sshFxpSymlinkPacket{}
- readonly = false
case ssh_FXP_EXTENDED:
pkt = &sshFxpExtendedPacket{}
default:
@@ -186,8 +178,10 @@
return err
}
- // handle FXP_OPENDIR specially
+ // readonly checks
switch pkt := pkt.(type) {
+ case notReadOnly:
+ readonly = false
case *sshFxpOpenPacket:
readonly = pkt.readonly()
case *sshFxpExtendedPacket: