MCPcopy
hub / github.com/rclone/rclone / Update

Method Update

backend/b2/b2.go:2143–2313  ·  view source on GitHub ↗

Update the object with the contents of the io.Reader, modTime and size The new object may have been created if an error is returned

(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

2141//
2142// The new object may have been created if an error is returned
2143func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) {
2144 if o.fs.opt.Versions {
2145 return errNotWithVersions
2146 }
2147 if o.fs.opt.VersionAt.IsSet() {
2148 return errNotWithVersionAt
2149 }
2150 size := src.Size()
2151
2152 bucket, bucketPath := o.split()
2153 err = o.fs.makeBucket(ctx, bucket)
2154 if err != nil {
2155 return err
2156 }
2157 if size < 0 {
2158 // Check if the file is large enough for a chunked upload (needs to be at least two chunks)
2159 rw := o.fs.getRW(false)
2160
2161 n, err := io.CopyN(rw, in, int64(o.fs.opt.ChunkSize))
2162 if err == nil {
2163 bufReader := bufio.NewReader(in)
2164 in = bufReader
2165 _, err = bufReader.Peek(1)
2166 }
2167
2168 if err == nil {
2169 fs.Debugf(o, "File is big enough for chunked streaming")
2170 up, err := o.fs.newLargeUpload(ctx, o, in, src, o.fs.opt.ChunkSize, false, nil, options...)
2171 if err != nil {
2172 o.fs.putRW(rw)
2173 return err
2174 }
2175 // NB Stream returns the buffer and token
2176 err = up.Stream(ctx, rw)
2177 if err != nil {
2178 return err
2179 }
2180 return o.decodeMetaDataFileInfo(up.info)
2181 } else if err == io.EOF {
2182 fs.Debugf(o, "File has %d bytes, which makes only one chunk. Using direct upload.", n)
2183 defer o.fs.putRW(rw)
2184 size = n
2185 in = rw
2186 } else {
2187 o.fs.putRW(rw)
2188 return err
2189 }
2190 } else if size > int64(o.fs.opt.UploadCutoff) {
2191 chunkWriter, err := multipart.UploadMultipart(ctx, src, in, multipart.UploadMultipartOptions{
2192 Open: o.fs,
2193 OpenOptions: options,
2194 })
2195 if err != nil {
2196 return err
2197 }
2198 up := chunkWriter.(*largeUpload)
2199 return o.decodeMetaDataFileInfo(up.info)
2200 }

Callers 1

PutMethod · 0.95

Calls 15

splitMethod · 0.95
getModTimeMethod · 0.95
DebugfFunction · 0.92
UploadMultipartFunction · 0.92
MimeTypeFunction · 0.92
newHashAppendingReaderFunction · 0.85
timeStringFunction · 0.85
getRWMethod · 0.80
putRWMethod · 0.80
StreamMethod · 0.80
AdditionalLengthMethod · 0.80

Tested by

no test coverage detected