MCPcopy
hub / github.com/kopia/kopia / run

Method run

cli/command_snapshot_estimate.go:71–138  ·  view source on GitHub ↗
(ctx context.Context, rep repo.Repository)

Source from the content-addressed store, hash-verified

69}
70
71func (c *commandSnapshotEstimate) run(ctx context.Context, rep repo.Repository) error {
72 path, err := filepath.Abs(c.snapshotEstimateSource)
73 if err != nil {
74 return errors.Errorf("invalid path: '%s': %s", path, err)
75 }
76
77 sourceInfo := snapshot.SourceInfo{
78 Path: filepath.Clean(path),
79 Host: rep.ClientOptions().Hostname,
80 UserName: rep.ClientOptions().Username,
81 }
82
83 entry, err := getLocalFSEntry(ctx, path)
84 if err != nil {
85 return err
86 }
87
88 dir, ok := entry.(fs.Directory)
89 if !ok {
90 return errors.Errorf("invalid path: '%s': must be a directory", path)
91 }
92
93 var ep estimateProgress
94
95 ep.quiet = c.snapshotEstimateQuiet
96
97 policyTree, err := policy.TreeForSource(ctx, rep, sourceInfo)
98 if err != nil {
99 return errors.Wrapf(err, "error creating policy tree for %v", sourceInfo)
100 }
101
102 if err := upload.Estimate(ctx, dir, policyTree, &ep, c.maxExamplesPerBucket); err != nil {
103 return errors.Wrap(err, "error estimating")
104 }
105
106 c.out.printStdout("Snapshot includes %v file(s), total size %v\n", ep.stats.TotalFileCount, units.BytesString(ep.stats.TotalFileSize))
107 c.showBuckets(ep.included, c.snapshotEstimateShowFiles)
108 c.out.printStdout("\n")
109
110 if ep.stats.ExcludedFileCount > 0 {
111 c.out.printStdout("Snapshot excludes %v file(s), total size %v\n", ep.stats.ExcludedFileCount, units.BytesString(ep.stats.ExcludedTotalFileSize))
112 c.showBuckets(ep.excluded, true)
113 } else {
114 c.out.printStdout("Snapshot excludes no files.\n")
115 }
116
117 if ep.stats.ExcludedDirCount > 0 {
118 c.out.printStdout("Snapshot excludes %v directories. Examples:\n", ep.stats.ExcludedDirCount)
119
120 for _, ed := range ep.excludedDirs {
121 c.out.printStdout(" - %v\n", ed)
122 }
123 } else {
124 c.out.printStdout("Snapshot excludes no directories.\n")
125 }
126
127 if ep.stats.ErrorCount > 0 {
128 c.out.printStdout("Encountered %v error(s).\n", ep.stats.ErrorCount)

Callers

nothing calls this directly

Calls 9

showBucketsMethod · 0.95
TreeForSourceFunction · 0.92
EstimateFunction · 0.92
BytesStringFunction · 0.92
getLocalFSEntryFunction · 0.85
ErrorfMethod · 0.80
printStdoutMethod · 0.80
ClientOptionsMethod · 0.65
DurationMethod · 0.45

Tested by

no test coverage detected