From e96c5b5f3995de6833f5357ec98777e8ba919888 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 30 Aug 2017 15:54:49 +0100 Subject: [PATCH] hubic: don't check the container exists before creating it This fixes being able to create containers for Hubic. --- hubic/hubic.go | 2 +- swift/swift.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hubic/hubic.go b/hubic/hubic.go index 0e92455a0..dd3f4f99a 100644 --- a/hubic/hubic.go +++ b/hubic/hubic.go @@ -165,7 +165,7 @@ func NewFs(name, root string) (fs.Fs, error) { } // Make inner swift Fs from the connection - swiftFs, err := swift.NewFsWithConnection(name, root, c) + swiftFs, err := swift.NewFsWithConnection(name, root, c, true) if err != nil && err != fs.ErrorIsFile { return nil, err } diff --git a/swift/swift.go b/swift/swift.go index c71975e77..cdec9f85d 100644 --- a/swift/swift.go +++ b/swift/swift.go @@ -121,6 +121,7 @@ type Fs struct { containerOKMu sync.Mutex // mutex to protect container OK containerOK bool // true if we have created the container segmentsContainer string // container to store the segments (if any) in + noCheckContainer bool // don't check the container before creating it } // Object describes a swift object @@ -215,8 +216,11 @@ func swiftConnection(name string) (*swift.Connection, error) { } // NewFsWithConnection contstructs an Fs from the path, container:path -// and authenticated connection -func NewFsWithConnection(name, root string, c *swift.Connection) (fs.Fs, error) { +// and authenticated connection. +// +// if noCheckContainer is set then the Fs won't check the container +// exists before creating it. +func NewFsWithConnection(name, root string, c *swift.Connection, noCheckContainer bool) (fs.Fs, error) { container, directory, err := parsePath(root) if err != nil { return nil, err @@ -227,6 +231,7 @@ func NewFsWithConnection(name, root string, c *swift.Connection) (fs.Fs, error) container: container, segmentsContainer: container + "_segments", root: directory, + noCheckContainer: noCheckContainer, } f.features = (&fs.Features{ ReadMimeType: true, @@ -263,7 +268,7 @@ func NewFs(name, root string) (fs.Fs, error) { if err != nil { return nil, err } - return NewFsWithConnection(name, root, c) + return NewFsWithConnection(name, root, c, false) } // Return an Object from a path @@ -480,7 +485,10 @@ func (f *Fs) Mkdir(dir string) error { return nil } // Check to see if container exists first - _, _, err := f.c.Container(f.container) + var err error = swift.ContainerNotFound + if !f.noCheckContainer { + _, _, err = f.c.Container(f.container) + } if err == swift.ContainerNotFound { err = f.c.ContainerCreate(f.container, nil) }