-
Notifications
You must be signed in to change notification settings - Fork 23
Conversation
3dbdce0
to
ae81210
Compare
Note that ipfs-cluster and certain other projects depend on these libraries too. I don't think it's hard to upgrade and I think it's a good argument for this change, but we should make sure we're all aware when a breaking change is coming up. |
ae81210
to
dc3989c
Compare
Can you give examples of this (link to other issues, etc fine). Also why is How does this change effect |
https://github.com/ipfs/go-ipfs/blob/master/core/coreapi/unixfs_test.go#L144
This makes things more complicated than they need to be, without any clear benefit (
Nothing at all changes, including http api, see ipfs/kubo#5661. Filestore works because reader files can carry their real filesystem path (note that this path doesn't have to be related in any way to paths this interface operates) To give some more context - my motivation is that currently you can't just take a file from |
|
If I was doing this I would create a new type for iterating over directory entries I would call it iter := dir.Entries()
for !iter.EOF() {
name, file, ok := iter.Next()
if !ok {panic("should not happen")}
...
} The last value could be omitted, but it is useful to return it and in most cases it can just be ignored. This is just one way, there are other ways to do it, for example we could instead have a iter := dir.Entries()
for !iter.EOF() {
name := iter.Name()
file := iter.File()
...
iter.Adv()
} In all cases I would work to remove the |
The type File interface {
io.Reader
io.Closer
io.Seeker
Size() (int64, error)
}
type Directory {
io.Closer
Size() (int64, error)
NextFile() (DirEntry, error)
}
type DirEntry {
Name() string
File() File // returns nil if not a File
Dir() Directory // returns nil if not a Directory
} |
(tl;dr I aimed for the simplest usable design) I considered the iterator syntax when initially doing this, I decided to keep
So, the thing I don't like about this is that we force file consumers to cast constantly. On the other hand we get nice switch syntax: func(f files.File) {
switch fi := f.(type) {
case files.Symlink: // above regular as symlinks can be interpreted as a regular file too
[symlink logic]
case files.Directory:
[dir logic]
case files.Regular:
[simple file]
default:
[potentially some special file or something]
}
I don't want to constrain the interface to in-order only walking, but I could implement a helper for this which could make things like MultipartFile less hacky
Adding write capabilities shouldn't be too hard (even less so if we go the multiple-types route), I'd leave this for later and focus on getting the read part right. |
(I'll try refactoring this into multiple types) |
So, my idea was more to define a smaller interface for in-order walking. |
@Stebalien can you show what you mean in code? I'm not quite sure I have the same idea. What I can think of as an optional extension for |
e82cb25
to
83d7cdb
Compare
I've refactored this into sepearate types + the directory iterator, @Stebalien @kevina can you have a look before I start updating this in other places? |
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 haven't looked much at the rest of the code but I really like the new interfaces.
Well, "like" given the fact that go doesn't have affine types.
13c2487
to
2936a34
Compare
Note: there are some failures in ipfs-cluster/ipfs-cluster#613 (thanks again for submitting @magik6k ) and upon first inspection it is not 100% clear to me that they belong to cluster's end. Until we figure out if some breakage was introduced here or a relevant behavior change I suggest we hold this off. |
1335344
to
bc7a700
Compare
@hsanjuan should be all fixed, can you have a look? |
Ok, happy if this moves forward with regards to the problems mentioned in Cluster and which have been resolved. I cannot immediately give a review for this code but I can put it on my queue and maybe get to it in the next few days. |
Done. I've split the helper functions into few more type-safe functions, It's not as bad as I thought it would be on the api consumer side. |
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.
That should now be a complete review.
d141a7f
to
7fea77e
Compare
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.
The code is looking pretty good now but I'd still like to nail the documentation. This is a pretty important interface.
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.
Actually, I'm not going to block this on documentation. @magik6k feel free to touch up the documentation as much as you want and then merge this. We can revisit it in another PR but there's no reason to block the refactor on that.
Refactor filename - file relation This commit was moved from ipfs/go-ipfs-files@86b2cb8
Now that we use this in CoreAPI, it would be nice if the file interface wasn't painful to use. Main focus for this PR is moving the responsibility of declaring file name/path from files to directories.
Currently files carry carry path/name which starts at some arbitrary root and need to be aware what path they are in, which is more than annoying.
With this PR files are just Readers with a bunch of utility functions, and directories are responsible for saying what it's children are called (like in real file systems).
TODO:
Close
for bort files and dirs