carddav: add Stat to AddressObject interface

This commit is contained in:
emersion 2017-09-04 12:06:06 +02:00
parent 163fa1656d
commit 7d69432517
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,7 @@ package carddav
import ( import (
"errors" "errors"
"os"
"github.com/emersion/go-vcard" "github.com/emersion/go-vcard"
) )
@ -15,6 +16,7 @@ var (
type AddressObject interface { type AddressObject interface {
ID() string ID() string
Card() (vcard.Card, error) Card() (vcard.Card, error)
Stat() (os.FileInfo, error) // can return nil, nil
} }
type AddressBook interface { type AddressBook interface {

View File

@ -117,6 +117,11 @@ func (f *file) Readdir(count int) ([]os.FileInfo, error) {
} }
func (f *file) Stat() (os.FileInfo, error) { func (f *file) Stat() (os.FileInfo, error) {
info, err := f.ao.Stat()
if info != nil || err != nil {
return info, err
}
return &fileInfo{ return &fileInfo{
name: f.name, name: f.name,
mode: os.ModePerm, mode: os.ModePerm,
@ -158,10 +163,18 @@ func (d *dir) Readdir(count int) ([]os.FileInfo, error) {
d.files = make([]os.FileInfo, len(aos)) d.files = make([]os.FileInfo, len(aos))
for i, ao := range aos { for i, ao := range aos {
d.files[i] = &fileInfo{ f := &file{
fs: d.fs,
name: ao.ID() + ".vcf", name: ao.ID() + ".vcf",
mode: os.ModePerm, ao: ao,
} }
info, err := f.Stat()
if err != nil {
return nil, err
}
d.files[i] = info
} }
} }