Path: blob/main/components/gitpod-cli/cmd/sync-await.go
2498 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"crypto/sha1"8"encoding/hex"9"fmt"10"os"11"time"1213"github.com/spf13/cobra"14)1516// awaitSyncCmd represents the awaitSync command17var awaitSyncCmd = &cobra.Command{18Use: "sync-await <name>",19Short: "Awaits an event triggered using gp sync-done",20Args: cobra.ExactArgs(1),21RunE: func(cmd *cobra.Command, args []string) error {22h := sha1.New()23h.Write([]byte(args[0]))24id := hex.EncodeToString(h.Sum(nil))25lockFile := fmt.Sprintf("/tmp/gp-%s.done", id)2627ticker := time.NewTicker(1 * time.Second)28done := make(chan bool)29go func() {30for {31if _, err := os.Stat(lockFile); !os.IsNotExist(err) {32break33}3435<-ticker.C36}3738ticker.Stop()39done <- true40}()4142select {43case <-cmd.Context().Done():44case <-done:45fmt.Printf("%s done\n", args[0])46}4748return nil49},50}5152func init() {53rootCmd.AddCommand(awaitSyncCmd)54}555657