mirror of
https://github.com/cloudreve/cloudreve.git
synced 2026-03-03 02:27:00 +00:00
fix(dbfs): setting version does not change file size
This commit is contained in:
@@ -198,7 +198,7 @@ type FileClient interface {
|
||||
// SoftDelete soft-deletes a file, also renaming it to a random name
|
||||
SoftDelete(ctx context.Context, file *ent.File) error
|
||||
// SetPrimaryEntity sets primary entity of a file
|
||||
SetPrimaryEntity(ctx context.Context, file *ent.File, entityID int) error
|
||||
SetPrimaryEntity(ctx context.Context, file *ent.File, entity *ent.Entity) error
|
||||
// UnlinkEntity unlinks an entity from a file
|
||||
UnlinkEntity(ctx context.Context, entity *ent.Entity, file *ent.File, owner *ent.User) (StorageDiff, error)
|
||||
// CreateDirectLink creates a direct link for a file
|
||||
@@ -743,8 +743,8 @@ func (f *fileClient) UpgradePlaceholder(ctx context.Context, file *ent.File, mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fileClient) SetPrimaryEntity(ctx context.Context, file *ent.File, entityID int) error {
|
||||
return f.client.File.UpdateOne(file).SetPrimaryEntity(entityID).Exec(ctx)
|
||||
func (f *fileClient) SetPrimaryEntity(ctx context.Context, file *ent.File, entity *ent.Entity) error {
|
||||
return f.client.File.UpdateOne(file).SetPrimaryEntity(entity.ID).SetSize(entity.Size).Exec(ctx)
|
||||
}
|
||||
|
||||
func (f *fileClient) CreateFile(ctx context.Context, root *ent.File, args *CreateFileParameters) (*ent.File, *ent.Entity, StorageDiff, error) {
|
||||
|
||||
@@ -752,7 +752,7 @@ func (f *DBFS) setCurrentVersion(ctx context.Context, target *File, versionId in
|
||||
return serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err)
|
||||
}
|
||||
|
||||
if err := fc.SetPrimaryEntity(ctx, target.Model, targetVersion.ID()); err != nil {
|
||||
if err := fc.SetPrimaryEntity(ctx, target.Model, targetVersion.Model()); err != nil {
|
||||
_ = inventory.Rollback(tx)
|
||||
return serializer.NewError(serializer.CodeDBError, "Failed to set primary entity", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user