Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/sync-done.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"crypto/sha1"
9
"encoding/hex"
10
"fmt"
11
"os"
12
13
"github.com/spf13/cobra"
14
"golang.org/x/xerrors"
15
)
16
17
// doneCmd represents the done command
18
var syncDoneCmd = &cobra.Command{
19
Use: "sync-done <name>",
20
Short: "Notifies the corresponding gp sync-await calls that this event has happened",
21
Args: cobra.ExactArgs(1),
22
RunE: func(cmd *cobra.Command, args []string) error {
23
h := sha1.New()
24
h.Write([]byte(args[0]))
25
id := hex.EncodeToString(h.Sum(nil))
26
lockFile := fmt.Sprintf("/tmp/gp-%s.done", id)
27
28
if _, err := os.Stat(lockFile); !os.IsNotExist(err) {
29
// file already exists - we're done
30
return nil
31
}
32
33
err := os.WriteFile(lockFile, []byte("done"), 0600)
34
if err != nil {
35
return xerrors.Errorf("cannot write lock file: %w", err)
36
}
37
return nil
38
},
39
}
40
41
func init() {
42
rootCmd.AddCommand(syncDoneCmd)
43
}
44
45