MCPcopy
hub / github.com/rclone/rclone / ArchiveCreate

Function ArchiveCreate

cmd/archive/create/create.go:298–388  ·  view source on GitHub ↗

ArchiveCreate - compresses/archive source to destination

(ctx context.Context, dst fs.Fs, dstFile string, src fs.Fs, format string, prefix string)

Source from the content-addressed store, hash-verified

296
297// ArchiveCreate - compresses/archive source to destination
298func ArchiveCreate(ctx context.Context, dst fs.Fs, dstFile string, src fs.Fs, format string, prefix string) error {
299 var err error
300 var list archivesFileInfoList
301 var compArchive archives.CompressedArchive
302 var totalLength int64
303
304 // check id dst is valid
305 err = CheckValidDestination(ctx, dst, dstFile)
306 if err != nil {
307 return err
308 }
309
310 ci := fs.GetConfig(ctx)
311 fi := filter.GetConfig(ctx)
312 // get archive format
313 compArchive, err = getCompressor(format, dstFile)
314 if err != nil {
315 return err
316 }
317 // get source files
318 err = walk.ListR(ctx, src, "", false, ci.MaxDepth, walk.ListAll, func(entries fs.DirEntries) error {
319 // get directories
320 entries.ForDir(func(o fs.Directory) {
321 var metadata fs.Metadata
322 if ci.Metadata {
323 metadata = loadMetadata(ctx, o)
324 }
325 if fi.Include(o.Remote(), o.Size(), o.ModTime(ctx), metadata) {
326 info := files.NewArchiveFileInfo(ctx, o, prefix, metadata)
327 list = append(list, info)
328 }
329 })
330 // get files
331 entries.ForObject(func(o fs.Object) {
332 var metadata fs.Metadata
333 if ci.Metadata {
334 metadata = loadMetadata(ctx, o)
335 }
336 if fi.Include(o.Remote(), o.Size(), o.ModTime(ctx), metadata) {
337 info := files.NewArchiveFileInfo(ctx, o, prefix, metadata)
338 list = append(list, info)
339 totalLength += o.Size()
340 }
341 })
342 return nil
343 })
344 if err != nil {
345 return err
346 } else if list.Len() == 0 {
347 return fmt.Errorf("no files found in source")
348 }
349 sort.Stable(list)
350 // create archive
351 if ci.DryRun {
352 // write nowhere
353 counter := files.NewCountWriter(nil)
354 err = compArchive.Archive(ctx, counter, list)
355 // log totals

Callers 2

testArchiveRemoteFunction · 0.92
create.goFile · 0.85

Calls 15

LenMethod · 0.95
CountMethod · 0.95
GetConfigFunction · 0.92
GetConfigFunction · 0.92
ListRFunction · 0.92
NewArchiveFileInfoFunction · 0.92
NewCountWriterFunction · 0.92
InfofFunction · 0.92
RcatFunction · 0.92
CheckValidDestinationFunction · 0.85
getCompressorFunction · 0.85
loadMetadataFunction · 0.85

Tested by 1

testArchiveRemoteFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…