mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 07:31:18 +00:00
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>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package virtualfs
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/get-drexa/drexa/internal/blob"
|
|
"github.com/google/uuid"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type FlatKeyResolver struct{}
|
|
|
|
var _ BlobKeyResolver = &FlatKeyResolver{}
|
|
|
|
func NewFlatKeyResolver() *FlatKeyResolver {
|
|
return &FlatKeyResolver{}
|
|
}
|
|
|
|
func (r *FlatKeyResolver) ShouldPersistKey() bool {
|
|
return true
|
|
}
|
|
|
|
func (r *FlatKeyResolver) Resolve(ctx context.Context, db bun.IDB, node *Node) (blob.Key, error) {
|
|
if node.BlobKey == "" {
|
|
id, err := uuid.NewV7()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return blob.Key(id.String()), nil
|
|
}
|
|
return node.BlobKey, nil
|
|
}
|
|
|
|
func (r *FlatKeyResolver) ResolveDeletionKeys(ctx context.Context, node *Node, allKeys []blob.Key) (*DeletionPlan, error) {
|
|
return &DeletionPlan{Keys: allKeys}, nil
|
|
}
|
|
|
|
// ResolveBulkMoveOps returns nil for flat key storage since blob keys are UUIDs
|
|
// and don't change when nodes are moved to a different parent.
|
|
func (r *FlatKeyResolver) ResolveBulkMoveOps(ctx context.Context, db bun.IDB, nodes []*Node, newParentID uuid.UUID) ([]BlobMoveOp, error) {
|
|
for _, node := range nodes[1:] {
|
|
if node.ParentID != nodes[0].ParentID {
|
|
return nil, ErrUnsupportedOperation
|
|
}
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// ResolveRenameOp returns nil for flat key storage since blob keys are UUIDs
|
|
// and don't change when nodes are renamed.
|
|
func (r *FlatKeyResolver) ResolveRenameOp(ctx context.Context, db bun.IDB, node *Node, newName string) (*BlobMoveOp, error) {
|
|
return nil, nil
|
|
}
|