mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-23 00:34:23 +00:00
carddav: cache file contents when opening it
This commit is contained in:
parent
d2d201e6ad
commit
579a25f989
@ -354,10 +354,19 @@ func (fs *fileSystem) OpenFile(ctx context.Context, name string, flag int, perm
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &file{
|
f := &file{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
ao: ao,
|
ao: ao,
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
if flag&os.O_RDONLY != 0 {
|
||||||
|
// This file will be read, cache its contents
|
||||||
|
if _, err := f.Read(nil); err != nil {
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *fileSystem) RemoveAll(ctx context.Context, name string) error {
|
func (fs *fileSystem) RemoveAll(ctx context.Context, name string) error {
|
||||||
|
@ -226,6 +226,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
|
|||||||
}
|
}
|
||||||
w.Header().Set("ETag", etag)
|
w.Header().Set("ETag", etag)
|
||||||
// Let ServeContent determine the Content-Type header.
|
// Let ServeContent determine the Content-Type header.
|
||||||
|
// TODO: use getcontenttype dead prop if available
|
||||||
http.ServeContent(w, r, reqPath, fi.ModTime(), f)
|
http.ServeContent(w, r, reqPath, fi.ModTime(), f)
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user