Run compares files, plans necessary s5cmd commands to execute and executes them in order to sync source to destination.
(c *cli.Context)
| 170 | // Run compares files, plans necessary s5cmd commands to execute |
| 171 | // and executes them in order to sync source to destination. |
| 172 | func (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 | }() |
no test coverage detected