lock.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package webdav
  5. import (
  6. "errors"
  7. "io"
  8. "time"
  9. )
  10. var (
  11. ErrConfirmationFailed = errors.New("webdav: confirmation failed")
  12. ErrForbidden = errors.New("webdav: forbidden")
  13. ErrNoSuchLock = errors.New("webdav: no such lock")
  14. )
  15. // Condition can match a WebDAV resource, based on a token or ETag.
  16. // Exactly one of Token and ETag should be non-empty.
  17. type Condition struct {
  18. Not bool
  19. Token string
  20. ETag string
  21. }
  22. type LockSystem interface {
  23. // TODO: comment that the conditions should be ANDed together.
  24. Confirm(path string, conditions ...Condition) (c io.Closer, err error)
  25. // TODO: comment that token should be an absolute URI as defined by RFC 3986,
  26. // Section 4.3. In particular, it should not contain whitespace.
  27. Create(path string, now time.Time, ld LockDetails) (token string, c io.Closer, err error)
  28. Refresh(token string, now time.Time, duration time.Duration) (ld LockDetails, c io.Closer, err error)
  29. Unlock(token string) error
  30. }
  31. type LockDetails struct {
  32. Depth int // Negative means infinite depth.
  33. Duration time.Duration // Negative means unlimited duration.
  34. OwnerXML string // Verbatim XML.
  35. Path string
  36. }
  37. // TODO: a MemLS implementation.