@@ -60,33 +60,19 @@ func (rs *RequestServer) nextRequest(r *Request) string {
60
60
return handle
61
61
}
62
62
63
- // Returns Request from openRequests, bool is false if it is missing
64
- // If the method is different, save/return a new Request w/ that Method.
63
+ // Returns Request from openRequests, bool is false if it is missing.
65
64
//
66
65
// The Requests in openRequests work essentially as open file descriptors that
67
66
// you can do different things with. What you are doing with it are denoted by
68
- // the first packet of that type (read/write/etc). We create a new Request when
69
- // it changes to set the request.Method attribute in a thread safe way.
70
- func (rs * RequestServer ) getRequest (handle , method string ) (* Request , bool ) {
67
+ // the first packet of that type (read/write/etc).
68
+ func (rs * RequestServer ) getRequest (handle string ) (* Request , bool ) {
71
69
rs .openRequestLock .RLock ()
70
+ defer rs .openRequestLock .RUnlock ()
72
71
r , ok := rs .openRequests [handle ]
73
- rs .openRequestLock .RUnlock ()
74
- if ! ok || r .Method == method {
75
- return r , ok
76
- }
77
- // if we make it here we need to replace the request
78
- rs .openRequestLock .Lock ()
79
- defer rs .openRequestLock .Unlock ()
80
- r , ok = rs .openRequests [handle ]
81
- if ! ok || r .Method == method { // re-check needed b/c lock race
82
- return r , ok
83
- }
84
- r = r .copy ()
85
- r .Method = method
86
- rs .openRequests [handle ] = r
87
72
return r , ok
88
73
}
89
74
75
+ // Close the Request and clear from openRequests map
90
76
func (rs * RequestServer ) closeRequest (handle string ) error {
91
77
rs .openRequestLock .Lock ()
92
78
defer rs .openRequestLock .Unlock ()
@@ -179,9 +165,18 @@ func (rs *RequestServer) packetWorker(
179
165
request := requestFromPacket (ctx , pkt )
180
166
rs .nextRequest (request )
181
167
rpkt = request .open (rs .Handlers , pkt )
168
+ case * sshFxpFstatPacket :
169
+ handle := pkt .getHandle ()
170
+ request , ok := rs .getRequest (handle )
171
+ if ! ok {
172
+ rpkt = statusFromError (pkt , syscall .EBADF )
173
+ } else {
174
+ request = NewRequest ("Stat" , request .Filepath )
175
+ rpkt = request .call (rs .Handlers , pkt )
176
+ }
182
177
case hasHandle :
183
178
handle := pkt .getHandle ()
184
- request , ok := rs .getRequest (handle , requestMethod ( pkt ) )
179
+ request , ok := rs .getRequest (handle )
185
180
if ! ok {
186
181
rpkt = statusFromError (pkt , syscall .EBADF )
187
182
} else {
@@ -201,12 +196,6 @@ func (rs *RequestServer) packetWorker(
201
196
return nil
202
197
}
203
198
204
- // True is responsePacket is an OK status packet
205
- func statusOk (rpkt responsePacket ) bool {
206
- p , ok := rpkt .(sshFxpStatusPacket )
207
- return ok && p .StatusError .Code == ssh_FX_OK
208
- }
209
-
210
199
// clean and return name packet for file
211
200
func cleanPacketPath (pkt * sshFxpRealpathPacket ) responsePacket {
212
201
path := cleanPath (pkt .getPath ())
0 commit comments