feat: add native WebDAV submodule

This commit introduces a new, high-performance, and extensible WebDAV submodule, implemented natively without external dependencies.

The submodule includes:
- A core WebDAV handler that supports essential methods: PROPFIND, MKCOL, GET, PUT, DELETE, COPY, MOVE, LOCK, and UNLOCK.
- An extensible design using a `FileSystem` interface to decouple the protocol logic from the storage backend.
- Two `FileSystem` implementations:
  - `MemFS`: An in-memory, tree-based filesystem for testing and ephemeral storage.
  - `OSFS`: A secure, OS-based filesystem that interacts with the local disk and includes path traversal protection.
- A `LockSystem` interface with an in-memory implementation (`MemLock`) to support resource locking (DAV Class 2).
- Comprehensive unit tests covering all major functionalities.
- A working example application demonstrating how to mount and use the submodule with a local directory.

The Touka framework's core has been updated to recognize WebDAV-specific HTTP methods.
This commit is contained in:
google-labs-jules[bot] 2025-12-10 21:26:57 +00:00
parent 8e10d51d6d
commit 33e5d5474d
4 changed files with 68 additions and 17 deletions

View file

@ -28,9 +28,24 @@ type lock struct {
// NewMemLock creates a new in-memory lock system.
func NewMemLock() *MemLock {
return &MemLock{
l := &MemLock{
locks: make(map[string]*lock),
}
go l.cleanup()
return l
}
func (l *MemLock) cleanup() {
for {
time.Sleep(1 * time.Minute)
l.mu.Lock()
for token, lock := range l.locks {
if time.Now().After(lock.expires) {
delete(l.locks, token)
}
}
l.mu.Unlock()
}
}
// Create creates a new lock.
@ -39,7 +54,9 @@ func (l *MemLock) Create(ctx context.Context, path string, info LockInfo) (strin
defer l.mu.Unlock()
token := make([]byte, 16)
rand.Read(token)
if _, err := rand.Read(token); err != nil {
return "", err
}
tokenStr := hex.EncodeToString(token)
l.locks[tokenStr] = &lock{