added webdav
This commit is contained in:
parent
2e78593526
commit
78bd754298
25 changed files with 7783 additions and 90 deletions
|
|
@ -9,7 +9,9 @@ import (
|
|||
|
||||
type Metadata struct {
|
||||
mu sync.RWMutex `json:"-"`
|
||||
fs *FS `json:"-"`
|
||||
f *os.File `json:"-"`
|
||||
name string `json:"-"`
|
||||
Size int64 `json:"s"`
|
||||
Chunks Chunks `json:"c"`
|
||||
preload bool `json:"-"`
|
||||
|
|
@ -28,13 +30,36 @@ func (md *Metadata) AddChunk(off int64, n int) {
|
|||
}
|
||||
|
||||
func (md *Metadata) ReadAt(p []byte, pos int64) (int, error) {
|
||||
if md.f == nil {
|
||||
err := md.openCacheFile()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return md.f.ReadAt(p, pos)
|
||||
}
|
||||
|
||||
func (md *Metadata) WriteAt(data []byte, pos int64) (int, error) {
|
||||
if md.f == nil {
|
||||
err := md.openCacheFile()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return md.f.WriteAt(data, pos)
|
||||
}
|
||||
|
||||
func (md *Metadata) openCacheFile() error {
|
||||
md.mu.Lock()
|
||||
defer md.mu.Unlock()
|
||||
if md.f != nil {
|
||||
return nil
|
||||
}
|
||||
f, err := md.fs.openCacheFile(md.name, md.Size)
|
||||
md.f = f
|
||||
return err
|
||||
}
|
||||
|
||||
func (md *Metadata) Preload() bool {
|
||||
md.mu.Lock()
|
||||
defer md.mu.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue