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

sftp.Glob returns incorrect path of found file or dir #531

Open
alexey-sderzhikov opened this issue Nov 10, 2022 · 1 comment
Open

sftp.Glob returns incorrect path of found file or dir #531

alexey-sderzhikov opened this issue Nov 10, 2022 · 1 comment

Comments

@alexey-sderzhikov
Copy link

If we use pattern with trailing slash, like "/home/" and such object exist, than sftp.Glob duplicates object's name, and returns "/home/home". It happens because c.Lstat(pattern) finds existing object with trailing slash, but Split(pattern) doesn't split dir and object, and then Join(dir, file.Name()) joins duplicates.

func (c *Client) Glob(pattern string) (matches []string, err error) {
	if !hasMeta(pattern) {
		file, err := c.Lstat(pattern)
		if err != nil {
			return nil, nil
		}
		dir, _ := Split(pattern)
		dir = cleanGlobPath(dir)
		return []string{Join(dir, file.Name())}, nil
	}
....

I'am not sure how it should to work, but i think current logic not properly right. May i help?

@puellanivis
Copy link
Collaborator

Hm… yeah, this splitting and cleaning path code doesn’t seem to be in the original. In this specific path, it just returns []string{pattern}, nil.

Not sure what we can update by porting the current code over again. 🤔 But this at least is something we should probably fix.

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

No branches or pull requests

2 participants