-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
coreapi unixfs: remove Cat, use sessions #5574
Conversation
core/corehttp/gateway_handler.go
Outdated
@@ -270,7 +269,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr | |||
} else { | |||
name = getFilename(urlPath) | |||
} | |||
i.serveFile(w, r, name, modtime, dr) | |||
i.serveFile(w, r, name, modtime, dr.(io.ReadSeeker)) |
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 am cautious of forced casts.
Is there a reason for not returning it with Seeker interface by default? |
b595b1c
to
21b1717
Compare
21b1717
to
221fffd
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.
LGTM, one non-blocking comment listen.
At the same time, I do not feel I have enough context to evaluate this code completely, and I would defer to someone with more expertise
if err != nil { | ||
return nil, 0, err | ||
} | ||
offset = 0 | ||
|
||
size := uint64(read.Size() - uint64(count)) | ||
fsize, err = file.Size() |
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.
minor nit pick but why are you recalculating fsize again here when you appear to have set w/ same value on line 147
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.
This is just a getter under the hood - https://github.com/ipfs/go-unixfs/blob/master/io/pbdagreader.go#L163
@Stebalien do you think we should test this on a gateway first or can this just be merged? |
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
2546567
to
a4cb060
Compare
|
||
// Cat returns a reader for the file | ||
// TODO: Remove in favour of Get (if we use Get on a file we still have reader directly, so..) | ||
Cat(context.Context, Path) (Reader, error) |
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.
We can probably get away with this but we'll need to be smart about whether we optimize for bandwidth or latency. That is, when calling Cat
, we clearly care about reading the file in-order (latency to next byte). When calling Get
, we're indicating we just want the entire file (maximize throughput overall).
We can still do this even if we remove the Cat
function. However, we'll probably need to add some kind of option (or some method on the UnixfsFile
interface).
We can handle this later, it's just something to keep in mind.
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.
Good point, I'd say this is easy enough to handle later
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.
No real objections other than we need to add a bit of documentation.
core/coreapi/path.go
Outdated
@@ -73,3 +74,8 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac | |||
|
|||
return coreiface.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil | |||
} | |||
|
|||
func (api *CoreAPI) getSession(ctx context.Context) *CoreAPI { |
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.
Let's add some documentation here. Specifically, we need to at least explain that the returned API has a read-only DAG.
core/corehttp/gateway_handler.go
Outdated
case coreiface.ErrIsDir: | ||
dir = true | ||
switch { | ||
case err == nil: |
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.
Why change this? If we're going to go with something like this, a simple if err == nil { ... } else { ... }
would probably be cleaner.
core/corehttp/gateway_handler.go
Outdated
case err == nil: | ||
dir = dr.IsDirectory() | ||
if !dir { | ||
defer dr.Close() |
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... shouldn't we be closing this regardless? (I have no idea, this just looks weird).
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.
So technically for go-ipfs-files.File
, in it's current form, Close
should be only called for non-directories: https://github.com/ipfs/go-ipfs-files/blob/master/file.go#L18-L20
I'm working on refactoring files, making close valid for all files is one of the goals, but I wouldn't want to have this PR blocked on that refactor
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.
SGTM.
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
646c88e
to
519c67a
Compare
coreapi unixfs: remove Cat, use sessions This commit was moved from ipfs/kubo@c4974d2
No description provided.