MCPcopy
hub / github.com/go-git/go-git / setRefNorwfs

Method setRefNorwfs

storage/filesystem/dotgit/dotgit_setref.go:61–90  ·  view source on GitHub ↗

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 it reads the reference file to check that it's not modified before updating it. This version of the function writes the reference without extra checks makin

(fileName, content string, old *plumbing.Reference)

Source from the content-addressed store, hash-verified

59// making it compatible with these simple filesystems. This is usually not
60// a problem as they should be accessed by only one process at a time.
61func (d *DotGit) setRefNorwfs(fileName, content string, old *plumbing.Reference) error {
62 _, err := d.fs.Stat(fileName)
63 if err == nil && old != nil {
64 fRead, err := d.fs.Open(fileName)
65 if err != nil {
66 return err
67 }
68
69 ref, err := d.readReferenceFrom(fRead, old.Name().String())
70 fRead.Close()
71
72 if err != nil {
73 return err
74 }
75
76 if ref.Hash() != old.Hash() {
77 return fmt.Errorf("reference has changed concurrently")
78 }
79 }
80
81 f, err := d.fs.Create(fileName)
82 if err != nil {
83 return err
84 }
85
86 defer f.Close()
87
88 _, err = f.Write([]byte(content))
89 return err
90}

Callers 1

setRefMethod · 0.95

Calls 9

readReferenceFromMethod · 0.95
StatMethod · 0.65
StringMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
HashMethod · 0.65
OpenMethod · 0.45
CreateMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected