Commit Graph

92 Commits

Author SHA1 Message Date
John Eikenberry 7f106a3327 change fstat to not reuse request object
When fstat is called it now uses the handle to get the opened request,
pulls the filepath from that and creates a new request for the fstat
call. This eliminates the need to change the Method on the request
object and furthers the goal of eliminating post-creation mutation of
the request object to open up the possibility to eliminate or at least
reduce the use of the global request lock.
2019-01-29 14:49:22 -08:00
John Eikenberry c71cbb17d3 'open' directory on opendir packet
Just like with files, the call to the hander to create the Lister is
done when the OPENDIR packet is received. This eliminates the need for
the lock in the filelist() method and opens the path for eliminating
more locks.
2019-01-29 14:49:22 -08:00
John Eikenberry 0a96e0de8a initial test of opening 'file' on open packet
Testing feasibility of creating the reader/writer when first receiving
the Open packet instead of waiting for the Get/Put.

This work is meant to make the Request locks easier to manage and
ultimately reducing/eliminating them as much as possible.
2019-01-29 14:49:22 -08:00
Daniel Theophanes d8ec5de5ee sftp: update tests to finish and not panic on windows
Many Unix assuptions have been made when testing.
Previously running tests on windows threw a panic
part way through the tests. After these changes
many more tests pass when the fix was isolated
to the test itself, and none panic.

Some tests are skipped because they do make sense
on windows (chmod, chown), while others are skipped
just to how the test was implemented.

Lastly, some of the external executables were hard coded.
Change these to look paths in TestMain first. This is done
to better support windows, where openssh may be installed and
sftp and sftp-server may both be in the PATH.
2019-01-18 16:29:07 -08:00
John Eikenberry fe93131e0a fix example request filesystem's file renaming
also added a test for the issue

Fixes #264
2018-08-17 11:59:53 -07:00
John Eikenberry 218c0d4148 Opendir return an error status when not found
The initial Opendir packet is supposed to repond with an error status if
the directory wasn't found. It was just returning a handle without
checking, now it does a Stat on the path and only returns the handle if
the Stat is successful and it indicates it is a directory, otherwise it
returns an error.
2018-05-26 13:59:55 -07:00
John Eikenberry 66107b5f08 unused variables in tests 2018-02-15 10:28:06 -08:00
John Eikenberry b00841bcd7 create master/parent context in the server session
Create a master Context in the per-session ReqeustServer.Serve method
that is then used as the parent for all Context's created in that
server. Its cancelFunc is then always called when Serve exits. This is
in line which out the http.serve code works.

Each Request gets a child WithCancel context created in the
requestFromPacket call. This Context is still closed on request.close().
2018-02-05 14:10:05 -08:00
Allan Feid 48468dac0d request context test 2018-02-05 12:46:27 -08:00
John Eikenberry 02e35135dc test errors now set in a more uniform manner
request_test and request-server_test set mocked/fake errors differently.
This makes them use the same basic API for simplicity.
2018-01-16 14:18:45 -08:00
John Eikenberry 30b632cf56 handle errors in file creation from open packet
open packet w/ the create flag would create the file but was ignoring
any errors from that. this fixes that and adds a test for it.
2018-01-07 18:30:26 -08:00
John Eikenberry 5d6c28a24a file fetch failure check 2018-01-07 18:05:50 -08:00
John Eikenberry 937c489fca tests should just fail, not panic 2018-01-06 19:47:44 -08:00
John Eikenberry 0e667a77c5 add test for uploading empty file 2017-12-24 13:43:57 -08:00
John Eikenberry 8722020a70 simpify Request struct and Method updating
In #192 we normalized all Request use to have pointer receivers. This
simplified reasoning and allowed for a simpler Request struct. This
change completes that work by eliminating the need for the
state/stackLock pointers and also removes the need for a new Request
each packet, reducing the pressure on the GC.

The main bit is that the RequestServer.openRequests[] map now stores Request
pointers and it only creates new Requests (replacing the mapped entry) when the
Method changes. It never updates/modifies an existing Request and the packet to
Method mapping is now all in place place (requestMethod).
2017-12-23 16:34:22 -08:00
John Eikenberry 3030aca5da Fix issue with path 'cleaning' and adds tests
Fix #207

The primary issue of the resolved ticket was path cleaning code returned
the path of '/.' instead of '/'.

We also reviewed and clarified the use of filepath/path and how OS
specific paths are handled in the server code. All paths are converted
to POSIX paths as they come into the server. They are then POSIX paths
for all internal operations.
2017-12-21 12:05:53 -08:00
sandreas 653e2f1043 Merge branch 'master' into master 2017-08-13 17:00:45 +02:00
andreas 4d7bb970c4 Resolved conflict with SftpServerWorkerCount
Splitted cleanPath into cleanPacketPath and cleanPath for better handling of slashes in file paths
Added test for cleanPath func
Removed code duplication => filepath.ToSlash(filepath.Clean(...)) => cleanPath(...)
Fixed tests for runLs to match year or time
Renamed constants to fit hound rules
2017-08-13 14:00:08 +02:00
John Eikenberry 733115c415 Fixes #184; better fix for file batching
I didn't like how the initial fix for #184 required the handler author
to track the token/offset for the filelist. I came up with a way to do
it that mimic'd the FileReader handler interface using a method
something like ReaderAt except for file lists.

changed MaxFileinfoList to a var for testing and tweaking

Renaming FileInfoer interface to FileLister.
FileInfoer -> FileLister
Fileinfo -> Filelist
2017-08-10 15:36:41 -07:00
John Eikenberry d02a2715ba Fixes #184; request server file list batching
The request server needs to support batching of file list requests. To
address this the methods LsSave(string) and LsNext()string are added to
the Request object. They should work to store a token to keep your place.

The Handler should now return an EOF when the end of the directory list is
reached. If it doesn't but returns an empty list, the wrapper will send the EOF
for you.

The old behaviour of just returning 1 batch and sending the EOF is preserved if
you don't set the token (you don't use LsSave). It will return the 1 list and
EOF on the next underlying readdir call. This is to preserve backwards
compatibility and it not the recommended way to handle file lists.
2017-07-10 16:43:58 -07:00
John Eikenberry 9b982bd499 Add test to replicate fstat hang 2017-04-24 21:39:51 -07:00
John Eikenberry a3c585f638 Fix several Setstat typos in request-server
Added a test that breaks w/ old code which has typos but is fixed with
typos fixed. Also added switch-default error message that would have
helped diagnose this (should have been there already).
2017-04-24 21:36:09 -07:00
Artyom Pervukhin f581f81666 Pass actual errors from FileReader/FileWriter implementations
Fixes #163
2017-03-25 16:48:13 -07:00
John Eikenberry 81c5ef6a75 rework fileinfo.Sys() output test for windows
split out the unix specific test code
2017-03-01 19:51:32 -08:00
John Eikenberry a4eb07c029 NewRequest() now takes method as first param 2017-02-18 18:20:37 -08:00
John Eikenberry df02b6e10d make NewRequest public 2017-02-18 18:20:37 -08:00
John Eikenberry 352ba90280 use proper newRequest in test 2017-02-18 18:20:37 -08:00
John Eikenberry 016dabfa49 golint and go vet fixes 2017-02-18 18:20:37 -08:00
John Eikenberry ce4586e8a5 convert request to be pass by value
Encapsulate stateful data into sub-structures with pointer references
from the Request structure. This allows me to pass by value in most
cases to keep non-stateful (write once) data data race free and tightly
controlling access to stateful data to ease locking.
2017-02-18 18:20:37 -08:00
John Eikenberry 887fd76631 remove old code 2017-02-18 18:20:37 -08:00
John Eikenberry 4f479d7876 tests use unix domain sockets instead of io.Pipe
Needed to be able to test out of order/synchronization issues which
io.Pipe wouldn't allow. So changed server tests to use unix sockets.
2017-02-18 18:20:37 -08:00
John Eikenberry f4432147d1 fix issue with leaking requests in handle cache 2017-02-18 18:20:37 -08:00
John Eikenberry b6f2e2d29e fix testing error
Mistakenly treated Readdir return value as list (ordered) instead of map
(unordered).
2017-02-18 18:20:37 -08:00
John Eikenberry 23acc34b25 change back to using int as handle key
Was using a filename as a placeholder for something that would allow for
stateless servers but decided the amount of work wasn't worth it at this
point. So I went back to the auto-inc number as it doesn't have the size
issues (max handle length is 256).
2017-02-18 18:20:37 -08:00
John Eikenberry 9962211713 linter fixes 2017-02-18 18:20:37 -08:00
John Eikenberry 56a1ff0d31 more tests 2017-02-18 18:20:37 -08:00
John Eikenberry e9fbfdcf4d 'integration' tests using in-mem request example backend 2017-02-18 18:20:37 -08:00
John Eikenberry f2d2606fc7 Add integration tests using example backend 2017-02-18 18:20:37 -08:00
John Eikenberry a15e6f57e3 updated tests 2017-02-18 18:20:37 -08:00
John Eikenberry e74311f79c variable name fix 2017-02-18 18:20:36 -08:00
John Eikenberry 37052567c8 name fixes 2017-02-18 18:20:36 -08:00
John Eikenberry 06bf237860 reworked in branch and liked it 2017-02-18 18:20:36 -08:00