-
Notifications
You must be signed in to change notification settings - Fork 23
create implicit directories from multipart requests #6
Conversation
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 ended up touching a lot of code for a small fix. Thoughts? Objections? Better fix?
@@ -22,94 +21,111 @@ const ( | |||
contentTypeHeader = "Content-Type" | |||
) | |||
|
|||
var ErrPartOutsideParent = errors.New("file outside parent dir") | |||
var ErrPartInChildTree = errors.New("file in child tree") | |||
type multipartDirectory struct { |
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.
Renamed as we only use this for directories.
part *multipart.Part | ||
reader *peekReader | ||
mediatype string | ||
type multipartWalker struct { |
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.
Replaced peakReader
with this so we don't have to keep putting the parts back.
} | ||
w.consumePart() |
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.
Maybe we should pass the part into this function? instead of getting it from the walker?
reader: part, | ||
abspath: part.Header.Get("abspath"), | ||
}, nil | ||
} | ||
|
||
var err error | ||
f.mediatype, _, err = mime.ParseMediaType(contentType) | ||
mediatype, _, err := mime.ParseMediaType(contentType) |
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'm throwing this away as we aren't using it. We can add it back later if we change our minds.
filename = escaped | ||
} // if there is a unescape error, just treat the name as unescaped | ||
|
||
return path.Clean("/" + filename) |
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 ensures filenames area always of the same form (makes it easier to work with them).
} | ||
|
||
func (it *multipartIterator) Err() error { | ||
if it.err == io.EOF { |
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'm using this as a "done" signal. Probably not necessary but I'm paranoid.
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.
A short comment would be nice
Also, introduce a multipart walker to simplify some things. fixes #5
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.
Few minor nits
} | ||
|
||
func (it *multipartIterator) Err() error { | ||
if it.err == io.EOF { |
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.
A short comment would be nice
Co-Authored-By: Stebalien <steven@stebalien.com>
create implicit directories from multipart requests This commit was moved from ipfs/go-ipfs-files@118a00e
Also, introduce a multipart walker to simplify some things.
fixes #5