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

Method getContentToSnapshot

cli/command_snapshot_create.go:460–498  ·  view source on GitHub ↗

the setManual return value is true when a snapshot is manually created, such as when overriding the source info or snapshotting from stdin.

(ctx context.Context, dir string, rep repo.RepositoryWriter)

Source from the content-addressed store, hash-verified

458// the setManual return value is true when a snapshot is manually created, such
459// as when overriding the source info or snapshotting from stdin.
460func (c *commandSnapshotCreate) getContentToSnapshot(ctx context.Context, dir string, rep repo.RepositoryWriter) (fsEntry fs.Entry, info snapshot.SourceInfo, setManual bool, err error) {
461 var absDir string
462
463 absDir, err = filepath.Abs(dir)
464 if err != nil {
465 return nil, info, false, errors.Wrapf(err, "invalid source %v", dir)
466 }
467
468 if c.sourceOverride != "" {
469 info, err = parseFullSource(c.sourceOverride, rep.ClientOptions().Hostname, rep.ClientOptions().Username)
470 if err != nil {
471 return nil, info, false, errors.Wrapf(err, "invalid source override %v", c.sourceOverride)
472 }
473
474 setManual = true
475 } else {
476 info = snapshot.SourceInfo{
477 Path: filepath.Clean(absDir),
478 Host: rep.ClientOptions().Hostname,
479 UserName: rep.ClientOptions().Username,
480 }
481 }
482
483 if c.snapshotCreateStdinFileName != "" {
484 // stdin source will be snapshotted using a virtual static root directory with a single streaming file entry
485 // Create a new static directory with the given name and add a streaming file entry with os.Stdin reader
486 fsEntry = virtualfs.NewStaticDirectory(absDir, []fs.Entry{
487 virtualfs.StreamingFileFromReader(c.snapshotCreateStdinFileName, io.NopCloser(c.svc.stdin())),
488 })
489 setManual = true
490 } else {
491 fsEntry, err = getLocalFSEntry(ctx, absDir)
492 if err != nil {
493 return nil, info, false, errors.Wrap(err, "unable to get local filesystem entry")
494 }
495 }
496
497 return fsEntry, info, setManual, nil
498}
499
500func parseFullSource(str, hostname, username string) (snapshot.SourceInfo, error) {
501 sourceInfo, err := snapshot.ParseSourceInfo(str, hostname, username)

Callers 1

runMethod · 0.95

Calls 6

NewStaticDirectoryFunction · 0.92
StreamingFileFromReaderFunction · 0.92
parseFullSourceFunction · 0.85
getLocalFSEntryFunction · 0.85
ClientOptionsMethod · 0.65
stdinMethod · 0.65

Tested by

no test coverage detected