mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
feat(installer): use go-git to clone
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
This commit is contained in:
61
vendor/github.com/go-git/go-billy/v5/osfs/os_windows.go
generated
vendored
Normal file
61
vendor/github.com/go-git/go-billy/v5/osfs/os_windows.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// +build windows
|
||||
|
||||
package osfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
type fileInfo struct {
|
||||
os.FileInfo
|
||||
name string
|
||||
}
|
||||
|
||||
func (fi *fileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
|
||||
var (
|
||||
kernel32DLL = windows.NewLazySystemDLL("kernel32.dll")
|
||||
lockFileExProc = kernel32DLL.NewProc("LockFileEx")
|
||||
unlockFileProc = kernel32DLL.NewProc("UnlockFile")
|
||||
)
|
||||
|
||||
const (
|
||||
lockfileExclusiveLock = 0x2
|
||||
)
|
||||
|
||||
func (f *file) Lock() error {
|
||||
f.m.Lock()
|
||||
defer f.m.Unlock()
|
||||
|
||||
var overlapped windows.Overlapped
|
||||
// err is always non-nil as per sys/windows semantics.
|
||||
ret, _, err := lockFileExProc.Call(f.File.Fd(), lockfileExclusiveLock, 0, 0xFFFFFFFF, 0,
|
||||
uintptr(unsafe.Pointer(&overlapped)))
|
||||
runtime.KeepAlive(&overlapped)
|
||||
if ret == 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *file) Unlock() error {
|
||||
f.m.Lock()
|
||||
defer f.m.Unlock()
|
||||
|
||||
// err is always non-nil as per sys/windows semantics.
|
||||
ret, _, err := unlockFileProc.Call(f.File.Fd(), 0, 0, 0xFFFFFFFF, 0)
|
||||
if ret == 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func rename(from, to string) error {
|
||||
return os.Rename(from, to)
|
||||
}
|
||||
Reference in New Issue
Block a user