carddav: cache file contents when opening it

This commit is contained in:
emersion 2017-09-14 11:08:16 +02:00
parent d2d201e6ad
commit 579a25f989
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 12 additions and 2 deletions

View File

@ -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 {

View File

@ -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
} }