Skip to content

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

Closed

Description

@alexey-sderzhikov

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?

Activity

  1. puellanivis commented on Nov 10, 2022

    @puellanivis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions