aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/dotgit
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2017-12-22 17:34:20 +0100
committerJavi Fontan <jfontan@gmail.com>2017-12-22 17:35:17 +0100
commitb869eb17b72e80be8e554864db6b6efa6ecb5ebf (patch)
tree42bb0b1af03f2c270891810ca34776a138270dc2 /storage/filesystem/internal/dotgit
parentd3e7c9060a14ac579f899fd01c936319132cbc97 (diff)
downloadgo-git-b869eb17b72e80be8e554864db6b6efa6ecb5ebf.tar.gz
Add norwfs version of rewritePackedRefsWhileLocked
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'storage/filesystem/internal/dotgit')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go5
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go10
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_norwfs.go34
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go5
4 files changed, 50 insertions, 4 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index 643a5d6..fac7aec 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -458,7 +458,10 @@ func (d *DotGit) openAndLockPackedRefs(doCreate bool) (
}
}()
- openFlags := os.O_RDWR
+ // File mode is retrieved from a constant defined in the target specific
+ // files (dotgit_rewrite_packed_refs_*). Some modes are not available
+ // in all filesystems.
+ openFlags := openAndLockPackedRefsMode
if doCreate {
openFlags |= os.O_CREATE
}
diff --git a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go
index af96196..c760793 100644
--- a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go
+++ b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go
@@ -1,8 +1,14 @@
-// +build !windows
+// +build !windows,!norwfs
package dotgit
-import "gopkg.in/src-d/go-billy.v4"
+import (
+ "os"
+
+ "gopkg.in/src-d/go-billy.v4"
+)
+
+const openAndLockPackedRefsMode = os.O_RDWR
func (d *DotGit) rewritePackedRefsWhileLocked(
tmp billy.File, pr billy.File) error {
diff --git a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_norwfs.go b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_norwfs.go
new file mode 100644
index 0000000..6e43b42
--- /dev/null
+++ b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_norwfs.go
@@ -0,0 +1,34 @@
+// +build norwfs
+
+package dotgit
+
+import (
+ "io"
+ "os"
+
+ "gopkg.in/src-d/go-billy.v4"
+)
+
+const openAndLockPackedRefsMode = os.O_RDONLY
+
+// Instead of renaming that can not be supported in simpler filesystems
+// a full copy is done.
+func (d *DotGit) rewritePackedRefsWhileLocked(
+ tmp billy.File, pr billy.File) error {
+
+ prWrite, err := d.fs.Create(pr.Name())
+ if err != nil {
+ return err
+ }
+
+ defer prWrite.Close()
+
+ _, err = tmp.Seek(0, io.SeekStart)
+ if err != nil {
+ return err
+ }
+
+ _, err = io.Copy(prWrite, tmp)
+
+ return err
+}
diff --git a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go
index bcdb93e..897d2c9 100644
--- a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go
+++ b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_windows.go
@@ -1,13 +1,16 @@
-// +build windows
+// +build windows,!norwfs
package dotgit
import (
"io"
+ "os"
"gopkg.in/src-d/go-billy.v4"
)
+const openAndLockPackedRefsMode = os.O_RDWR
+
func (d *DotGit) rewritePackedRefsWhileLocked(
tmp billy.File, pr billy.File) error {
// If we aren't using the bare Windows filesystem as the storage