Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit b869eb1

Browse files
committed
Add norwfs version of rewritePackedRefsWhileLocked
Signed-off-by: Javi Fontan <jfontan@gmail.com>
1 parent d3e7c90 commit b869eb1

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

storage/filesystem/internal/dotgit/dotgit.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ func (d *DotGit) openAndLockPackedRefs(doCreate bool) (
458458
}
459459
}()
460460

461-
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
462465
if doCreate {
463466
openFlags |= os.O_CREATE
464467
}

storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// +build !windows
1+
// +build !windows,!norwfs
22

33
package dotgit
44

5-
import "gopkg.in/src-d/go-billy.v4"
5+
import (
6+
"os"
7+
8+
"gopkg.in/src-d/go-billy.v4"
9+
)
10+
11+
const openAndLockPackedRefsMode = os.O_RDWR
612

713
func (d *DotGit) rewritePackedRefsWhileLocked(
814
tmp billy.File, pr billy.File) error {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// +build norwfs
2+
3+
package dotgit
4+
5+
import (
6+
"io"
7+
"os"
8+
9+
"gopkg.in/src-d/go-billy.v4"
10+
)
11+
12+
const openAndLockPackedRefsMode = os.O_RDONLY
13+
14+
// Instead of renaming that can not be supported in simpler filesystems
15+
// a full copy is done.
16+
func (d *DotGit) rewritePackedRefsWhileLocked(
17+
tmp billy.File, pr billy.File) error {
18+
19+
prWrite, err := d.fs.Create(pr.Name())
20+
if err != nil {
21+
return err
22+
}
23+
24+
defer prWrite.Close()
25+
26+
_, err = tmp.Seek(0, io.SeekStart)
27+
if err != nil {
28+
return err
29+
}
30+
31+
_, err = io.Copy(prWrite, tmp)
32+
33+
return err
34+
}

storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// +build windows
1+
// +build windows,!norwfs
22

33
package dotgit
44

55
import (
66
"io"
7+
"os"
78

89
"gopkg.in/src-d/go-billy.v4"
910
)
1011

12+
const openAndLockPackedRefsMode = os.O_RDWR
13+
1114
func (d *DotGit) rewritePackedRefsWhileLocked(
1215
tmp billy.File, pr billy.File) error {
1316
// If we aren't using the bare Windows filesystem as the storage

0 commit comments

Comments
 (0)