aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2017-12-22 17:16:59 +0100
committerJavi Fontan <jfontan@gmail.com>2017-12-22 17:16:59 +0100
commitd3e7c9060a14ac579f899fd01c936319132cbc97 (patch)
tree342d8ecb4599d592bac2b8dfeedd62c6ccec9d1c /storage
parentdae8c68b753943058aa397947e5c318d8db8cab8 (diff)
downloadgo-git-d3e7c9060a14ac579f899fd01c936319132cbc97.tar.gz
Check reference also in norwfs SetRef
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_setref_norwfs.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit_setref_norwfs.go b/storage/filesystem/internal/dotgit/dotgit_setref_norwfs.go
index 8b1e662..5695bd3 100644
--- a/storage/filesystem/internal/dotgit/dotgit_setref_norwfs.go
+++ b/storage/filesystem/internal/dotgit/dotgit_setref_norwfs.go
@@ -2,9 +2,13 @@
package dotgit
-import "gopkg.in/src-d/go-git.v4/plumbing"
+import (
+ "fmt"
-// There are some filesystems tha don't support opening files in RDWD mode.
+ "gopkg.in/src-d/go-git.v4/plumbing"
+)
+
+// There are some filesystems that don't support opening files in RDWD mode.
// In these filesystems the standard SetRef function can not be used as i
// reads the reference file to check that it's not modified before updating it.
//
@@ -12,6 +16,25 @@ import "gopkg.in/src-d/go-git.v4/plumbing"
// making it compatible with these simple filesystems. This is usually not
// a problem as they should be accessed by only one process at a time.
func (d *DotGit) setRef(fileName, content string, old *plumbing.Reference) error {
+ _, err := d.fs.Stat(fileName)
+ if err == nil && old != nil {
+ fRead, err := d.fs.Open(fileName)
+ if err != nil {
+ return err
+ }
+
+ ref, err := d.readReferenceFrom(fRead, old.Name().String())
+ fRead.Close()
+
+ if err != nil {
+ return err
+ }
+
+ if ref.Hash() != old.Hash() {
+ return fmt.Errorf("reference has changed concurrently")
+ }
+ }
+
f, err := d.fs.Create(fileName)
if err != nil {
return err