plan figures out which files need to be uploaded.
(ctx context.Context)
| 180 | |
| 181 | // plan figures out which files need to be uploaded. |
| 182 | func (d *Deployer) plan(ctx context.Context) error { |
| 183 | remoteFiles, err := d.store.FileMap(ctx) |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | d.printf("Found %d remote files\n", len(remoteFiles)) |
| 188 | |
| 189 | // All local files at sourcePath |
| 190 | localFiles := make(chan *osFile) |
| 191 | d.g.Go(func() error { |
| 192 | return d.walk(ctx, d.cfg.SourcePath, localFiles) |
| 193 | }) |
| 194 | |
| 195 | for f := range localFiles { |
| 196 | // default: upload because local file not found on remote. |
| 197 | up := true |
| 198 | reason := reasonNotFound |
| 199 | |
| 200 | bucketPath := f.keyPath |
| 201 | if d.cfg.BucketPath != "" { |
| 202 | bucketPath = pathJoin(d.cfg.BucketPath, bucketPath) |
| 203 | } |
| 204 | |
| 205 | if remoteFile, ok := remoteFiles[bucketPath]; ok { |
| 206 | if d.cfg.Force { |
| 207 | up = true |
| 208 | reason = reasonForce |
| 209 | } else { |
| 210 | up, reason = f.shouldThisReplace(remoteFile) |
| 211 | } |
| 212 | // remove from map, whatever is leftover should be deleted: |
| 213 | delete(remoteFiles, bucketPath) |
| 214 | } |
| 215 | |
| 216 | f.reason = reason |
| 217 | |
| 218 | if up { |
| 219 | d.enqueueUpload(ctx, f) |
| 220 | } else { |
| 221 | d.skipFile(f) |
| 222 | } |
| 223 | } |
| 224 | close(d.filesToUpload) |
| 225 | |
| 226 | // any remote files not found locally should be removed: |
| 227 | // except for ignored files |
| 228 | for key := range remoteFiles { |
| 229 | if d.cfg.shouldIgnoreRemote(key) { |
| 230 | d.printf("%s ignored …\n", key) |
| 231 | continue |
| 232 | } |
| 233 | d.enqueueDelete(key) |
| 234 | } |
| 235 | |
| 236 | return nil |
| 237 | } |
| 238 | |
| 239 | // walk a local directory |
no test coverage detected