This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
storage/filesystem/internal/dotgit Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 22
33package dotgit
44
5- import "gopkg.in/src-d/go-git.v4/plumbing"
5+ import (
6+ "fmt"
67
7- // There are some filesystems tha don't support opening files in RDWD mode.
8+ "gopkg.in/src-d/go-git.v4/plumbing"
9+ )
10+
11+ // There are some filesystems that don't support opening files in RDWD mode.
812// In these filesystems the standard SetRef function can not be used as i
913// reads the reference file to check that it's not modified before updating it.
1014//
1115// This version of the function writes the reference without extra checks
1216// making it compatible with these simple filesystems. This is usually not
1317// a problem as they should be accessed by only one process at a time.
1418func (d * DotGit ) setRef (fileName , content string , old * plumbing.Reference ) error {
19+ _ , err := d .fs .Stat (fileName )
20+ if err == nil && old != nil {
21+ fRead , err := d .fs .Open (fileName )
22+ if err != nil {
23+ return err
24+ }
25+
26+ ref , err := d .readReferenceFrom (fRead , old .Name ().String ())
27+ fRead .Close ()
28+
29+ if err != nil {
30+ return err
31+ }
32+
33+ if ref .Hash () != old .Hash () {
34+ return fmt .Errorf ("reference has changed concurrently" )
35+ }
36+ }
37+
1538 f , err := d .fs .Create (fileName )
1639 if err != nil {
1740 return err
You can’t perform that action at this time.
0 commit comments