mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Migrate to go-git/go-git v5.0.0 (#10735)
This commit is contained in:
		
							
								
								
									
										139
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,139 @@ | ||||
| // Package osfs provides a billy filesystem for the OS. | ||||
| package osfs // import "github.com/go-git/go-billy/v5/osfs" | ||||
|  | ||||
| import ( | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"sync" | ||||
|  | ||||
| 	"github.com/go-git/go-billy/v5" | ||||
| 	"github.com/go-git/go-billy/v5/helper/chroot" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	defaultDirectoryMode = 0755 | ||||
| 	defaultCreateMode    = 0666 | ||||
| ) | ||||
|  | ||||
| // OS is a filesystem based on the os filesystem. | ||||
| type OS struct{} | ||||
|  | ||||
| // New returns a new OS filesystem. | ||||
| func New(baseDir string) billy.Filesystem { | ||||
| 	return chroot.New(&OS{}, baseDir) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Create(filename string) (billy.File, error) { | ||||
| 	return fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, defaultCreateMode) | ||||
| } | ||||
|  | ||||
| func (fs *OS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) { | ||||
| 	if flag&os.O_CREATE != 0 { | ||||
| 		if err := fs.createDir(filename); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	f, err := os.OpenFile(filename, flag, perm) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &file{File: f}, err | ||||
| } | ||||
|  | ||||
| func (fs *OS) createDir(fullpath string) error { | ||||
| 	dir := filepath.Dir(fullpath) | ||||
| 	if dir != "." { | ||||
| 		if err := os.MkdirAll(dir, defaultDirectoryMode); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (fs *OS) ReadDir(path string) ([]os.FileInfo, error) { | ||||
| 	l, err := ioutil.ReadDir(path) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	var s = make([]os.FileInfo, len(l)) | ||||
| 	for i, f := range l { | ||||
| 		s[i] = f | ||||
| 	} | ||||
|  | ||||
| 	return s, nil | ||||
| } | ||||
|  | ||||
| func (fs *OS) Rename(from, to string) error { | ||||
| 	if err := fs.createDir(to); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return rename(from, to) | ||||
| } | ||||
|  | ||||
| func (fs *OS) MkdirAll(path string, perm os.FileMode) error { | ||||
| 	return os.MkdirAll(path, defaultDirectoryMode) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Open(filename string) (billy.File, error) { | ||||
| 	return fs.OpenFile(filename, os.O_RDONLY, 0) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Stat(filename string) (os.FileInfo, error) { | ||||
| 	return os.Stat(filename) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Remove(filename string) error { | ||||
| 	return os.Remove(filename) | ||||
| } | ||||
|  | ||||
| func (fs *OS) TempFile(dir, prefix string) (billy.File, error) { | ||||
| 	if err := fs.createDir(dir + string(os.PathSeparator)); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	f, err := ioutil.TempFile(dir, prefix) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &file{File: f}, nil | ||||
| } | ||||
|  | ||||
| func (fs *OS) Join(elem ...string) string { | ||||
| 	return filepath.Join(elem...) | ||||
| } | ||||
|  | ||||
| func (fs *OS) RemoveAll(path string) error { | ||||
| 	return os.RemoveAll(filepath.Clean(path)) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Lstat(filename string) (os.FileInfo, error) { | ||||
| 	return os.Lstat(filepath.Clean(filename)) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Symlink(target, link string) error { | ||||
| 	if err := fs.createDir(link); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return os.Symlink(target, link) | ||||
| } | ||||
|  | ||||
| func (fs *OS) Readlink(link string) (string, error) { | ||||
| 	return os.Readlink(link) | ||||
| } | ||||
|  | ||||
| // Capabilities implements the Capable interface. | ||||
| func (fs *OS) Capabilities() billy.Capability { | ||||
| 	return billy.DefaultCapabilities | ||||
| } | ||||
|  | ||||
| // file is a wrapper for an os.File which adds support for file locking. | ||||
| type file struct { | ||||
| 	*os.File | ||||
| 	m sync.Mutex | ||||
| } | ||||
							
								
								
									
										83
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os_plan9.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os_plan9.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| package osfs | ||||
|  | ||||
| import ( | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"syscall" | ||||
| ) | ||||
|  | ||||
| func (f *file) Lock() error { | ||||
| 	// Plan 9 uses a mode bit instead of explicit lock/unlock syscalls. | ||||
| 	// | ||||
| 	// Per http://man.cat-v.org/plan_9/5/stat: “Exclusive use files may be open | ||||
| 	// for I/O by only one fid at a time across all clients of the server. If a | ||||
| 	// second open is attempted, it draws an error.” | ||||
| 	// | ||||
| 	// There is no obvious way to implement this function using the exclusive use bit. | ||||
| 	// See https://golang.org/src/cmd/go/internal/lockedfile/lockedfile_plan9.go | ||||
| 	// for how file locking is done by the go tool on Plan 9. | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (f *file) Unlock() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func rename(from, to string) error { | ||||
| 	// If from and to are in different directories, copy the file | ||||
| 	// since Plan 9 does not support cross-directory rename. | ||||
| 	if filepath.Dir(from) != filepath.Dir(to) { | ||||
| 		fi, err := os.Stat(from) | ||||
| 		if err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
| 		if fi.Mode().IsDir() { | ||||
| 			return &os.LinkError{"rename", from, to, syscall.EISDIR} | ||||
| 		} | ||||
| 		fromFile, err := os.Open(from) | ||||
| 		if err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
| 		toFile, err := os.OpenFile(to, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fi.Mode()) | ||||
| 		if err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
| 		_, err = io.Copy(toFile, fromFile) | ||||
| 		if err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
|  | ||||
| 		// Copy mtime and mode from original file. | ||||
| 		// We need only one syscall if we avoid os.Chmod and os.Chtimes. | ||||
| 		dir := fi.Sys().(*syscall.Dir) | ||||
| 		var d syscall.Dir | ||||
| 		d.Null() | ||||
| 		d.Mtime = dir.Mtime | ||||
| 		d.Mode = dir.Mode | ||||
| 		if err = dirwstat(to, &d); err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
|  | ||||
| 		// Remove original file. | ||||
| 		err = os.Remove(from) | ||||
| 		if err != nil { | ||||
| 			return &os.LinkError{"rename", from, to, err} | ||||
| 		} | ||||
| 		return nil | ||||
| 	} | ||||
| 	return os.Rename(from, to) | ||||
| } | ||||
|  | ||||
| func dirwstat(name string, d *syscall.Dir) error { | ||||
| 	var buf [syscall.STATFIXLEN]byte | ||||
|  | ||||
| 	n, err := d.Marshal(buf[:]) | ||||
| 	if err != nil { | ||||
| 		return &os.PathError{"dirwstat", name, err} | ||||
| 	} | ||||
| 	if err = syscall.Wstat(name, buf[:n]); err != nil { | ||||
| 		return &os.PathError{"dirwstat", name, err} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										27
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os_posix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/go-git/go-billy/v5/osfs/os_posix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| // +build !plan9,!windows | ||||
|  | ||||
| package osfs | ||||
|  | ||||
| import ( | ||||
| 	"os" | ||||
|  | ||||
| 	"golang.org/x/sys/unix" | ||||
| ) | ||||
|  | ||||
| func (f *file) Lock() error { | ||||
| 	f.m.Lock() | ||||
| 	defer f.m.Unlock() | ||||
|  | ||||
| 	return unix.Flock(int(f.File.Fd()), unix.LOCK_EX) | ||||
| } | ||||
|  | ||||
| func (f *file) Unlock() error { | ||||
| 	f.m.Lock() | ||||
| 	defer f.m.Unlock() | ||||
|  | ||||
| 	return unix.Flock(int(f.File.Fd()), unix.LOCK_UN) | ||||
| } | ||||
|  | ||||
| func rename(from, to string) error { | ||||
| 	return os.Rename(from, to) | ||||
| } | ||||
							
								
								
									
										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