MCPcopy Index your code
hub / github.com/peak/s5cmd / Run

Method Run

command/sync.go:172–239  ·  view source on GitHub ↗

Run compares files, plans necessary s5cmd commands to execute and executes them in order to sync source to destination.

(c *cli.Context)

Source from the content-addressed store, hash-verified

170// Run compares files, plans necessary s5cmd commands to execute
171// and executes them in order to sync source to destination.
172func (s Sync) Run(c *cli.Context) error {
173 srcurl, err := url.New(s.src, url.WithRaw(s.raw))
174 if err != nil {
175 return err
176 }
177
178 dsturl, err := url.New(s.dst, url.WithRaw(s.raw))
179 if err != nil {
180 return err
181 }
182
183 ctx, cancel := context.WithCancel(c.Context)
184
185 sourceObjects, destObjects, err := s.getSourceAndDestinationObjects(ctx, cancel, srcurl, dsturl)
186 if err != nil {
187 printError(s.fullCommand, s.op, err)
188 return err
189 }
190
191 isBatch := srcurl.IsWildcard()
192 if !isBatch && !srcurl.IsRemote() {
193 sourceClient, err := storage.NewClient(ctx, srcurl, s.storageOpts)
194 if err != nil {
195 return err
196 }
197
198 obj, err := sourceClient.Stat(ctx, srcurl)
199 if err != nil {
200 return err
201 }
202
203 isBatch = obj != nil && obj.Type.IsDir()
204 }
205
206 onlySource, onlyDest, commonObjects := compareObjects(sourceObjects, destObjects, isBatch)
207
208 sourceObjects = nil
209 destObjects = nil
210
211 waiter := parallel.NewWaiter()
212 var (
213 merrorWaiter error
214 errDoneCh = make(chan struct{})
215 )
216
217 go func() {
218 defer close(errDoneCh)
219 for err := range waiter.Err() {
220 if strings.Contains(err.Error(), "too many open files") {
221 fmt.Println(strings.TrimSpace(fdlimitWarning))
222 fmt.Printf("ERROR %v\n", err)
223
224 os.Exit(1)
225 }
226 printError(s.fullCommand, s.op, err)
227 merrorWaiter = multierror.Append(merrorWaiter, err)
228 }
229 }()

Callers 1

NewSyncCommandFunction · 0.45

Calls 15

ErrMethod · 0.95
planRunMethod · 0.95
NewFunction · 0.92
WithRawFunction · 0.92
NewClientFunction · 0.92
NewWaiterFunction · 0.92
printErrorFunction · 0.85
compareObjectsFunction · 0.85
NewStrategyFunction · 0.85
NewRunFunction · 0.85
IsWildcardMethod · 0.80

Tested by

no test coverage detected