From 9090b94294927bb3d8b082323e1e687ae920703a Mon Sep 17 00:00:00 2001 From: Valentin Tjoncke Date: Tue, 20 Mar 2018 23:38:26 +0100 Subject: [PATCH] Fix #5 --- helm-gcs/gcs/gcs.go | 5 +++++ helm-gcs/repo/repo.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/helm-gcs/gcs/gcs.go b/helm-gcs/gcs/gcs.go index 1ae973df..ee84b2e6 100644 --- a/helm-gcs/gcs/gcs.go +++ b/helm-gcs/gcs/gcs.go @@ -10,6 +10,8 @@ import ( "cloud.google.com/go/storage" ) +var ErrObjectNotExist = errors.New("gcs: " + storage.ErrObjectNotExist.Error()) + func NewWriter(url string) (io.WriteCloser, error) { makeError := makeErrorFunc("gcs.NewWriter") bucket, fullname, err := splitURL(url) @@ -43,6 +45,9 @@ func NewReader(url string) (io.ReadCloser, error) { o := b.Object(fullname[1:]) r, err := o.NewReader(ctx) if err != nil { + if err == storage.ErrObjectNotExist { + return nil, ErrObjectNotExist + } return nil, makeError(err) } return r, nil diff --git a/helm-gcs/repo/repo.go b/helm-gcs/repo/repo.go index 1c9d4de2..d1ae23ce 100644 --- a/helm-gcs/repo/repo.go +++ b/helm-gcs/repo/repo.go @@ -50,6 +50,17 @@ func CreateRepo(path string) error { if err != nil { return makeError(err) } + // Do not rewrite index.yaml if it already exists + _, err = gcs.NewReader(indexFileURL) + if err != nil { + if err != gcs.ErrObjectNotExist { + return makeError(err) + } + } else { + debug("repository already initialized") + return nil + } + // Create index.yaml w, err := gcs.NewWriter(indexFileURL) if err != nil { return makeError(err)