-
Notifications
You must be signed in to change notification settings - Fork 380
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
request-server: implement Open method #377
Conversation
add an optional interface to FileWriter to allow to open a file for both writing and reading Fixes pkg#374
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think there’s much if any recommendations for change. Just musings over possible alternatives. (i.e. soft approve; design and structure are fine)
request-example.go
Outdated
if fs.mockErr != nil { | ||
return nil, fs.mockErr | ||
} | ||
_ = r.WithContext(r.Context()) // initialize context for deadlock testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary for non-testing situations?
f.contentLock.Lock() | ||
defer f.contentLock.Unlock() | ||
reader := bytes.NewReader(f.content) | ||
return reader.ReadAt(p, off) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would probably rather see an actual implementation rather than exploiting the bytes.NewReader
type, but I doubt there ends up being any difference in speed really, and this is more readable.
Why can’t the memFile
contain a bytes.Buffer
and then we could get a bunch of the functionalit— oh, huh, bytes.Buffer
doesn’t implement ReaderAt
or WriterAt
? 😬
Hi, after changing the code like this
I'm getting test failures like this one:
for some reason now in code like this
to avoid this issue? Thank you |
Improve memory handler and some test case Improve nil check for Close and TransferError interfaces
Yeah, this is a source of a lot of issues, where a |
OK, so is this PR ready to merge for you? Or should we document that the implementer should expect a null pointer? Thank you |
More preferably, the It shouldn’t be hard to copy-paste the |
Great! I wish you could review all my code! |
You say that. And then a month in, you’re just like, “but it works, right?” 😰 |
I don't think so :) |
All good! |
add an optional interface to FileWriter to allow to open a file for both
writing and reading
Fixes #374
I noticed that an
Open
method is documented but not implemented, see here. I implemented this method. The change is backward compatible and implementing the new optional Filewriter interface the request server can handle both reading and writing to the same file fixing the corruption issue reported in #374I know that we want something different for v2 and so I'll not push this change myself.
However I cannot wait until we implement v2 to fix a file corruption issue in SFTPGo, so if we don't agree to merge this change I'll maintain it in my fork until we have an alternative, thank you