Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

create implicit directories from multipart requests #6

Merged
merged 3 commits into from
Feb 11, 2019
Merged

Conversation

Stebalien
Copy link
Member

Also, introduce a multipart walker to simplify some things.

fixes #5

@ghost ghost assigned Stebalien Feb 9, 2019
@ghost ghost added the status/in-progress In progress label Feb 9, 2019
Copy link
Member Author

@Stebalien Stebalien left a 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 {
Copy link
Member Author

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 {
Copy link
Member Author

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.

multipartfile.go Outdated Show resolved Hide resolved
}
w.consumePart()
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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 {
Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor nits

multipartfile.go Outdated Show resolved Hide resolved
}

func (it *multipartIterator) Err() error {
if it.err == io.EOF {
Copy link
Member

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

@Stebalien Stebalien merged commit 118a00e into master Feb 11, 2019
@ghost ghost removed the status/in-progress In progress label Feb 11, 2019
@Stebalien Stebalien deleted the fix/5 branch February 11, 2019 16:31
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 11, 2023
create implicit directories from multipart requests

This commit was moved from ipfs/go-ipfs-files@118a00e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle multipart files without directories
2 participants