Commit Graph

103 Commits

Author SHA1 Message Date
Cassondra Foesch bb06e29d17 get integration tests passing on WSL for GOOS=windows 2022-01-31 21:12:49 +00:00
Gleb Teterin dad23755af Fix missing io.EOF when concurency is disabled #489 2022-01-20 07:55:17 +13:00
greatroar 1fffa629f6 Add File.ReadFrom test with a Sized Reader
This tests ReadFrom's determining concurrency from the estimated input
size. go test -cover -integration, before:

coverage: 77.3% of statements

After:

coverage: 79.2% of statements
2021-12-24 08:42:10 +01:00
Cassondra Foesch f525d180b6
Merge pull request #456 from pkg/refactor/regroup-and-lint
Regroup marshling/unmarshaling and lint
2021-08-20 22:59:08 +00:00
codesoap 997499abb6 Fix a few misspells 2021-08-20 21:00:33 +02:00
Cassondra Foesch 1b6d816185 remove min function 2021-08-11 13:29:16 +00:00
Cassondra Foesch 96bf4d30dc
Merge pull request #422 from greatroar/cleanup
Minor cleanup
2021-03-21 13:12:55 +00:00
greatroar 95591b2015 Remove unnecessary TeeReader from readHash 2021-03-20 11:43:59 +01:00
Cassondra Foesch d26c4bc2a7
Merge pull request #421 from pkg/benchmarks-and-errors
Improve benchmarks and errors
2021-03-20 03:11:49 +00:00
Cassondra Foesch addaabd30b give the bytes.Buffer a preallocated slice to use for less variance 2021-03-17 20:18:50 +00:00
greatroar 846e27dc7f Implement File.Chmod via setfstat 2021-03-17 18:50:51 +01:00
Cassondra Foesch b22b9e472e remove writeToBuffer, the bytes.Buffer.Grow I saw in the memprofile was elsewhere 2021-03-17 13:18:17 +00:00
Cassondra Foesch 39e1161d12 address my own code review comments 2021-03-17 12:05:00 +00:00
Cassondra Foesch f1e28f8a88 Improve benchmarks and errors 2021-03-17 11:03:51 +00:00
Cassondra Foesch 460ad57385
Merge pull request #416 from greatroar/match-cleanup
Clean up matching/globbing code
2021-03-16 01:20:24 +00:00
greatroar d3695c2587 Fix Glob handling of backslashes
\m\a\t\c\h\.\g\o would be interpreted as a literal path, because the
backslash was missing in the check.
2021-03-15 18:11:02 +01:00
greatroar 2573693ec5 Support os.Mode{Setuid,Setgid,Sticky} in Chmod
Previously, these bits were ignored by Chmod, which sent the numerical
value of the mode argument as-is to the server. As a result, callers had
to supply POSIX values for setuid, setgid and sticky to Chmod.

The new version supports both the POSIX values and the Go values.

Also added a note to the docs to clarify that the umask is not
subtracted from the mode, and why that is. The only portable way to get
the umask is to set it, then reset it, but that's racy. On Linux, we
could parse /proc/self/status, but that doesn't work portably and will
fail where /proc is not available (some Docker containers, notably).
2021-03-12 16:17:56 +01:00
Nicola Murino e1e59da6e3 add readAtSequential: used if concurrent reads are disabled ...
... and the requested buffer is bigger than maxPacket
2021-03-05 15:04:17 +01:00
Nicola Murino 5f2c008b8e add an option to disable concurrent reads
Fixs #345
2021-02-23 19:13:26 +01:00
Cassondra Foesch 29c556e3a6 WriteTo benchmarks 2021-02-22 12:04:43 +00:00
Cassondra Foesch 59de31242c more robust tests, fix typos 2021-02-22 12:04:43 +00:00
Cassondra Foesch d178e4730e avoid panic if double call to Close 2021-02-22 12:04:43 +00:00
Cassondra Foesch 27538347e7 defers in a for loop don't execute until the end of the function 2021-02-22 12:04:43 +00:00
Cassondra Foesch 4f2503d286 using sftp-server these tests hang without this close 2021-02-22 12:04:43 +00:00
Nicola Murino f5fd2fb058 normalise permission denied error as file not found error 2020-12-08 12:14:21 +01:00
greatroar 06d60c4c06 Test disconnect handling in open files 2020-11-04 10:17:06 +01:00
greatroar 7f43671909 Rename remaining temps in client integration test 2020-10-31 14:34:16 +01:00
greatroar 360f7af3e6 {assert,require}.Nil(t, err) => NoError, NotNil => Error 2020-10-29 16:02:25 +01:00
greatroar 4c4fa330bb First check for uid 0, then lookup daemon's uid 2020-10-29 16:00:27 +01:00
greatroar 7c0f7eea70 Comment out path matching test that breaks on Go tip 2020-10-29 14:47:28 +01:00
greatroar eb20cfe9bc Clean up temporary files in client tests 2020-10-23 22:14:32 +02:00
greatroar 83e0eb8f30 Fix typos in clients tests 2020-10-23 22:14:05 +02:00
greatroar d352a1d176 Add Client.Sync method
This uses the fsync@openssh.com extension:
https://github.com/openssh/openssh-portable/blob/master/PROTOCOL, §3.6.
2020-10-23 13:09:54 +02:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
Tommie Gannert 2c24eaad1c Implement the hardlink@openssh.com extension.
Both client and server. This is documented in

  https://github.com/openssh/openssh-portable/blob/master/PROTOCOL

Draft 7 of SFTP added support for SSH_FXP_LINK which supports both
symlinks and hardlinks, but unfortunately OpenSSH doesn't support
that:

  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-07#section-7.7

Adding support for this as an option would be a nice extension to
this.
2019-08-25 20:16:37 -07: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
Urjit Singh Bhatia 831654e4aa Client.MkdirAll - mimic os.MkdirAll code for consistency & perf 2018-04-25 08:13:19 -07:00
Urjit Singh Bhatia a03704e892 Add mkdirall implementation 2018-04-24 23:58:10 -07:00
John Eikenberry 49488377fa fix client deadlock on server death during writes
Fixes #234

Similar to #181 (which was about read methods), the client deadlocks on
server drop on write methods (Write/ReadFrom). This is another case of
broadcastErr() and dispatchRequest() deadlocking.

The fix is to bump up the channel used to communicate about inflight
packets to maxConcurrentRequests+1 (+1 is new). It seems that it can
have the full set of packets going and hit the error (triggering
broadcastErr) yet it still tries to call dispatchRequest again. More
details in that ticket.

I'm also bumping up the chan buffer in the read methods to keep them
consistent. I can't reproduce the problem, but it looks like it should
have it. So it might just be a much harder race to trigger.

This also includes 2 tests which reprocuded the issue for ReadFrom and
Write.
2018-03-15 13:53:30 -07:00
John Eikenberry 161bbaf9a8 a few code simplifications
ran gosimple over the code and made suggested adjustments
2018-02-15 11:17:19 -08:00
John Eikenberry 9fa3832aa2 update seek constants 2018-02-15 10:27:33 -08:00
Iain Wade 9b6cdb8fab Add PosixRename method which uses the posix-rename@openssh.com extension
to support actual rename() operations rather than the link() call
effectively mandated by the sftp v3/draft-2 requirement that targets
not be overwritten.
2017-09-05 04:46:03 -07:00
John Eikenberry 4f3e725e88 Fixes #188; eliminates duplicated core code
match contained lots of cut-n-pasted code from filepath/match.go in the
core libraries. Particularly Match() and Join() were changed in such a
way that made them functionally equivalent to the versions in
path/match.go. This removes the duplicate code and just calls the path
versions.
2017-07-20 15:28:11 -07:00
John Eikenberry 8e0c78ade5 fix spelling error in comment 2017-07-03 13:14:51 -07:00
John Eikenberry 737aa1dc61 Fixes #181: client deadlock on server death
The client was deadlocking if you killed the server when a file transfer
was occuring. The problem occured when you had many requests sent and
were waiting on responses when the server dies. The errors for all those
pending requests get sent along the response channel which is also used
for the errors reported by the new requests being made. The new request
channel send is in the same loop as the channel reading, so when it
blocked due to all other errors filling the channel it deadlocked the
program.

There were 2 possible fixes, changing the new request error channel
usage to be in a separate goroutine to keep it from blocking the loop or
to increase the size of the buffer to handle all the errors. This
implements the latter.

Included is a test that reproduces the problem most of the time. Due to
the required timing of the issue, it was impossible to reproduce 100% of
the time.
2017-06-29 11:27:52 -07:00
John Eikenberry ca043ca452 add ReadFrom benchmark 2017-06-25 19:21:59 -07:00
John Eikenberry 8f9da7f630 quick fix to get benchmarks running
benchmarks were broken due to double closing of a channel in some tests.
I just commented out the problematic closes which probably means it's
leaking in the tests but at least they run now. Should probably try to
figure out what happened here at some point.
2017-03-14 12:27:51 -07:00
Catalin Tanasescu 43d52d4faa ported Glob method from filepath - https://golang.org/pkg/path/filepath/#Glob 2017-02-18 14:26:32 -08:00
John Eikenberry cfb6d5c5b2 Add tests for deadlocks in Read and WriteTo
Just like issues reported in #145
2017-02-13 17:20:40 -08:00
John Eikenberry 14f0a222dd Tests to replicate deadlock bug in Write/ReadFrom
github issue #145

A deadlock will occur in cases when using client.Write or client.ReadFrom,
it has 2 network issues in a row, and it is starting a new loop to send
more concurrent packets.
2017-02-13 00:32:33 -08:00