Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete method to sftp client #772

Merged
merged 1 commit into from
Nov 20, 2023
Merged

Conversation

Diogenesoftoronto
Copy link
Contributor

No description provided.

Copy link
Collaborator

@djjuhasz djjuhasz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Diogenesoftoronto overall this looks good, but I've requested a few changes.

internal/sftp/client.go Outdated Show resolved Hide resolved
internal/sftp/client.go Outdated Show resolved Hide resolved
internal/sftp/goclient.go Outdated Show resolved Hide resolved
internal/sftp/goclient.go Outdated Show resolved Hide resolved
internal/sftp/goclient.go Outdated Show resolved Hide resolved
internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
// closed when the delete is complete or cancelled.
//
// Delete is not thread safe.
func (c *GoClient) Delete(ctx context.Context, dest string) (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm realizing that we can't use ctx for cancellation, but I suggest to leave it in case we find a way to use it in the future. I think that both the ssh and sftp packages that we're using predate the context package so they were not designed to accept a context. One alternative that we could consider is to pass the context to the dial method and create our own dialer with net.DialContext, but I don't see it as a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rclone is doing it here, but it looks complicated because they support edge cases like proxy settings, etc. It also looks like the ssh package is going to have a DialContext sometime soon: https://go-review.googlesource.com/c/crypto/+/504735.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, interesting @sevein. I thought ctx would be unnecessary for delete because the actual sftp.Remove() operation should be very fast, AFAIK. But now I realize that dialing the server could take a while if there are communications issues, so I agree ctx is still worthwhile for future use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I have considered is doing something similar to what contextio does, or wwe can do @sevein suggestion. I think including context on the actual client struct makes sense and then we can context is equal for operations that normally do not have a context like in contextio

Copy link
Collaborator

@djjuhasz djjuhasz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Diogenesoftoronto a few more change requests.

internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
internal/sftp/goclient_test.go Outdated Show resolved Hide resolved
internal/sftp/goclient.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@djjuhasz djjuhasz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Don't forget to squash the commits.

@Diogenesoftoronto Diogenesoftoronto force-pushed the dev/sftp-delete-method branch 2 times, most recently from 073d050 to 8c976d2 Compare November 20, 2023 18:13
- add second arg to want error for second method
- split tests, handle non-existent or insufficient perms
- improve comment, and remove results
- generate mocks for delete
@Diogenesoftoronto Diogenesoftoronto merged commit 7460ed5 into main Nov 20, 2023
10 of 11 checks passed
@Diogenesoftoronto Diogenesoftoronto deleted the dev/sftp-delete-method branch November 20, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants