Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1017)

Unified Diff: mmutex/cmd/mmutex/exclusive.go

Issue 2980603003: Flesh out the mmutex binary wrapper and test for existence of lockfile (Closed)
Patch Set: Change tempdir directory to work on Windows Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mmutex/cmd/mmutex/.gitignore ('k') | mmutex/cmd/mmutex/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mmutex/cmd/mmutex/exclusive.go
diff --git a/mmutex/cmd/mmutex/exclusive.go b/mmutex/cmd/mmutex/exclusive.go
new file mode 100644
index 0000000000000000000000000000000000000000..2c77b738170a6c1d085a8417af58cc4ea71cd378
--- /dev/null
+++ b/mmutex/cmd/mmutex/exclusive.go
@@ -0,0 +1,37 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/maruel/subcommands"
+
+ "github.com/luci/luci-go/mmutex/lib"
+)
+
+var cmdExclusive = &subcommands.Command{
+ UsageLine: "exclusive -- <command>",
+ ShortDesc: "acquires an exclusive lock before running the command",
+ CommandRun: func() subcommands.CommandRun {
+ return &cmdExclusiveRun{}
+ },
+}
+
+type cmdExclusiveRun struct {
+ subcommands.CommandRunBase
+}
+
+func (c *cmdExclusiveRun) Run(a subcommands.Application, args []string, env subcommands.Env) int {
+ // TODO(charliea): Make sure that `args` has length greater than zero.
+
+ if err := lib.AcquireExclusiveLock(lockFilePath); err != nil {
+ fmt.Fprintf(os.Stderr, "error acquiring exclusive lock: %s\n", err)
+ return 1
+ }
+
+ return 0
+}
« no previous file with comments | « mmutex/cmd/mmutex/.gitignore ('k') | mmutex/cmd/mmutex/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698