mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 06:07:22 +01:00
Implement If-Match handling
This commit is contained in:
parent
0719d5c32f
commit
7f0f9fd365
1 changed files with 23 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
|
@ -428,9 +429,19 @@ func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string
|
|||
flags := os.O_RDWR | os.O_CREATE | os.O_TRUNC
|
||||
if opts.IfNoneMatch {
|
||||
flags |= os.O_EXCL
|
||||
} else if opts.IfMatch == "*" {
|
||||
flags &= ^os.O_CREATE
|
||||
} else if opts.IfMatch != "" {
|
||||
etag, err := etagForFile(localPath)
|
||||
if err != nil {
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
if opts.IfMatch != etag {
|
||||
err = fmt.Errorf("If-Match does not match current ETag (%s/%s)", opts.IfMatch, etag)
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO handle IfMatch
|
||||
f, err := os.OpenFile(localPath, flags, 0666)
|
||||
if os.IsExist(err) {
|
||||
return "", carddav.NewPreconditionError(carddav.PreconditionNoUIDConflict)
|
||||
|
|
@ -608,9 +619,19 @@ func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath strin
|
|||
flags := os.O_RDWR | os.O_CREATE | os.O_TRUNC
|
||||
if opts.IfNoneMatch {
|
||||
flags |= os.O_EXCL
|
||||
} else if opts.IfMatch == "*" {
|
||||
flags &= ^os.O_CREATE
|
||||
} else if opts.IfMatch != "" {
|
||||
etag, err := etagForFile(localPath)
|
||||
if err != nil {
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
if opts.IfMatch != etag {
|
||||
err = fmt.Errorf("If-Match does not match current ETag (%s/%s)", opts.IfMatch, etag)
|
||||
return "", webdav.NewHTTPError(http.StatusPreconditionFailed, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO handle IfMatch
|
||||
f, err := os.OpenFile(localPath, flags, 0666)
|
||||
if os.IsExist(err) {
|
||||
return "", caldav.NewPreconditionError(caldav.PreconditionNoUIDConflict)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue