(ctx context.Context, args *CopyParameter)
| 606 | } |
| 607 | |
| 608 | func (f *fileClient) Copy(ctx context.Context, args *CopyParameter) (map[int][]*ent.File, StorageDiff, error) { |
| 609 | files := args.Files |
| 610 | dstMap := args.DstMap |
| 611 | pageSize := capPageSize(f.maxSQlParam, intsets.MaxInt, 10) |
| 612 | // 1. Copy files and metadata |
| 613 | copyFileStm := lo.Map(files, func(file *ent.File, index int) *ent.FileCreate { |
| 614 | |
| 615 | stm := f.client.File.Create(). |
| 616 | SetName(file.Name). |
| 617 | SetOwnerID(dstMap[file.FileChildren][0].OwnerID). |
| 618 | SetSize(file.Size). |
| 619 | SetType(file.Type). |
| 620 | SetParent(dstMap[file.FileChildren][0]). |
| 621 | SetIsSymbolic(file.IsSymbolic) |
| 622 | if file.StoragePolicyFiles > 0 { |
| 623 | stm.SetStoragePolicyFiles(file.StoragePolicyFiles) |
| 624 | } |
| 625 | if file.PrimaryEntity > 0 { |
| 626 | stm.SetPrimaryEntity(file.PrimaryEntity) |
| 627 | } |
| 628 | |
| 629 | if file.Props != nil && dstMap[file.FileChildren][0].OwnerID == file.OwnerID { |
| 630 | stm.SetProps(file.Props) |
| 631 | } |
| 632 | |
| 633 | return stm |
| 634 | }) |
| 635 | |
| 636 | metadataStm := []*ent.MetadataCreate{} |
| 637 | entityStm := []*ent.EntityUpdate{} |
| 638 | newDstMap := make(map[int][]*ent.File, len(files)) |
| 639 | sizeDiff := int64(0) |
| 640 | for index, stm := range copyFileStm { |
| 641 | newFile, err := stm.Save(ctx) |
| 642 | if err != nil { |
| 643 | return nil, nil, fmt.Errorf("failed to copy file: %w", err) |
| 644 | } |
| 645 | |
| 646 | fileMetadata, err := files[index].Edges.MetadataOrErr() |
| 647 | if err != nil { |
| 648 | return nil, nil, fmt.Errorf("failed to get metadata of file: %w", err) |
| 649 | } |
| 650 | |
| 651 | metadataStm = append(metadataStm, lo.FilterMap(fileMetadata, func(metadata *ent.Metadata, index int) (*ent.MetadataCreate, bool) { |
| 652 | if lo.Contains(args.ExcludedMetadataKeys, metadata.Name) { |
| 653 | return nil, false |
| 654 | } |
| 655 | return f.client.Metadata.Create(). |
| 656 | SetName(metadata.Name). |
| 657 | SetValue(metadata.Value). |
| 658 | SetFile(newFile). |
| 659 | SetIsPublic(metadata.IsPublic), true |
| 660 | })...) |
| 661 | |
| 662 | fileEntities, err := files[index].Edges.EntitiesOrErr() |
| 663 | if err != nil { |
| 664 | return nil, nil, fmt.Errorf("failed to get entities of file: %w", err) |
| 665 | } |
nothing calls this directly
no test coverage detected