fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.26k stars 1.4k forks source link

func (f *fileDialog) setLocation(dir fyne.URI) error { does not work with non "file" repository #5207

Open brucealthompson opened 1 month ago

brucealthompson commented 1 month ago

Checklist

Describe the bug

There is "file" respository specific code in fyne.io\fyne\v2@v2.5.2\dialog\file.go: func (f *fileDialog) setLocation(dir fyne.URI) error {}

Here is the code where the issue is: newDir := storage.NewFileURI(buildDir) isDir, err := storage.CanList(newDir) if err != nil { return err }

Notice that setLocation takes a fyne URL as input (dir fyne.URI). If the fyne URL has a scheme of "file" then the call to storage.NewFileURI(buildDir) above will work. If the fyne URL in the parameter (dir fyne.URI) has a scheme different than "file". Then the call to storage.NewFileURI(buildDir) will return a URL with the "file" scheme instead of the scheme passed in dir fyne.URI.

I found this bug when trying to use the respository "httpfile" that I created.

How to reproduce

Create a non "file" repository. Create a new file dialog pointing to the non "file" repository Try traversing directories in the non "file" repository. The UI will stop once storage.NewFileURI(buildDir) resturns an invalid "file" URI.

Screenshots

No response

Example code

Create a new file dialog using the following code:

locationURI, err := storage.ParseURI("httpfile:///")
    if err != nil {
        return err
    }
    listableURI, err := storage.ListerForURI(locationURI)
    if err != nil {
        return err
    }
    folderdialog := dialog.NewFolderOpen(callback, parent)
    folderdialog.SetLocation(listableURI)
    folderdialog.Show()

Fyne version

2.5.2

Go compiler version

1.23.1

Operating system and version

Windows 11

Additional Information

No response

brucealthompson commented 1 month ago

Here's the fix:

 **newURL := dir.Scheme() + "://" + filepath.ToSlash(buildDir)
        newDir, err := storage.ParseURI(newURL)
        if err != nil {
            return err
        }**
        isDir, err := storage.CanList(newDir)
        if err != nil {
            return err
        }
brucealthompson commented 1 month ago

Pull request created: https://github.com/fyne-io/fyne/pull/5215

andydotxyz commented 1 month ago

As noted on the PR I don't think that is a fix - it looks like a workaround for your repository. In a situation where the URI represents something other than another file system (like a media library or an LDAP directory) this will still create very strange results and/or not work at all.