MCPcopy
hub / github.com/rclone/rclone / put

Method put

backend/crypt/crypt.go:497–563  ·  view source on GitHub ↗

put implements Put or PutStream

(ctx context.Context, in io.Reader, src fs.ObjectInfo, options []fs.OpenOption, put putFn)

Source from the content-addressed store, hash-verified

495
496// put implements Put or PutStream
497func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options []fs.OpenOption, put putFn) (fs.Object, error) {
498 ci := fs.GetConfig(ctx)
499
500 if f.opt.NoDataEncryption {
501 o, err := put(ctx, in, f.newObjectInfo(src, nonce{}), options...)
502 if err == nil && o != nil {
503 o = f.newObject(o)
504 }
505 return o, err
506 }
507
508 // Encrypt the data into wrappedIn
509 wrappedIn, encrypter, err := f.cipher.encryptData(in)
510 if err != nil {
511 return nil, err
512 }
513
514 // Find a hash the destination supports to compute a hash of
515 // the encrypted data
516 ht := f.Fs.Hashes().GetOne()
517 if ci.IgnoreChecksum {
518 ht = hash.None
519 }
520 var hasher *hash.MultiHasher
521 if ht != hash.None {
522 hasher, err = hash.NewMultiHasherTypes(hash.NewHashSet(ht))
523 if err != nil {
524 return nil, err
525 }
526 // unwrap the accounting
527 var wrap accounting.WrapFn
528 wrappedIn, wrap = accounting.UnWrap(wrappedIn)
529 // add the hasher
530 wrappedIn = io.TeeReader(wrappedIn, hasher)
531 // wrap the accounting back on
532 wrappedIn = wrap(wrappedIn)
533 }
534
535 // Transfer the data
536 o, err := put(ctx, wrappedIn, f.newObjectInfo(src, encrypter.nonce), options...)
537 if err != nil {
538 return nil, err
539 }
540
541 // Check the hashes of the encrypted data if we were comparing them
542 if ht != hash.None && hasher != nil {
543 srcHash := hasher.Sums()[ht]
544 var dstHash string
545 dstHash, err = o.Hash(ctx, ht)
546 if err != nil {
547 return nil, fmt.Errorf("failed to read destination hash: %w", err)
548 }
549 if srcHash != "" && dstHash != "" {
550 if srcHash != dstHash {
551 // remove object
552 err = o.Remove(ctx)
553 if err != nil {
554 fs.Errorf(o, "Failed to remove corrupted object: %v", err)

Callers 3

PutMethod · 0.95
PutStreamMethod · 0.95
UpdateMethod · 0.45

Calls 15

newObjectInfoMethod · 0.95
newObjectMethod · 0.95
SumsMethod · 0.95
GetConfigFunction · 0.92
NewMultiHasherTypesFunction · 0.92
NewHashSetFunction · 0.92
UnWrapFunction · 0.92
ErrorfFunction · 0.92
DebugfFunction · 0.92
wrapFunction · 0.85
encryptDataMethod · 0.80
GetOneMethod · 0.80

Tested by

no test coverage detected