Skip to content

Commit

Permalink
style(general): minor followups to #3041 (#3141)
Browse files Browse the repository at this point in the history
* explicitly pass username and hostname instead of repo writer
* nit: name return values
  • Loading branch information
julio-lopez committed Jul 12, 2023
1 parent 851fe6c commit c017d26
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions cli/command_snapshot_create.go
Expand Up @@ -448,30 +448,26 @@ func shouldSnapshotSource(ctx context.Context, src snapshot.SourceInfo, rep repo
!policy.IsManualSnapshot(policyTree), nil
}

func (c *commandSnapshotCreate) getContentToSnapshot(ctx context.Context, dir string, rep repo.RepositoryWriter) (fs.Entry, snapshot.SourceInfo, bool, error) {
var (
absDir string
sourceInfo snapshot.SourceInfo
fsEntry fs.Entry
setManual bool
err error
)
// the setManual return value is true when a snapshot is manually created, such
// as when overriding the source info or snapshotting from stdin.
func (c *commandSnapshotCreate) getContentToSnapshot(ctx context.Context, dir string, rep repo.RepositoryWriter) (fsEntry fs.Entry, info snapshot.SourceInfo, setManual bool, err error) {
var absDir string

absDir, err = filepath.Abs(dir)
if err != nil {
return nil, sourceInfo, false, errors.Wrapf(err, "invalid source %v", dir)
return nil, info, false, errors.Wrapf(err, "invalid source %v", dir)
}

if c.sourceOverride != "" {
sourceInfo, err = parseFullSource(c.sourceOverride, rep)
info, err = parseFullSource(c.sourceOverride, rep.ClientOptions().Hostname, rep.ClientOptions().Username)

if err != nil {
return nil, sourceInfo, false, errors.Wrapf(err, "invalid source override %v", c.sourceOverride)
return nil, info, false, errors.Wrapf(err, "invalid source override %v", c.sourceOverride)
}

setManual = true
} else {
sourceInfo = snapshot.SourceInfo{
info = snapshot.SourceInfo{
Path: filepath.Clean(absDir),
Host: rep.ClientOptions().Hostname,
UserName: rep.ClientOptions().Username,
Expand All @@ -488,15 +484,15 @@ func (c *commandSnapshotCreate) getContentToSnapshot(ctx context.Context, dir st
} else {
fsEntry, err = getLocalFSEntry(ctx, absDir)
if err != nil {
return nil, sourceInfo, false, errors.Wrap(err, "unable to get local filesystem entry")
return nil, info, false, errors.Wrap(err, "unable to get local filesystem entry")
}
}

return fsEntry, sourceInfo, setManual, nil
return fsEntry, info, setManual, nil
}

func parseFullSource(str string, rep repo.RepositoryWriter) (snapshot.SourceInfo, error) {
sourceInfo, err := snapshot.ParseSourceInfo(str, rep.ClientOptions().Hostname, rep.ClientOptions().Username)
func parseFullSource(str, hostname, username string) (snapshot.SourceInfo, error) {
sourceInfo, err := snapshot.ParseSourceInfo(str, hostname, username)

if err != nil {
return snapshot.SourceInfo{}, errors.Wrapf(err, "not a valid source %v", str)
Expand Down

0 comments on commit c017d26

Please sign in to comment.