(ctx context.Context, src blob.Reader, dst blob.Storage)
| 83 | const syncProgressInterval = 300 * time.Millisecond |
| 84 | |
| 85 | func (c *commandRepositorySyncTo) runSyncWithStorage(ctx context.Context, src blob.Reader, dst blob.Storage) error { |
| 86 | log(ctx).Info("Synchronizing repositories:") |
| 87 | log(ctx).Infof(" Source: %v", src.DisplayName()) |
| 88 | log(ctx).Infof(" Destination: %v", dst.DisplayName()) |
| 89 | |
| 90 | if !c.repositorySyncDelete { |
| 91 | log(ctx).Info("NOTE: By default no BLOBs are deleted, pass --delete to allow it.") |
| 92 | } |
| 93 | |
| 94 | if err := c.ensureRepositoriesHaveSameFormatBlob(ctx, src, dst); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | log(ctx).Info("Looking for BLOBs to synchronize...") |
| 99 | |
| 100 | var ( |
| 101 | inSyncBlobs int |
| 102 | inSyncBytes int64 |
| 103 | |
| 104 | blobsToCopy []blob.Metadata |
| 105 | totalCopyBytes int64 |
| 106 | |
| 107 | blobsToDelete []blob.Metadata |
| 108 | totalDeleteBytes int64 |
| 109 | |
| 110 | srcBlobs int |
| 111 | totalSrcSize int64 |
| 112 | ) |
| 113 | |
| 114 | dstMetadata, err := c.listDestinationBlobs(ctx, dst) |
| 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | |
| 119 | c.beginSyncProgress() |
| 120 | |
| 121 | if err := src.ListBlobs(ctx, "", func(srcmd blob.Metadata) error { |
| 122 | totalSrcSize += srcmd.Length |
| 123 | |
| 124 | dstmd, exists := dstMetadata[srcmd.BlobID] |
| 125 | delete(dstMetadata, srcmd.BlobID) |
| 126 | |
| 127 | switch { |
| 128 | case !exists: |
| 129 | blobsToCopy = append(blobsToCopy, srcmd) |
| 130 | totalCopyBytes += srcmd.Length |
| 131 | case srcmd.Timestamp.After(dstmd.Timestamp) && c.repositorySyncUpdate: |
| 132 | blobsToCopy = append(blobsToCopy, srcmd) |
| 133 | totalCopyBytes += srcmd.Length |
| 134 | default: |
| 135 | inSyncBlobs++ |
| 136 | inSyncBytes += srcmd.Length |
| 137 | } |
| 138 | |
| 139 | srcBlobs++ |
| 140 | c.outputSyncProgress(fmt.Sprintf(" Found %v BLOBs (%v) in the source repository, %v (%v) to copy", srcBlobs, units.BytesString(totalSrcSize), len(blobsToCopy), units.BytesString(totalCopyBytes))) |
| 141 | |
| 142 | return nil |
no test coverage detected