From 514514f61b1dec32386fca74dfe3875a277d1791 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 18 Aug 2022 14:32:50 +0000 Subject: all: hash and ignore duplicate assets Calculate sha256 values of assets-to-upload and don't upload them if they already exist. --- pkg/gcs/gcs.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pkg/gcs') diff --git a/pkg/gcs/gcs.go b/pkg/gcs/gcs.go index 2776927d4..e0ccd39c5 100644 --- a/pkg/gcs/gcs.go +++ b/pkg/gcs/gcs.go @@ -143,6 +143,20 @@ func (client *Client) DeleteFile(gcsFile string) error { return err } +func (client *Client) FileExists(gcsFile string) (bool, error) { + bucket, filename, err := split(gcsFile) + if err != nil { + return false, err + } + _, err = client.client.Bucket(bucket).Object(filename).Attrs(client.ctx) + if err == storage.ErrObjectNotExist { + return false, nil + } else if err != nil { + return false, err + } + return true, nil +} + // Where things get published. const ( PublicPrefix = "https://storage.googleapis.com/" -- cgit mrf-deployment