Add initial support for solr

This commit is contained in:
Tom Wiesing 2022-11-02 13:50:11 +01:00
parent 7bedeefb50
commit b27871f39a
No known key found for this signature in database
13 changed files with 131 additions and 31 deletions

View file

@ -55,5 +55,5 @@ type WritableFile interface {
}
func init() {
var _ Environment = Native{}
var _ Environment = new(Native)
}

View file

@ -10,7 +10,7 @@ import (
//
// If the command executes, it's exit code will be returned.
// If the command can not be executed, returns [ExecCommandError].
func (Native) Exec(io stream.IOStream, workdir string, exe string, argv ...string) int {
func (*Native) Exec(io stream.IOStream, workdir string, exe string, argv ...string) int {
// setup the command
cmd := exec.Command(exe, argv...)
cmd.Dir = workdir
@ -35,7 +35,7 @@ func (Native) Exec(io stream.IOStream, workdir string, exe string, argv ...strin
return 0
}
func (n Native) LookPathAbs(file string) (string, error) {
func (n *Native) LookPathAbs(file string) (string, error) {
path, err := exec.LookPath(file)
if err != nil {
return "", err

View file

@ -4,77 +4,101 @@ import (
"io/fs"
"os"
"path/filepath"
"sync"
"syscall"
"time"
)
type Native struct{}
type Native struct {
ulock sync.Mutex
umask int
}
func (Native) isEnv() {}
func (*Native) isEnv() {}
func (Native) GetEnv(name string) string {
func (n *Native) setMask(umask int) {
n.ulock.Lock()
n.umask = syscall.Umask(umask)
}
func (n *Native) resetMask() {
syscall.Umask(n.umask)
n.ulock.Unlock()
}
func (*Native) GetEnv(name string) string {
return os.Getenv(name)
}
func (Native) Stat(path string) (fs.FileInfo, error) {
func (*Native) Stat(path string) (fs.FileInfo, error) {
return os.Stat(path)
}
func (Native) Lstat(path string) (fs.FileInfo, error) {
func (*Native) Lstat(path string) (fs.FileInfo, error) {
return os.Lstat(path)
}
func (Native) Readlink(path string) (string, error) {
func (*Native) Readlink(path string) (string, error) {
return os.Readlink(path)
}
func (Native) Symlink(oldname, newname string) error {
func (*Native) Symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
}
func (Native) ReadDir(name string) ([]fs.DirEntry, error) {
func (*Native) ReadDir(name string) ([]fs.DirEntry, error) {
return os.ReadDir(name)
}
func (Native) SameFile(f1, f2 fs.FileInfo) bool {
func (*Native) SameFile(f1, f2 fs.FileInfo) bool {
return os.SameFile(f1, f2)
}
func (Native) WalkDir(path string, f fs.WalkDirFunc) error {
func (*Native) WalkDir(path string, f fs.WalkDirFunc) error {
return filepath.WalkDir(path, f)
}
func (Native) Executable() (string, error) {
func (*Native) Executable() (string, error) {
return os.Executable() // TODO: not sure this works with the remote concepts
}
func (Native) Open(path string) (fs.File, error) {
func (*Native) Open(path string) (fs.File, error) {
return os.Open(path)
}
func (Native) Create(path string, mode fs.FileMode) (WritableFile, error) {
func (n *Native) Create(path string, mode fs.FileMode) (WritableFile, error) {
n.ulock.Lock()
defer n.ulock.Unlock()
return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode)
}
func (Native) Chtimes(name string, atime time.Time, mtime time.Time) error {
func (*Native) Chtimes(name string, atime time.Time, mtime time.Time) error {
return os.Chtimes(name, atime, mtime)
}
func (Native) Mkdir(path string, mode fs.FileMode) error {
return os.Mkdir(path, mode)
func (n *Native) Mkdir(path string, mode fs.FileMode) error {
n.setMask(0)
defer n.resetMask()
return os.Mkdir(path, fs.ModeDir|mode)
}
func (Native) MkdirAll(path string, mode fs.FileMode) error {
return os.MkdirAll(path, mode)
func (n *Native) MkdirAll(path string, mode fs.FileMode) error {
n.setMask(0)
defer n.resetMask()
return os.MkdirAll(path, fs.ModeDir|mode)
}
func (Native) Remove(path string) error {
func (*Native) Remove(path string) error {
return os.Remove(path)
}
func (Native) RemoveAll(path string) error {
func (*Native) RemoveAll(path string) error {
return os.RemoveAll(path)
}
func (Native) Abs(path string) (string, error) {
func (*Native) Abs(path string) (string, error) {
return filepath.Abs(path)
}

View file

@ -5,11 +5,11 @@ import (
"net"
)
func (Native) Listen(network, address string) (net.Listener, error) {
func (*Native) Listen(network, address string) (net.Listener, error) {
return net.Listen(network, address)
}
func (Native) DialContext(context context.Context, network, address string) (net.Conn, error) {
func (*Native) DialContext(context context.Context, network, address string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(context, network, address)
}