diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-30 11:36:50 -0800 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-30 14:14:12 -0800 |
commit | d53264806f0d5ddef259f45f4490a19398a102ba (patch) | |
tree | 24b4c7ee75bb84cb45e9fc63d21542e056c72f0d /storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go | |
parent | 5a6cc4e0996d1dd6c66d46ced92dee26c3121628 (diff) | |
download | go-git-d53264806f0d5ddef259f45f4490a19398a102ba.tar.gz |
dotgit: rewrite packed-refs while holding lock
Windows file system doesn't let us rename over a file while holding
that file's lock, so use rewrite as a last resort. It could result in
a partially-written file, if there's a failure at the wrong time.
Diffstat (limited to 'storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go new file mode 100644 index 0000000..af96196 --- /dev/null +++ b/storage/filesystem/internal/dotgit/dotgit_rewrite_packed_refs_nix.go @@ -0,0 +1,11 @@ +// +build !windows + +package dotgit + +import "gopkg.in/src-d/go-billy.v4" + +func (d *DotGit) rewritePackedRefsWhileLocked( + tmp billy.File, pr billy.File) error { + // On non-Windows platforms, we can have atomic rename. + return d.fs.Rename(tmp.Name(), pr.Name()) +} |