some fixes
This commit is contained in:
parent
13a64cecfe
commit
1075b3215c
4 changed files with 24 additions and 7 deletions
|
|
@ -5,12 +5,15 @@ import (
|
|||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var _ provider.File = (*file)(nil)
|
||||
|
||||
type file struct {
|
||||
provider.File
|
||||
rmu sync.Mutex
|
||||
wmu sync.Mutex
|
||||
fs *FS
|
||||
r *reader
|
||||
w *writer
|
||||
|
|
@ -140,10 +143,12 @@ func (f *file) Seek(offset int64, whence int) (n int64, err error) {
|
|||
f.r.nonce = f.nonce
|
||||
f.w.nonce = f.nonce
|
||||
f.r.off = roff
|
||||
f.r.cn = cn
|
||||
return
|
||||
}
|
||||
|
||||
func (f *file) Read(p []byte) (n int, err error) {
|
||||
f.r.cn = -1
|
||||
n, err = f.r.Read(p)
|
||||
return
|
||||
}
|
||||
|
|
@ -154,6 +159,8 @@ func (f *file) Write(p []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (f *file) ReadAt(p []byte, pos int64) (n int, err error) {
|
||||
f.rmu.Lock()
|
||||
defer f.rmu.Unlock()
|
||||
cn, _, roff := align(pos)
|
||||
var last bool
|
||||
if f.r.cn != cn {
|
||||
|
|
@ -165,7 +172,6 @@ func (f *file) ReadAt(p []byte, pos int64) (n int, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
f.r.cn = cn
|
||||
}
|
||||
n = copy(p, f.r.unread[roff:])
|
||||
if last && len(f.r.unread) == n+int(roff) {
|
||||
|
|
@ -175,6 +181,8 @@ func (f *file) ReadAt(p []byte, pos int64) (n int, err error) {
|
|||
}
|
||||
|
||||
func (f *file) WriteAt(data []byte, pos int64) (n int, err error) {
|
||||
f.wmu.Lock()
|
||||
defer f.wmu.Unlock()
|
||||
cn, off, woff := align(pos)
|
||||
c, ok := f.w.cm[cn]
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue