(svc advancedAppServices, parent commandParent)
| 39 | } |
| 40 | |
| 41 | func (c *commandRepositorySyncTo) setup(svc advancedAppServices, parent commandParent) { |
| 42 | cmd := parent.Command("sync-to", "Synchronizes the contents of this repository to another location") |
| 43 | cmd.Flag("update", "Whether to update blobs present in destination and source if the source is newer.").Default("true").BoolVar(&c.repositorySyncUpdate) |
| 44 | cmd.Flag("delete", "Whether to delete blobs present in destination but not source.").BoolVar(&c.repositorySyncDelete) |
| 45 | cmd.Flag("dry-run", "Do not perform copying.").Short('n').BoolVar(&c.repositorySyncDryRun) |
| 46 | cmd.Flag("parallel", "Copy parallelism.").Default("1").IntVar(&c.repositorySyncParallelism) |
| 47 | cmd.Flag("must-exist", "Fail if destination does not have repository format blob.").BoolVar(&c.repositorySyncDestinationMustExist) |
| 48 | cmd.Flag("times", "Synchronize blob times if supported.").BoolVar(&c.repositorySyncTimes) |
| 49 | |
| 50 | c.out.setup(svc) |
| 51 | c.progress = svc.getProgress() |
| 52 | |
| 53 | for _, prov := range svc.storageProviders() { |
| 54 | // Set up 'sync-to' subcommand |
| 55 | f := prov.NewFlags() |
| 56 | cc := cmd.Command(prov.Name, "Synchronize repository data to another repository in "+prov.Description) |
| 57 | f.Setup(svc, cc) |
| 58 | cc.Action(func(kpc *kingpin.ParseContext) error { |
| 59 | return svc.runAppWithContext(kpc.SelectedCommand, func(ctx context.Context) error { |
| 60 | st, err := f.Connect(ctx, false, 0) |
| 61 | if err != nil { |
| 62 | return errors.Wrap(err, "can't connect to storage") |
| 63 | } |
| 64 | |
| 65 | rep, err := svc.openRepository(ctx, true) |
| 66 | if err != nil { |
| 67 | return errors.Wrap(err, "open repository") |
| 68 | } |
| 69 | |
| 70 | defer rep.Close(ctx) //nolint:errcheck |
| 71 | |
| 72 | dr, ok := rep.(repo.DirectRepository) |
| 73 | if !ok { |
| 74 | return errors.New("sync only supports directly-connected repositories") |
| 75 | } |
| 76 | |
| 77 | return c.runSyncWithStorage(ctx, dr.BlobReader(), st) |
| 78 | }) |
| 79 | }) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | const syncProgressInterval = 300 * time.Millisecond |
| 84 |
nothing calls this directly
no test coverage detected