Skip to content
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

Support container.Put without knowing the item size #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion local/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *container) Put(name string, r io.Reader, size int64, metadata map[strin
if err != nil {
return nil, err
}
if n != size {
if size >= 0 && n != size {
return nil, errors.New("bad size")
}
return item, nil
Expand Down
16 changes: 10 additions & 6 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func All(t *testing.T, kind string, config stow.Config) {
// Tests metadata retrieval on PUTs.
item1Content := "item one"
item1Name := "a_first/the item"
item1, skip1 := putItem(is, c1, item1Name, item1Content, md1)
item1, skip1 := putItem(is, c1, item1Name, item1Content, md1, true)
is.OK(item1)
if !skip1 {
is.NoErr(checkMetadata(t, is, item1, md1))
}

item2, _ := putItem(is, c1, "a_second/the item", "item two", nil)
item2, _ := putItem(is, c1, "a_second/the item", "item two", nil, true)
is.OK(item2)

item3, _ := putItem(is, c1, "the_third/the item", "item three", nil)
item3, _ := putItem(is, c1, "the_third/the item", "item three", nil, false)
is.OK(item3)

defer func() {
Expand Down Expand Up @@ -309,13 +309,17 @@ func createContainer(is is.I, location stow.Location, name string) stow.Containe
return container
}

func putItem(is is.I, container stow.Container, name, content string, md map[string]interface{}) (stow.Item, bool) {
func putItem(is is.I, container stow.Container, name, content string, md map[string]interface{}, knownSize bool) (stow.Item, bool) {
var skipAssertion bool // skip metadata assertion
item, err := container.Put(name, strings.NewReader(content), int64(len(content)), md)
size := int64(len(content))
if !knownSize {
size = int64(-1)
}
item, err := container.Put(name, strings.NewReader(content), size, md)

// Metadata retrieval isn't supported
if stow.IsNotSupported(err) {
item, err = container.Put(name, strings.NewReader(content), int64(len(content)), nil)
item, err = container.Put(name, strings.NewReader(content), size, nil)
skipAssertion = true
}

Expand Down