@@ -323,36 +323,9 @@ func (d *DotGit) SetRef(r, old *plumbing.Reference) error {
323
323
content = fmt .Sprintln (r .Hash ().String ())
324
324
}
325
325
326
- // If we are not checking an old ref, just truncate the file.
327
- mode := os .O_RDWR | os .O_CREATE
328
- if old == nil {
329
- mode |= os .O_TRUNC
330
- }
331
-
332
- f , err := d .fs .OpenFile (r .Name ().String (), mode , 0666 )
333
- if err != nil {
334
- return err
335
- }
336
-
337
- defer ioutil .CheckClose (f , & err )
338
-
339
- // Lock is unlocked by the deferred Close above. This is because Unlock
340
- // does not imply a fsync and thus there would be a race between
341
- // Unlock+Close and other concurrent writers. Adding Sync to go-billy
342
- // could work, but this is better (and avoids superfluous syncs).
343
- err = f .Lock ()
344
- if err != nil {
345
- return err
346
- }
347
-
348
- // this is a no-op to call even when old is nil.
349
- err = d .checkReferenceAndTruncate (f , old )
350
- if err != nil {
351
- return err
352
- }
326
+ fileName := r .Name ().String ()
353
327
354
- _ , err = f .Write ([]byte (content ))
355
- return err
328
+ return d .setRef (fileName , content , old )
356
329
}
357
330
358
331
// Refs scans the git directory collecting references, which it returns.
@@ -485,7 +458,10 @@ func (d *DotGit) openAndLockPackedRefs(doCreate bool) (
485
458
}
486
459
}()
487
460
488
- openFlags := os .O_RDWR
461
+ // File mode is retrieved from a constant defined in the target specific
462
+ // files (dotgit_rewrite_packed_refs_*). Some modes are not available
463
+ // in all filesystems.
464
+ openFlags := openAndLockPackedRefsMode
489
465
if doCreate {
490
466
openFlags |= os .O_CREATE
491
467
}
0 commit comments