Skip to content

Conversation

@sandreas
Copy link
Contributor

On windows systems the directory separator is a backslash (). This leads to misbehavior of the library in some cases. I tried to fix this issues without changing to much code.

According to RFC https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02, SFTP always uses slashes.

Other improvements:

  • added elementary unit-test for runLs (server.go)
  • changed stub version of "runLs" to provide an as valid as possible longname attribute (i tried to follow the windows 10 ubuntu layer ls command, which is an improvement, because widely used open source sftp client FileZilla can now be used connecting windows sftp servers)

server_test.go Outdated

const (
TYPE_DIRECTORY = "d"
TYPE_FILE = "[^d]"

Choose a reason for hiding this comment

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

don't use ALL_CAPS in Go names; use CamelCase

server_test.go Outdated
)

const (
TYPE_DIRECTORY = "d"

Choose a reason for hiding this comment

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

don't use ALL_CAPS in Go names; use CamelCase

} // all paths are absolute

cleaned_path := filepath.Clean(path)
cleaned_path := filepath.ToSlash(filepath.Clean(path))

Choose a reason for hiding this comment

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

don't use underscores in Go names; var cleaned_path should be cleanedPath

Copy link
Member

Choose a reason for hiding this comment

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

don't create a new variable, overwrite path so that the unclean version cannot be used by mistake.

@eikenb
Copy link
Member

eikenb commented Aug 13, 2017

Reviewing...

if !filepath.IsAbs(path) {
path = "/" + path
// prevent double slash (e.g. on windows, / paths are not absolute)
path = "/" + strings.TrimPrefix(path, "/")
Copy link
Member

Choose a reason for hiding this comment

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

filepath.Clean may be more appropriate here

} // all paths are absolute

cleaned_path := filepath.Clean(path)
cleaned_path := filepath.ToSlash(filepath.Clean(path))
Copy link
Member

Choose a reason for hiding this comment

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

don't create a new variable, overwrite path so that the unclean version cannot be used by mistake.

request.go Outdated
// NewRequest creates a new Request object.
func NewRequest(method, path string) Request {
request := Request{Method: method, Filepath: filepath.Clean(path)}
request := Request{Method: method, Filepath: filepath.ToSlash(filepath.Clean(path))}
Copy link
Member

Choose a reason for hiding this comment

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

This filepath.ToSlash(filepath.Clean() logic appears too many times.

Please break it into a helper function and add a unit test for all the appropriate cases; "/", "//", "\", "/a/", "\a/", etc

request.go Outdated
func NewRequest(method, path string) Request {
request := Request{Method: method, Filepath: filepath.Clean(path)}
request := Request{Method: method, Filepath: filepath.ToSlash(filepath.Clean(path))}
request.packets = make(chan packet_data, sftpServerWorkerCount)
Copy link
Member

Choose a reason for hiding this comment

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

This is the line that is in conflict below. The conflict is due to my making sftpServerWorkerCount public (capitalizing it). It is easy to resolve.


// mod time (len 12, e.g. Aug 9 19:46)
got = result[43:55]
layout := "Jan 2 15:04"
Copy link
Member

Choose a reason for hiding this comment

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

Date stat display flips over to the year at a certain point (6 months I think). The LICENSE file on my system did this and this test failed. The format can be "Jan 2 15:04" or "Jan 2 2006" depending on this. One fix would be to check both and only error if neither parses.

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

const (
sftpServerWorkerCount = 8
SftpServerWorkerCount = 8

Choose a reason for hiding this comment

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

exported const SftpServerWorkerCount should have comment (or a comment on this block) or be unexported


const (
sftpServerWorkerCount = 8
SftpServerWorkerCount = 8

Choose a reason for hiding this comment

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

exported const SftpServerWorkerCount should have comment (or a comment on this block) or be unexported

@sandreas
Copy link
Contributor Author

All mentioned things should be fixed now...

@eikenb
Copy link
Member

eikenb commented Aug 13, 2017

@davecheney What do you think? There are a few extraneous things but they are all improvements, so I'm OK with them. I'm ready to merge it unless you have more you'd like to see.

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.

4 participants