feat: tested
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"math"
|
||||
@@ -114,6 +113,20 @@ func NewEncFile(name string, file *os.File, encFs *EncFs, isCreate bool) (*EncFi
|
||||
}
|
||||
isDir := fileInfo.IsDir()
|
||||
var encFileMeta *EncFileMeta = nil
|
||||
|
||||
fileState, err := os.Stat(name)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
isCreate = true
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if !fileState.IsDir() && fileState.Size() == 0 {
|
||||
isCreate = true
|
||||
}
|
||||
}
|
||||
|
||||
if !isDir {
|
||||
if isCreate {
|
||||
encFileMeta, err = openOrNewEncFileMeta(name)
|
||||
@@ -193,14 +206,9 @@ func (f *EncFile) Seek(offset int64, whence int) (int64, error) {
|
||||
return 0, checkIsFileErr
|
||||
}
|
||||
|
||||
// I do not understand whence
|
||||
if whence != 0 {
|
||||
return 0, fmt.Errorf("not supported whence: %d", whence)
|
||||
}
|
||||
|
||||
ret, err := f.file.Seek(offset, whence)
|
||||
if err == nil {
|
||||
f.filePos = offset
|
||||
f.filePos = ret
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user