pkg/environment: Remove some file-based functions

This commit removes certain file-based functions from 'pkg/environment',
continuing the migration to entirely remove the package.
This commit is contained in:
Tom Wiesing 2023-03-02 11:15:15 +01:00
parent 39207a1cb5
commit 45540ab253
No known key found for this signature in database
20 changed files with 52 additions and 120 deletions

View file

@ -3,7 +3,6 @@ package environment
import (
"io"
"io/fs"
"time"
)
// Environment represents an environment that a program can run it.
@ -11,31 +10,9 @@ import (
type Environment interface {
isEnv()
GetEnv(name string) string
Stat(path string) (fs.FileInfo, error)
Lstat(path string) (fs.FileInfo, error)
Readlink(path string) (string, error)
Symlink(oldname, newname string) error
ReadDir(name string) ([]fs.DirEntry, error)
Open(path string) (fs.File, error)
Chtimes(name string, atime time.Time, mtime time.Time) error
SameFile(f1, f2 fs.FileInfo) bool
Create(path string, mode fs.FileMode) (WritableFile, error)
Mkdir(path string, mode fs.FileMode) error
MkdirAll(path string, mode fs.FileMode) error
Remove(path string) error
RemoveAll(path string) error
WalkDir(root string, fn fs.WalkDirFunc) error
Abs(path string) (string, error)
}
type WritableFile interface {

View file

@ -8,15 +8,6 @@ import (
"github.com/tkw1536/pkglib/pools"
)
// ExecCommandError is returned by Exec when a command could not be executed.
// This typically hints that the executable cannot be found, but may have other causes.
const ExecCommandError = 127
// ExecCommandErrorFunc always returns ExecCommandError.
func ExecCommandErrorFunc() int {
return ExecCommandError
}
// DefaultFilePerm is the default mode to use for files
const DefaultFilePerm fs.FileMode = 0666
@ -51,7 +42,7 @@ func WriteFile(env Environment, path string, data []byte, mode fs.FileMode) erro
// ReadFile is like [os.ReadFile]
func ReadFile(env Environment, path string) ([]byte, error) {
// open the file!
file, err := env.Open(path)
file, err := os.Open(path)
if err != nil {
return nil, err
}

View file

@ -3,7 +3,6 @@ package environment
import (
"io/fs"
"os"
"path/filepath"
"sync"
"syscall"
"time"
@ -26,46 +25,6 @@ func (n *Native) resetMask() {
n.ulock.Unlock()
}
func (*Native) GetEnv(name string) string {
return os.Getenv(name)
}
func (*Native) Stat(path string) (fs.FileInfo, error) {
return os.Stat(path)
}
func (*Native) Lstat(path string) (fs.FileInfo, error) {
return os.Lstat(path)
}
func (*Native) Readlink(path string) (string, error) {
return os.Readlink(path)
}
func (*Native) Symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
}
func (*Native) ReadDir(name string) ([]fs.DirEntry, error) {
return os.ReadDir(name)
}
func (*Native) SameFile(f1, f2 fs.FileInfo) bool {
return os.SameFile(f1, f2)
}
func (*Native) WalkDir(path string, f fs.WalkDirFunc) error {
return filepath.WalkDir(path, f)
}
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) {
return os.Open(path)
}
func (n *Native) Create(path string, mode fs.FileMode) (WritableFile, error) {
n.ulock.Lock()
defer n.ulock.Unlock()
@ -90,15 +49,3 @@ func (n *Native) MkdirAll(path string, mode fs.FileMode) error {
return os.MkdirAll(path, fs.ModeDir|mode)
}
func (*Native) Remove(path string) error {
return os.Remove(path)
}
func (*Native) RemoveAll(path string) error {
return os.RemoveAll(path)
}
func (*Native) Abs(path string) (string, error) {
return filepath.Abs(path)
}