aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/gcs
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-08-18 14:32:50 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-08-24 12:05:06 +0200
commit514514f61b1dec32386fca74dfe3875a277d1791 (patch)
treed8f6ef06ab971a28f447b6fbe4a9161ac61d5fe4 /pkg/gcs
parent43795179c6b57e7f671f7471e53a0bf2fdcfad0d (diff)
all: hash and ignore duplicate assets
Calculate sha256 values of assets-to-upload and don't upload them if they already exist.
Diffstat (limited to 'pkg/gcs')
-rw-r--r--pkg/gcs/gcs.go14
1 files changed, 14 insertions, 0 deletions
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/"