Skip to content

Commit

Permalink
Merge pull request #1447 from jinroh/swift-thumbnails-prefixed
Browse files Browse the repository at this point in the history
Fix missing prefix for thumbnail swift container
  • Loading branch information
jinroh committed Jun 29, 2018
2 parents 168c50a + 1c868bb commit 6cab7bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (i *Instance) ThumbsFS() vfs.Thumbser {
return vfsafero.NewThumbsFs(baseFS)
case config.SchemeSwift:
if i.SwiftCluster > 0 {
return vfsswift.NewThumbsFsV2(config.GetSwiftConnection(), i.Domain)
return vfsswift.NewThumbsFsV2(config.GetSwiftConnection(), i)
}
return vfsswift.NewThumbsFs(config.GetSwiftConnection(), i.Domain)
default:
Expand Down
13 changes: 10 additions & 3 deletions pkg/vfs/vfsswift/thumbs_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"time"

"github.com/cozy/cozy-stack/pkg/prefixer"
"github.com/cozy/cozy-stack/pkg/vfs"
"github.com/cozy/swift"
)
Expand All @@ -18,8 +19,8 @@ var unixEpochZero = time.Time{}
//
// This version stores the thumbnails in the same container as the main data
// container.
func NewThumbsFsV2(c *swift.Connection, domain string) vfs.Thumbser {
return &thumbsV2{c: c, container: swiftV2ContainerPrefixData + domain}
func NewThumbsFsV2(c *swift.Connection, db prefixer.Prefixer) vfs.Thumbser {
return &thumbsV2{c: c, container: swiftV2ContainerPrefixData + db.DBPrefix()}
}

type thumbsV2 struct {
Expand Down Expand Up @@ -58,7 +59,13 @@ func (t *thumbsV2) CreateThumb(img *vfs.FileDoc, format string) (vfs.ThumbFiler,
obj, err := t.c.ObjectCreate(t.container, name, false, "", img.Mime,
objMeta.ObjectHeaders())
if err != nil {
return nil, err
if _, _, errc := t.c.Container(t.container); errc == swift.ContainerNotFound {
if errc = t.c.ContainerCreate(t.container, nil); errc != nil {
return nil, err
}
} else {
return nil, err
}
}
th := &thumb{
WriteCloser: obj,
Expand Down

0 comments on commit 6cab7bc

Please sign in to comment.