MCPcopy Index your code
hub / github.com/rclone/rclone / Copy

Method Copy

backend/googlecloudstorage/googlecloudstorage.go:1135–1188  ·  view source on GitHub ↗

Copy src to this remote using server-side copy operations. This is stored with the remote path given. It returns the destination Object and a possible error. Will only be called if src.Fs().Name() == f.Name() If it isn't possible then return fs.ErrorCantCopy

(ctx context.Context, src fs.Object, remote string)

Source from the content-addressed store, hash-verified

1133//
1134// If it isn't possible then return fs.ErrorCantCopy
1135func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
1136 dstBucket, dstPath := f.split(remote)
1137 err := f.mkdirParent(ctx, remote)
1138 if err != nil {
1139 return nil, err
1140 }
1141 srcObj, ok := src.(*Object)
1142 if !ok {
1143 fs.Debugf(src, "Can't copy - not same remote type")
1144 return nil, fs.ErrorCantCopy
1145 }
1146 srcBucket, srcPath := srcObj.split()
1147
1148 // Temporary Object under construction
1149 dstObj := &Object{
1150 fs: f,
1151 remote: remote,
1152 }
1153
1154 // Set the storage class for the destination object if configured
1155 var dstObject *storage.Object
1156 if f.opt.StorageClass != "" {
1157 dstObject = &storage.Object{
1158 StorageClass: f.opt.StorageClass,
1159 }
1160 }
1161
1162 rewriteRequest := f.svc.Objects.Rewrite(srcBucket, srcPath, dstBucket, dstPath, dstObject)
1163 if !f.opt.BucketPolicyOnly {
1164 rewriteRequest.DestinationPredefinedAcl(f.opt.ObjectACL)
1165 }
1166 var rewriteResponse *storage.RewriteResponse
1167 for {
1168 err = f.pacer.Call(func() (bool, error) {
1169 rewriteRequest = rewriteRequest.Context(ctx)
1170 if f.opt.UserProject != "" {
1171 rewriteRequest.UserProject(f.opt.UserProject)
1172 }
1173 rewriteResponse, err = rewriteRequest.Do()
1174 return shouldRetry(ctx, err)
1175 })
1176 if err != nil {
1177 return nil, err
1178 }
1179 if rewriteResponse.Done {
1180 break
1181 }
1182 rewriteRequest.RewriteToken(rewriteResponse.RewriteToken)
1183 fs.Debugf(dstObj, "Continuing rewrite %d bytes done", rewriteResponse.TotalBytesRewritten)
1184 }
1185 // Set the metadata for the new object while we have it
1186 dstObj.setMetaData(rewriteResponse.Resource)
1187 return dstObj, nil
1188}
1189
1190// Hashes returns the supported hash sets.
1191func (f *Fs) Hashes() hash.Set {

Callers

nothing calls this directly

Calls 7

splitMethod · 0.95
mkdirParentMethod · 0.95
setMetaDataMethod · 0.95
DebugfFunction · 0.92
shouldRetryFunction · 0.70
DoMethod · 0.65
CallMethod · 0.45

Tested by

no test coverage detected