fix: add ResolveRenameOp to handle directory renames

RenameNode was calling Resolve() which generated blob keys for
directories that don't have blobs, causing 'key not found' errors.

Added ResolveRenameOp to BlobKeyResolver interface:
- FlatKeyResolver returns nil (UUIDs don't change on rename)
- HierarchicalKeyResolver returns move op for files and directories

This allows directory renames to work correctly with flat storage,
and leverages os.Rename for atomic directory moves with hierarchical.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-01-04 23:58:43 +00:00
parent b8e1671248
commit d0c2a21ffd
5 changed files with 75 additions and 12 deletions

View File

@@ -301,8 +301,31 @@ func TestHTTP_CatalogEndpoints(t *testing.T) {
}
})
// Note: Directory rename test skipped due to VFS bug where it tries to
// resolve blob keys for directories which don't have blobs.
t.Run("rename directory", func(t *testing.T) {
root, err := env.vfs.FindNode(ctx, env.db, env.rootDirID.String(), env.scope)
if err != nil {
t.Fatalf("FindNode root: %v", err)
}
renameDir, err := env.vfs.CreateDirectory(ctx, env.db, root.ID, "to-rename", env.scope)
if err != nil {
t.Fatalf("CreateDirectory to-rename: %v", err)
}
var resp struct {
Kind string `json:"kind"`
ID string `json:"id"`
Name string `json:"name"`
}
body := map[string]string{"name": "renamed-dir"}
doJSONAuth(t, env.app, http.MethodPatch, driveURL(fmt.Sprintf("/directories/%s", renameDir.PublicID)), env.accessToken, body, http.StatusOK, &resp)
if resp.Kind != "directory" {
t.Errorf("expected kind=directory, got %q", resp.Kind)
}
if resp.Name != "renamed-dir" {
t.Errorf("expected name=renamed-dir, got %q", resp.Name)
}
})
// File tests
t.Run("fetch file by ID", func(t *testing.T) {