diff --git a/internal/package_handler/package.go b/internal/package_handler/package.go index f3201eff..966b5866 100644 --- a/internal/package_handler/package.go +++ b/internal/package_handler/package.go @@ -190,6 +190,8 @@ func (p *PackageHandler) LatestVersion() (string, error) { return versions[len(versions)-1], nil } +// CommitPrecedence returns true if the new commit hash is a descendant of the +// old commit hash. It returns an error if the commit hashes are not found. func (p *PackageHandler) CommitPrecedence(oldCommitHash, newCommitHash string) (bool, error) { err := p.CheckoutCommit(newCommitHash) if err != nil { @@ -205,6 +207,7 @@ func (p *PackageHandler) CommitPrecedence(oldCommitHash, newCommitHash string) ( if err != nil { return false, err } + // Skip first commit, because it is the new commit hash itself _, err = commitIter.Next() if err != nil { if errors.Is(err, io.EOF) { diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 7c553b54..ac32ff7e 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -152,6 +152,10 @@ type PullResult struct { } type PullUpdateResult struct { + Name string + Tag string + Url string + Profile string // OldVersion is the version of the old package. OldVersion string @@ -174,7 +178,7 @@ type PullUpdateResult struct { NewOptions []Option // MergedOptions is the list of options of the new package merged with the - // old package. These options the ones that will be used for the new instance + // old package. These options are the ones that will be used for the new instance // and should be filled by the user. MergedOptions []Option @@ -187,6 +191,10 @@ type InstallOptions struct { // Name is the name of the AVS represented by the package. Name string + // Tag is the tag to use for the instance, required to build the instance id + // with the format - + Tag string + // URL is the URL of the git repository containing the node software package. URL string @@ -207,10 +215,6 @@ type InstallOptions struct { // Options is the list of options to use for the instance. Options []Option - - // Tag is the tag to use for the instance, required to build the instance id - // with the format - - Tag string } // LocalInstallOptions is a set of options for installing a node software package diff --git a/pkg/daemon/egn_daemon.go b/pkg/daemon/egn_daemon.go index 7cf2bbf7..5ef92235 100644 --- a/pkg/daemon/egn_daemon.go +++ b/pkg/daemon/egn_daemon.go @@ -339,6 +339,9 @@ func (d *EgnDaemon) Pull(url string, ref PullTarget, force bool) (result PullRes } func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (PullUpdateResult, error) { + if !d.dataDir.HasInstance(instanceID) { + return PullUpdateResult{}, fmt.Errorf("%w: %s", ErrInstanceNotFound, instanceID) + } pkgHandler, err := d.pullPackage(url, true) if err != nil { return PullUpdateResult{}, err @@ -419,7 +422,7 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P if v, ok := valuesOld[o.Target()]; ok { err := o.Set(v) if err != nil { - return PullUpdateResult{}, err + return PullUpdateResult{}, fmt.Errorf("error setting old option value: %v", err) } } else { return PullUpdateResult{}, fmt.Errorf("%w: old option %s", ErrOptionWithoutValue, o.Name()) @@ -432,6 +435,11 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P } return PullUpdateResult{ + Name: instance.Name, + Tag: instance.Tag, + Url: instance.URL, + Profile: instance.Profile, + HasPlugin: instance.Plugin != nil, OldVersion: instance.Version, NewVersion: newVersion, OldCommit: instance.Commit, @@ -442,7 +450,22 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P }, nil } +// mergeOptions merges the old options with the new ones following the next rules: +// +// 1. New option is not present in the old options: New option is added to the +// merged options without a value. +// +// 2. New option is present in the old options: +// +// 2.1: Old option value is valid for the new option: the new option is added +// to the merged options using the old option value. +// +// 2.2: Old option value is not valid for the new option: the new option is +// added to the merged options without a value and probably the user +// will need to fill it again or use its default value. func mergeOptions(oldOptions, newOptions []Option) ([]Option, error) { + // mergedOptions will contain the result of merging the new options with the + // old ones var mergedOptions []Option for _, oNew := range newOptions { var oOld Option diff --git a/pkg/daemon/error.go b/pkg/daemon/error.go index 19862010..7a54a539 100644 --- a/pkg/daemon/error.go +++ b/pkg/daemon/error.go @@ -6,6 +6,7 @@ var ( ErrInstanceAlreadyExists = errors.New("instance already exists") ErrProfileDoesNotExist = errors.New("profile does not exist") ErrInstanceNotRunning = errors.New("instance is not running") + ErrInstanceNotFound = errors.New("instance not found") ErrOptionWithoutValue = errors.New("option without value") ErrMonitoringTargetPortNotSet = errors.New("monitoring target port is not set") ErrInstanceHasNoPlugin = errors.New("instance has no plugin")