5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
dotgit_rewrite_packed_refs.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
package dotgit
import (
"io"
"os"
"runtime"
"gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
func (d *DotGit) openAndLockPackedRefsMode() int {
if billy.CapabilityCheck(d.fs, billy.ReadAndWriteCapability) {
return os.O_RDWR
}
return os.O_RDONLY
}
func (d *DotGit) rewritePackedRefsWhileLocked(
tmp billy.File, pr billy.File) error {
// Try plain rename. If we aren't using the bare Windows filesystem as the
// storage layer, we might be able to get away with a rename over a locked
// file.
err := d.fs.Rename(tmp.Name(), pr.Name())
if err == nil {
return nil
}
// If we are in a filesystem that does not support rename (e.g. sivafs)
// a full copy is done.
if err == billy.ErrNotSupported {
return d.copyNewFile(tmp, pr)
}
if runtime.GOOS != "windows" {
return err
}
// Otherwise, Windows doesn't let us rename over a locked file, so
// we have to do a straight copy. Unfortunately this could result
// in a partially-written file if the process fails before the
// copy completes.
return d.copyToExistingFile(tmp, pr)
}
func (d *DotGit) copyToExistingFile(tmp, pr billy.File) error {
_, err := pr.Seek(0, io.SeekStart)
if err != nil {
return err
}
err = pr.Truncate(0)
if err != nil {
return err
}
_, err = tmp.Seek(0, io.SeekStart)
if err != nil {
return err
}
_, err = io.Copy(pr, tmp)
return err
}
func (d *DotGit) copyNewFile(tmp billy.File, pr billy.File) (err error) {
prWrite, err := d.fs.Create(pr.Name())
if err != nil {
return err
}
defer ioutil.CheckClose(prWrite, &err)
_, err = tmp.Seek(0, io.SeekStart)
if err != nil {
return err
}
_, err = io.Copy(prWrite, tmp)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.7.0

搜索帮助