mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
fix(objectstore): decouple WebDAV targetPath from logical storage key and fix basePath duplication
- WebDAV Put now returns PutResult with driver-agnostic logical relative key (relKey), keeping database records decoupled from mount basePath. - targetPath mounts logical keys to the remote WebDAV server path, and transparently handles legacy database records containing basePath or duplicate basePath prefixes. - Make localBackend path resolution resilient to keys with leading slashes or legacy absolute paths outside local root by safely mounting them as relative paths. - Add comprehensive unit tests for WebDAV targetPath, relKey, end-to-end roundtrip with in-memory WebDAV server, and local storage leading slash handling.
This commit is contained in:
@@ -48,4 +48,19 @@ func TestLocalBackendRoundTrip(t *testing.T) {
|
||||
if _, err := backend.Get(ctx, key); err == nil {
|
||||
t.Errorf("Get(%q) after Delete() returned nil error", key)
|
||||
}
|
||||
|
||||
// Test key with leading slash
|
||||
slashKey := "/uploads/2026/06/13/slash_test.txt"
|
||||
putSlashRes, err := backend.Put(ctx, slashKey, bytes.NewBufferString(content), int64(len(content)), "text/plain")
|
||||
if err != nil {
|
||||
t.Fatalf("Put(%q) returned error: %v", slashKey, err)
|
||||
}
|
||||
if putSlashRes.Key != slashKey {
|
||||
t.Errorf("Put(%q) key = %q, want %q", slashKey, putSlashRes.Key, slashKey)
|
||||
}
|
||||
objSlash, err := backend.Get(ctx, slashKey)
|
||||
if err != nil {
|
||||
t.Fatalf("Get(%q) returned error: %v", slashKey, err)
|
||||
}
|
||||
_ = objSlash.Body.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user