Path: blob/main/components/gitpod-cli/cmd/sync-done.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"1112"github.com/spf13/cobra"13"golang.org/x/xerrors"14)1516// doneCmd represents the done command17var syncDoneCmd = &cobra.Command{18Use: "sync-done <name>",19Short: "Notifies the corresponding gp sync-await calls that this event has happened",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)2627if _, err := os.Stat(lockFile); !os.IsNotExist(err) {28// file already exists - we're done29return nil30}3132err := os.WriteFile(lockFile, []byte("done"), 0600)33if err != nil {34return xerrors.Errorf("cannot write lock file: %w", err)35}36return nil37},38}3940func init() {41rootCmd.AddCommand(syncDoneCmd)42}434445