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

@ -36,7 +36,13 @@ func (fs *MemFS) findNode(path string) (*memNode, error) {
current := fs.root
parts := strings.Split(path, "/")
for _, part := range parts {
if part == "" {
if part == "" || part == "." {
continue
}
if part == ".." {
if current.parent != nil {
current = current.parent
}
continue
}
if current.children == nil {
@ -105,6 +111,7 @@ func (fs *MemFS) OpenFile(ctx context.Context, name string, flag int, perm os.Fi
if flag&os.O_TRUNC != 0 {
node.data = nil
node.size = 0
}
return &memFile{
@ -234,14 +241,21 @@ func (f *memFile) Write(p []byte) (n int, err error) {
func (f *memFile) Seek(offset int64, whence int) (int64, error) {
f.fs.mu.Lock()
defer f.fs.mu.Unlock()
var newOffset int64
switch whence {
case 0:
f.offset = offset
case 1:
f.offset += offset
case 2:
f.offset = int64(len(f.node.data)) + offset
case io.SeekStart:
newOffset = offset
case io.SeekCurrent:
newOffset = f.offset + offset
case io.SeekEnd:
newOffset = f.node.size + offset
default:
return 0, os.ErrInvalid
}
if newOffset < 0 {
return 0, os.ErrInvalid
}
f.offset = newOffset
return f.offset, nil
}