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
ListableURI interface & Initial Implementation thereof #1233
Conversation
Would like commentary from @andydotxyz One thing I wonder -- why did you make I also think we could do better naming for I am lukewarm on having I would definitely like commentary from people who work with mobile. I really only have UNIX-ey local filesystems as a point of reference, so I may be missing details that someone with more experience in that area would have. These are the thoughts that come to mind to me after this first initial sketch. |
A good start thanks. I agree that Writable may not be right for inclusion - we don’t know what type of operation will be performed and on some systems you only know if it worked by attempting... I agree the Child naming could be tidied - but also I wonder - does CreateChild even make sense? Some types of resource don’t get created ahead of writing, so all we need to do is support creating a name of a relative URI then writing could create it (as NewFileFromURI should do). So maybe RelativeURI or NewChildURI to mirror the package NewURI? Which leaves the possibility that ListableURIs need to be created in this way perhaps? |
I think embedding URI was intended a list to return plain URIs or new lists, whereas URIReadCloser and URIWriteCloser are handling driver level input/output. Does that help? |
Thinking about it we might need something like |
Just pushed up a new sketch based on what we've discussed recently. This tries to crate a clear distinction between a URI as a reference to an abstract resource that presumably exists, and a new concept which I've dubbed I think maybe rather than in The user could also define their own URI handler to support things beyond the purview of the platform. Maybe we want some kind of shortcut like RFC @andydotxyz |
I don't really understand what |
The thought with it being a public API is so that downstream developers can define their own URI providers. Someone may want to handle URIs specific to their application or use case. I think it would be best to have that exposed for people that want it. It would also implement our storage providers. |
I can see that as a desired outcome - but with |
It seemed to me like a list-able URI is a type of realization of a URI, much like a readable or writable URI. I thought bundling all the stuff relating to realizing URIs into one interface would make sense. In principle, I could simply implement the necessary bits to do list-able URIs, and table the handler thing for some future point in time, which is probably better for keeping the size of this PR down, though I do think it's an idea work revisiting in the future. |
That all makese sense - but I'm not sure that ListableURI is a realization of URI in the same way that scp:// would be. |
It seems realization-ey to me. Retrieving a directory listing almost always implies a read operation of some kind. |
I guess by "realization" I thought you meant the re-hydration we disccussed. Looking more I think we don't have the same design in mind - perhaps this might help understand the differences:
On the face of it both work, but I'm not sure that having to go via a handler is the cleanest API - which is why I wondered if it could be an internal API (or at least not exposed on the happy path). Another consideration could be can we shorten the APIs and make more available through URI(), for example storage.NewURI(...).Open() (URIReadCloser, error)
storage.NewURI(...).List() ([]URI, error) But this is just thinking out loud. |
As discussed in fyne-io#1233 and elsewhere, this isn't really relevant to the listable URI stuff. It might be worth revisiting later.
I've added a working prototype of the list-able URI interface, and removed the URI handler bits that aren't needed. How do we feel about this? I put it in the GLFW driver, since this feels like something that would be platform specific. Maybe we want some kind of standardized interface for I've also added a basic test. Maybe this needs to be expanded a little. RFC (@andydotxyz ) Edit: also, this does not preclude later adding helper methods in |
Looks pretty solid. I guess To move to ListableURI in dialog package we probably don't need the storage API, but if we want to have |
For now, the mobile driver just returns a not implemented error. I have also copied the implementation from glfw/file.go into testdriver.go. Perhaps the underlying implementation should move to some separate, common location? Like internal/urihandlers/?
I think this is ready for review. I decided to adopt the I can't figure out from the CI logs why Travis is failing, the tests and linter pass on my end. |
Ahh, I think Travis was failing due to |
As discussed in today's (2020-08-21) meeting, we explicitly error with a unique error type if the caller tries to find the parent of the root of a URI.
I have addressed the issues mentioned in today's meeting, this should be good to go. Also, in case it wasn't obvious, I want to make it really clear that this is a potentially breaking change, in that the |
test/testfile.go
Outdated
// lazily copied over from the glfw driver, should be good enough for testing | ||
// purposes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be revisited? We probably don't need a full copy of an implementation for testing, and could probably get by with a simple type that saves its parameters and returns predetermined results, both of which can be asserted against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with this. Copying implementation into tests is a bit of a smell - as you're not really testing that code but potentially copying bugs into the test code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quite like this API, thanks - but there are some fixes to be done to the testing (and potentially windows file URI parse...)
test/testfile.go
Outdated
// lazily copied over from the glfw driver, should be good enough for testing | ||
// purposes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with this. Copying implementation into tests is a bit of a smell - as you're not really testing that code but potentially copying bugs into the test code
As discussed in #fyne-contributors, storage.Parent() is no longer a pointer receiver to avoid breaking backwards compatibility with existing code. Parent() is no longer a member of the URI interface. In 2.0, we should consider moving it to be part of the URI interface.
I only copied it over so that the interface would be satisfied. I don't know that the code in How would you suggest that I address this @andydotxyz ? I think the code would end up looking very similar anyway, as the operations being implemented aren't exactly complex. In principle, it would be nice to have a whole system for mocking the filesystem during testing, but I feel like that's a separate concern from what this PR addresses. |
I guess it's not a big deal. However the error messages are wrong as they have hard coded file names in that should not really copy over. if uri.Scheme() != "file" {
return nil, fmt.Errorf("unsupported URL protocol")
} from the other file checks above? |
I updated the error messages, I agree those shouldn't have been copied over. Do we want to do something else for |
I think it’s ok for now, let’s get it landed, tested and iterated. In my last comment I meant to write “I guess it’s not a big deal” updated now, apologies! |
Because the test file driver only had ListerForURI() so it would satisfy the driver interface, but this code was not actually used, it has been removed and replaced with a stub that returns an error message, similar to the mobile driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Charles!
Description:
Relevant to #1108, this PR addresses the need to create a cross-platform "listable" URI, so that filesystem directories and other analogous things can be represented in a portable fashion.
Checklist:
Where applicable: