added cache only access server

This commit is contained in:
ston1th 2022-03-22 21:48:59 +01:00
commit b5ae5504a7
6 changed files with 217 additions and 8 deletions

View file

@ -128,11 +128,50 @@ func (fs *FS) RemoveDst(name string) error {
return os.Remove(dp)
}
func (fs *FS) statDst(name string) (fi stdfs.FileInfo, err error) {
func (fs *FS) StatDst(name string) (fi stdfs.FileInfo, err error) {
fi, err = fs.sc.Get(name)
if err == nil {
return
}
return fs.statDst(name)
}
func (fs *FS) statDst(name string) (stdfs.FileInfo, error) {
_, dp := fs.paths(name)
return os.Stat(dp)
}
func (fs *FS) OpenDst(name string) (f http.File, err error) {
log := fs.log.WithValues("file", name)
_, dp := fs.paths(name)
fi, err := fs.StatDst(name)
if err != nil {
if !skipLog(name) {
log.Error(err, "error stat cache file")
}
return
}
file, err := os.Open(dp)
if err != nil {
if !skipLog(name) {
log.Error(err, "error opening cache file")
}
return
}
if fi.IsDir() {
f = &Dir{log: log.WithName("dir"), f: file, dc: fs.dc}
return
}
md := fs.metadata(name, fi.Size())
f = &File{
log: log,
f: file,
md: md,
offline: true,
}
return
}
func (fs *FS) CancelPreload(name string) {
if cancel, ok := fs.pm[name]; ok {
cancel()