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

Unified Diff: mmutex/lib/flock.go

Issue 2980603003: Flesh out the mmutex binary wrapper and test for existence of lockfile (Closed)
Patch Set: 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
Index: mmutex/lib/flock.go
diff --git a/mmutex/lib/flock.go b/mmutex/lib/flock.go
new file mode 100644
index 0000000000000000000000000000000000000000..6a6a0ee9c1351629556cb1313ec756c96dfb447a
--- /dev/null
+++ b/mmutex/lib/flock.go
@@ -0,0 +1,20 @@
+// 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 lib
+
+import (
+ "fmt"
+ "os"
+)
+
+// TODO(charliea): Add timeout parameter to this function.
+func AcquireExclusiveLock(path string) error {
+ if _, err := os.Stat(path); os.IsNotExist(err) {
iannucci 2017/07/11 20:52:15 tbh, I would probably not stat, I'd just bail on E
charliea (OOO until 10-5) 2017/07/11 23:26:16 The actual lock implementation accepts an already-
+ return fmt.Errorf("cannot acquire lock on %s because file does not exist", path)
+ }
+
+ // TODO(charliea): Acquire the actual lock.
iannucci 2017/07/11 20:52:14 can also `panic("implement lock acquisition")`
charliea (OOO until 10-5) 2017/07/11 23:26:16 Done.
+ return nil
+}

Powered by Google App Engine
This is Rietveld 408576698