| 276 | } |
| 277 | |
| 278 | func (b *bisyncRun) tryDownloadHash(ctx context.Context, o fs.DirEntry, hashVal string) (string, error) { |
| 279 | if hashVal != "" || !b.downloadHashOpt.downloadHash { |
| 280 | return hashVal, nil |
| 281 | } |
| 282 | obj, ok := o.(fs.Object) |
| 283 | if !ok { |
| 284 | fs.Infof(o, "failed to download hash -- not an fs.Object") |
| 285 | return hashVal, fs.ErrorObjectNotFound |
| 286 | } |
| 287 | if o.Size() < 0 { |
| 288 | b.downloadHashOpt.downloadHashWarn.Do(func() { |
| 289 | fs.Log(o, Color(terminal.YellowFg, "Skipping hash download as checksum not reliable with files of unknown length.")) |
| 290 | }) |
| 291 | fs.Debugf(o, "Skipping hash download as checksum not reliable with files of unknown length.") |
| 292 | return hashVal, hash.ErrUnsupported |
| 293 | } |
| 294 | |
| 295 | b.downloadHashOpt.firstDownloadHash.Do(func() { |
| 296 | fs.Infoc(obj.Fs().Name(), Color(terminal.Dim, "Downloading hashes...")) |
| 297 | }) |
| 298 | tr := accounting.Stats(ctx).NewCheckingTransfer(o, "computing hash with --download-hash") |
| 299 | defer func() { |
| 300 | tr.Done(ctx, nil) |
| 301 | }() |
| 302 | |
| 303 | sum, err := operations.HashSum(ctx, hash.MD5, false, true, obj) |
| 304 | if err != nil { |
| 305 | fs.Infof(o, "DownloadHash -- hash: %v, err: %v", sum, err) |
| 306 | } else { |
| 307 | fs.Debugf(o, "DownloadHash -- hash: %v", sum) |
| 308 | } |
| 309 | return sum, err |
| 310 | } |