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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: add raw paths #497

Closed
wants to merge 1 commit into from
Closed

request: add raw paths #497

wants to merge 1 commit into from

Conversation

drakkan
Copy link
Collaborator

@drakkan drakkan commented Feb 24, 2022

This allows to clean the paths externally to the library and allows to handle a start directory for example.

Another option is to add a start directory option to the request server and build the relative path using this directory as base instead of /. I would prefer to handle paths myself outside the library but I'm open to discussions. I can also live without this feature 馃槃

@drakkan drakkan marked this pull request as draft February 24, 2022 08:50
@puellanivis
Copy link
Collaborator

So, my principal concern here is avoiding another Attr []byte field issue, where we鈥檙e not keeping a decoded value, we鈥檙e keeping the raw unparsed binary data. 馃槵 That caused a headache when I went in and did the marshal/unmarshal work, and made my first aborted pass on getting it rolled out. But I don鈥檛 think there鈥檚 any concern of that here.

I鈥檓 not opposed to this idea, but one thing, is maybe we could take the chance to reformat the struct. Right now, it鈥檚 all clumped together, no paragraphs showing the grouping of fields, and both the RawTarget and the purposed RawFilepath have their comment on the line above them, rather than on the same line to the right, like the other fields do. This causes a break of the formatting flow.

There are already unexported fields, so no one could be using the implicit field building of the struct except us, so even reordering fields won鈥檛 break anyone鈥檚 code. Then we can put the four paths together, Flags and Attrs together, and maybe handle should be at the top?

And we can shorten this up pretty tight: func (r *Request) copy() *Request { r2 := *r ; r2.state = r.state.copy(); return &r2 } ?

@drakkan
Copy link
Collaborator Author

drakkan commented Feb 24, 2022

Thanks, do you mean reordering the struct like this?

// Request contains the data and state for the incoming service request.
type Request struct {
	handle string

	// Get, Put, Setstat, Stat, Rename, Remove
	// Rmdir, Mkdir, List, Readlink, Link, Symlink
	Method string

	RawFilepath string // raw file path as sent by the SFTP client
	Filepath    string // POSIX absolute path, "/" is used as base if RawFilepath is relative
	RawTarget   string // raw target path for rename and sym-links as sent by the SFTP client
	Target      string // POSIX absolute path for renames and sym-links, "/" is used as base if RawTarget is relative

	Flags uint32
	Attrs []byte // convert to sub-struct

	// reader/writer/readdir from handlers
	state

	// context lasts duration of request
	ctx       context.Context
	cancelCtx context.CancelFunc
}

@drakkan
Copy link
Collaborator Author

drakkan commented Feb 25, 2022

So, my principal concern here is avoiding another Attr []byte field issue, where we鈥檙e not keeping a decoded value, we鈥檙e keeping the raw unparsed binary data. grimacing That caused a headache when I went in and did the marshal/unmarshal work, and made my first aborted pass on getting it rolled out. But I don鈥檛 think there鈥檚 any concern of that here.

I鈥檓 not opposed to this idea, but one thing, is maybe we could take the chance to reformat the struct. Right now, it鈥檚 all clumped together, no paragraphs showing the grouping of fields, and both the RawTarget and the purposed RawFilepath have their comment on the line above them, rather than on the same line to the right, like the other fields do. This causes a break of the formatting flow.

There are already unexported fields, so no one could be using the implicit field building of the struct except us, so even reordering fields won鈥檛 break anyone鈥檚 code. Then we can put the four paths together, Flags and Attrs together, and maybe handle should be at the top?

And we can shorten this up pretty tight: func (r *Request) copy() *Request { r2 := *r ; r2.state = r.state.copy(); return &r2 } ?

r2 := *r

will produce the warning assignment copies lock value to r2, we could ignore the warning since in the next statement we do r2.state = r.state.copy(). I'm not sure

@puellanivis
Copy link
Collaborator

will produce the warning assignment copies lock value to r2

Ah yes. OK, that鈥檚 why we were doing it that way. OK then, let鈥檚 ignore that improvement. Ideally, if we鈥檙e reimplementing, we would be able to avoid using any locks, the same as http.Request.

@drakkan
Copy link
Collaborator Author

drakkan commented Feb 26, 2022

will produce the warning assignment copies lock value to r2

Ah yes. OK, that鈥檚 why we were doing it that way. OK then, let鈥檚 ignore that improvement. Ideally, if we鈥檙e reimplementing, we would be able to avoid using any locks, the same as http.Request.

The lock seems only used to protect the state in close method that could happen concurrently with other requests. It is a read/write lock and in the most of the cases the lock should not be held for write (if my quick look at the code is correct) so it should not be performance critical.

I marked this PR as draft because I wanted to hear your opinion on the approach used and wanted to test the implementation of the start directory in a separate sftpgo branch. I'm not sure I have enough time this weekend to do that. So my priority, for now is to test this patch in a real implementation. If it works as expected we can discuss about other library improvements 馃槃

@drakkan
Copy link
Collaborator Author

drakkan commented Mar 2, 2022

After real testing I changed my mind and I would prefer to merge #498

@drakkan drakkan closed this Mar 2, 2022
@drakkan drakkan deleted the rawpaths branch July 15, 2022 10:23
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.

None yet

2 participants