From b869eb17b72e80be8e554864db6b6efa6ecb5ebf Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 22 Dec 2017 17:34:20 +0100 Subject: Add norwfs version of rewritePackedRefsWhileLocked Signed-off-by: Javi Fontan --- storage/filesystem/internal/dotgit/dotgit.go | 5 +++- .../dotgit/dotgit_rewrite_packed_refs_nix.go | 10 +++++-- .../dotgit/dotgit_rewrite_packed_refs_norwfs.go | 34 ++++++++++++++++++++++ .../dotgit/dotgit_rewrite_packed_refs_windows.go | 5 +++- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_norwfs.go (limited to 'storage/filesystem/internal') 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 -- cgit