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)
| 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. |
| 61 | func (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 | } |