feat: working in process
This commit is contained in:
53
encfs/fs.go
53
encfs/fs.go
@@ -10,15 +10,19 @@ import (
|
||||
|
||||
// copied from afero/os.go
|
||||
|
||||
type EncFs struct{}
|
||||
|
||||
func NewEncFs() afero.Fs {
|
||||
return &EncFs{}
|
||||
type EncFs struct {
|
||||
key []byte
|
||||
}
|
||||
|
||||
func (EncFs) Name() string { return "EncFs" }
|
||||
func NewEncFs(key []byte) afero.Fs {
|
||||
return &EncFs{
|
||||
key: key,
|
||||
}
|
||||
}
|
||||
|
||||
func (EncFs) Create(name string) (afero.File, error) {
|
||||
func (*EncFs) Name() string { return "EncFs" }
|
||||
|
||||
func (encFs *EncFs) Create(name string) (afero.File, error) {
|
||||
if err := checkFileExt(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -28,18 +32,18 @@ func (EncFs) Create(name string) (afero.File, error) {
|
||||
// a nil value of type *os.File or nil won't be nil
|
||||
return nil, e
|
||||
}
|
||||
return convertOsFileToEncFile(name, f, e, true)
|
||||
return convertOsFileToEncFile(name, f, e, encFs, true)
|
||||
}
|
||||
|
||||
func (EncFs) Mkdir(name string, perm os.FileMode) error {
|
||||
func (*EncFs) Mkdir(name string, perm os.FileMode) error {
|
||||
return os.Mkdir(name, perm)
|
||||
}
|
||||
|
||||
func (EncFs) MkdirAll(path string, perm os.FileMode) error {
|
||||
func (*EncFs) MkdirAll(path string, perm os.FileMode) error {
|
||||
return os.MkdirAll(path, perm)
|
||||
}
|
||||
|
||||
func (EncFs) Open(name string) (afero.File, error) {
|
||||
func (encFs *EncFs) Open(name string) (afero.File, error) {
|
||||
if err := checkFileExt(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -49,10 +53,10 @@ func (EncFs) Open(name string) (afero.File, error) {
|
||||
// a nil value of type *os.File or nil won't be nil
|
||||
return nil, e
|
||||
}
|
||||
return convertOsFileToEncFile(name, f, e, false)
|
||||
return convertOsFileToEncFile(name, f, e, encFs, false)
|
||||
}
|
||||
|
||||
func (EncFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
|
||||
func (*EncFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
|
||||
f, e := os.OpenFile(name, flag, perm)
|
||||
if f == nil {
|
||||
// while this looks strange, we need to return a bare nil (of type nil) not
|
||||
@@ -62,47 +66,47 @@ func (EncFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, erro
|
||||
return f, e
|
||||
}
|
||||
|
||||
func (EncFs) Remove(name string) error {
|
||||
func (*EncFs) Remove(name string) error {
|
||||
// TODO remove enc file meta
|
||||
return os.Remove(name)
|
||||
}
|
||||
|
||||
func (EncFs) RemoveAll(path string) error {
|
||||
func (*EncFs) RemoveAll(path string) error {
|
||||
// TODO remove enc file meta
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
func (EncFs) Rename(oldname, newname string) error {
|
||||
func (*EncFs) Rename(oldname, newname string) error {
|
||||
// TODO rename enc file meta
|
||||
return os.Rename(oldname, newname)
|
||||
}
|
||||
|
||||
func (EncFs) Stat(name string) (os.FileInfo, error) {
|
||||
func (*EncFs) Stat(name string) (os.FileInfo, error) {
|
||||
return os.Stat(name)
|
||||
}
|
||||
|
||||
func (EncFs) Chmod(name string, mode os.FileMode) error {
|
||||
func (*EncFs) Chmod(name string, mode os.FileMode) error {
|
||||
return os.Chmod(name, mode)
|
||||
}
|
||||
|
||||
func (EncFs) Chown(name string, uid, gid int) error {
|
||||
func (*EncFs) Chown(name string, uid, gid int) error {
|
||||
return os.Chown(name, uid, gid)
|
||||
}
|
||||
|
||||
func (EncFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
func (*EncFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
return os.Chtimes(name, atime, mtime)
|
||||
}
|
||||
|
||||
func (EncFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||
func (*EncFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||
fi, err := os.Lstat(name)
|
||||
return fi, true, err
|
||||
}
|
||||
|
||||
func (EncFs) SymlinkIfPossible(oldname, newname string) error {
|
||||
func (*EncFs) SymlinkIfPossible(oldname, newname string) error {
|
||||
return os.Symlink(oldname, newname)
|
||||
}
|
||||
|
||||
func (EncFs) ReadlinkIfPossible(name string) (string, error) {
|
||||
func (*EncFs) ReadlinkIfPossible(name string) (string, error) {
|
||||
return os.Readlink(name)
|
||||
}
|
||||
|
||||
@@ -113,12 +117,11 @@ func checkFileExt(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertOsFileToEncFile(name string, file *os.File, e error, isCreate bool) (afero.File, error) {
|
||||
func convertOsFileToEncFile(name string, file *os.File, e error, encFs *EncFs, isCreate bool) (afero.File, error) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
// TODO add password, and IV etc ...
|
||||
encFile, err := NewEncFile(name, file, isCreate)
|
||||
encFile, err := NewEncFile(name, file, encFs, isCreate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user