mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 14:17:21 +01:00
storage: adapt to go-webdav interface changes
This commit is contained in:
parent
39f90686f9
commit
adb2a8bdfb
3 changed files with 139 additions and 40 deletions
|
|
@ -225,6 +225,10 @@ func (b *filesystemBackend) GetCalendar(ctx context.Context, urlPath string) (*c
|
|||
return &calendar, nil
|
||||
}
|
||||
|
||||
func (b *filesystemBackend) CreateCalendar(ctx context.Context, calendar *caldav.Calendar) error {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func (b *filesystemBackend) GetCalendarObject(ctx context.Context, objPath string, req *caldav.CalendarCompRequest) (*caldav.CalendarObject, error) {
|
||||
log.Debug().Str("path", objPath).Msg("filesystem.GetCalendarObject()")
|
||||
|
||||
|
|
@ -299,12 +303,12 @@ func (b *filesystemBackend) QueryCalendarObjects(ctx context.Context, urlPath st
|
|||
return filtered, err
|
||||
}
|
||||
|
||||
func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath string, calendar *ical.Calendar, opts *caldav.PutCalendarObjectOptions) (loc string, err error) {
|
||||
func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath string, calendar *ical.Calendar, opts *caldav.PutCalendarObjectOptions) (*caldav.CalendarObject, error) {
|
||||
log.Debug().Str("path", objPath).Msg("filesystem.PutCalendarObject()")
|
||||
|
||||
_, uid, err := caldav.ValidateCalendarObject(calendar)
|
||||
if err != nil {
|
||||
return "", caldav.NewPreconditionError(caldav.PreconditionValidCalendarObjectResource)
|
||||
return nil, caldav.NewPreconditionError(caldav.PreconditionValidCalendarObjectResource)
|
||||
}
|
||||
|
||||
// Object always get saved as <UID>.ics
|
||||
|
|
@ -313,7 +317,7 @@ func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath strin
|
|||
|
||||
localPath, err := b.safeLocalCalDAVPath(ctx, objPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
flags := os.O_RDWR | os.O_CREATE | os.O_TRUNC
|
||||
|
|
@ -328,33 +332,49 @@ func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath strin
|
|||
// Make sure we overwrite the _right_ file
|
||||
etag, err := etagForFile(localPath)
|
||||
if err != nil {
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
return nil, webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
want, err := opts.IfMatch.ETag()
|
||||
if err != nil {
|
||||
return "", webdav.NewHTTPError(http.StatusBadRequest, err)
|
||||
return nil, webdav.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
if want != etag {
|
||||
err = fmt.Errorf("If-Match does not match current ETag (%s/%s)", want, etag)
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
return nil, webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(localPath, flags, 0666)
|
||||
if os.IsExist(err) {
|
||||
return "", caldav.NewPreconditionError(caldav.PreconditionNoUIDConflict)
|
||||
return nil, caldav.NewPreconditionError(caldav.PreconditionNoUIDConflict)
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
enc := ical.NewEncoder(f)
|
||||
err = enc.Encode(calendar)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return objPath, nil
|
||||
etag, err := etagForFile(localPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := caldav.CalendarObject{
|
||||
Path: objPath,
|
||||
ModTime: info.ModTime(),
|
||||
ContentLength: info.Size(),
|
||||
ETag: etag,
|
||||
Data: calendar,
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (b *filesystemBackend) DeleteCalendarObject(ctx context.Context, path string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue