MCPcopy Index your code
hub / github.com/kopia/kopia / snapshotSingleSource

Method snapshotSingleSource

cli/command_snapshot_create.go:284–390  ·  view source on GitHub ↗

nolint:gocyclo,funlen

(
	ctx context.Context,
	fsEntry fs.Entry,
	setManual bool,
	rep repo.RepositoryWriter,
	u *upload.Uploader,
	sourceInfo snapshot.SourceInfo,
	tags map[string]string,
	st *notifydata.MultiSnapshotStatus,
)

Source from the content-addressed store, hash-verified

282
283//nolint:gocyclo,funlen
284func (c *commandSnapshotCreate) snapshotSingleSource(
285 ctx context.Context,
286 fsEntry fs.Entry,
287 setManual bool,
288 rep repo.RepositoryWriter,
289 u *upload.Uploader,
290 sourceInfo snapshot.SourceInfo,
291 tags map[string]string,
292 st *notifydata.MultiSnapshotStatus,
293) (finalErr error) {
294 log(ctx).Infof("Snapshotting %v ...", sourceInfo)
295
296 var mwe notifydata.ManifestWithError
297
298 mwe.Manifest.Source = sourceInfo
299
300 st.Snapshots = append(st.Snapshots, &mwe)
301
302 defer func() {
303 if finalErr != nil {
304 mwe.Error = finalErr.Error()
305 }
306 }()
307
308 var previous []*snapshot.Manifest
309
310 previous, finalErr = snapshot.FindPreviousManifests(ctx, rep, sourceInfo, nil)
311 if finalErr != nil {
312 return errors.Wrap(finalErr, "unable to find previous manifests")
313 }
314
315 if len(previous) > 0 {
316 mwe.Previous = previous[0]
317 }
318
319 policyTree, finalErr := policy.TreeForSource(ctx, rep, sourceInfo)
320 if finalErr != nil {
321 return errors.Wrap(finalErr, "unable to get policy tree")
322 }
323
324 manifest, finalErr := u.Upload(ctx, fsEntry, policyTree, sourceInfo, previous...)
325 if finalErr != nil {
326 // fail-fast uploads will fail here without recording a manifest, other uploads will
327 // possibly fail later.
328 return errors.Wrap(finalErr, "upload error")
329 }
330
331 manifest.Description = c.snapshotCreateDescription
332 manifest.Tags = tags
333 manifest.UpdatePins(c.pins, nil)
334
335 startTimeOverride, _ := parseTimestamp(c.snapshotCreateStartTime)
336 endTimeOverride, _ := parseTimestamp(c.snapshotCreateEndTime)
337
338 if !startTimeOverride.IsZero() {
339 if endTimeOverride.IsZero() {
340 // Calculate the correct end time based on current duration if they're not specified
341 duration := manifest.EndTime.Sub(manifest.StartTime)

Callers 1

runMethod · 0.95

Calls 15

reportSnapshotStatusMethod · 0.95
FindPreviousManifestsFunction · 0.92
TreeForSourceFunction · 0.92
UTCTimestampFromTimeFunction · 0.92
SaveSnapshotFunction · 0.92
ApplyRetentionPolicyFunction · 0.92
SetManualFunction · 0.92
parseTimestampFunction · 0.85
UploadMethod · 0.80
UpdatePinsMethod · 0.80
SubMethod · 0.80
EffectivePolicyMethod · 0.80

Tested by

no test coverage detected