Ejemplo n.º 1
0
func updateCollection(steplibSource string) (models.StepCollectionModel, error) {
	route, found := stepman.ReadRoute(steplibSource)
	if !found {
		log.Warnf("No route found for collection: %s, cleaning up routing..", steplibSource)
		if err := stepman.CleanupDanglingLib(steplibSource); err != nil {
			log.Errorf("Error cleaning up lib: %s", steplibSource)
		}
		log.Infof("Call 'stepman setup -c %s' for a clean setup", steplibSource)
		return models.StepCollectionModel{}, fmt.Errorf("No route found for StepLib: %s", steplibSource)
	}

	isLocalSteplib := strings.HasPrefix(steplibSource, "file://")

	if isLocalSteplib {
		if err := stepman.CleanupRoute(route); err != nil {
			return models.StepCollectionModel{}, fmt.Errorf("Failed to cleanup route for StepLib: %s", steplibSource)
		}

		if err := setupSteplib(steplibSource, false); err != nil {
			return models.StepCollectionModel{}, fmt.Errorf("Failed to setup StepLib: %s", steplibSource)
		}
	} else {
		pth := stepman.GetCollectionBaseDirPath(route)
		if exists, err := pathutil.IsPathExists(pth); err != nil {
			return models.StepCollectionModel{}, err
		} else if !exists {
			return models.StepCollectionModel{}, errors.New("Not initialized")
		}

		gitPullErr := retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error {
			if attempt > 0 {
				log.Infoln("Retrying ...")
			}
			return cmdex.GitPull(pth)
		})
		if gitPullErr != nil {
			return models.StepCollectionModel{}, fmt.Errorf("Failed to update StepLib git repository, error: %s", gitPullErr)
		}

		if err := stepman.ReGenerateStepSpec(route); err != nil {
			return models.StepCollectionModel{}, err
		}
	}

	return stepman.ReadStepSpec(steplibSource)
}
Ejemplo n.º 2
0
func updateCollection(steplibSource string) (models.StepCollectionModel, error) {
	route, found := stepman.ReadRoute(steplibSource)
	if !found {
		return models.StepCollectionModel{},
			fmt.Errorf("No collection found for lib, call 'stepman delete -c %s' for cleanup", steplibSource)
	}

	pth := stepman.GetCollectionBaseDirPath(route)
	if exists, err := pathutil.IsPathExists(pth); err != nil {
		return models.StepCollectionModel{}, err
	} else if !exists {
		return models.StepCollectionModel{}, errors.New("Not initialized")
	}

	if err := cmdex.GitPull(pth); err != nil {
		return models.StepCollectionModel{}, err
	}

	if err := stepman.ReGenerateStepSpec(route); err != nil {
		return models.StepCollectionModel{}, err
	}

	return stepman.ReadStepSpec(steplibSource)
}