aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skqp/upload_model
blob: cd9554c67120d0300efc56c9c2301c6508f9d102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /bin/sh

# Copyright 2018 Google Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

BASE_DIR='platform_tools/android/apps/skqp/src/main/assets'
PATH_LIST='gmkb skqp'
BUCKET=skia-skqp-assets

EXTANT="$(mktemp "${TMPDIR:-/tmp}/extant.XXXXXXXXXX")"
gsutil ls gs://$BUCKET/ | sed "s|^gs://$BUCKET/||"  > "$EXTANT"

upload() {
    MD5=$(md5sum < "$1" | head -c 32)
    if ! grep -q "$MD5" "$EXTANT"; then
        URL="gs://${BUCKET}/$MD5"
        gsutil cp "$1" "$URL" > /dev/null 2>&1 &
    fi
    echo $MD5
}

size() { gsutil du -s gs://$BUCKET | awk '{print $1}'; }

cd "$(dirname "$0")/../../$BASE_DIR"

rm -f files.checksum

FILES="$(mktemp "${TMPDIR:-/tmp}/files.XXXXXXXXXX")"

: > "$FILES"

COUNT=$(find $PATH_LIST -type f | wc -l)
INDEX=1
SHARD_COUNT=32

SIZE=$(size)
find $PATH_LIST -type f | sort | while IFS= read -r FILENAME; do
    printf '\r %d / %d   ' "$INDEX" "$COUNT"
    if ! [ -f "$FILENAME" ]; then
        echo error [${FILENAME}] >&2;
        exit 1;
    fi
    case "$FILENAME" in *\;*) echo bad filename: $FILENAME >&2; exit 1;; esac
    MD5=$(upload "$FILENAME")
    printf '%s;%s\n' "$MD5" "$FILENAME" >> "$FILES"

    if [ $(($INDEX % $SHARD_COUNT)) = 0 ]; then
        wait
    fi
    INDEX=$(( $INDEX + 1))
done
printf '\rdone          \n'
upload "$FILES" > files.checksum
wait

D=$(( $(size) - $SIZE ))
printf 'Added %d bytes to %s, %d%%\n' $D $BUCKET $(( $D * 100 / $SIZE ))

rm "$EXTANT"