Esempio n. 1
0
func Search(searchSpec *utils.SpecFiles, flags *SearchFlags) (result []SearchResult, err error) {
	err = utils.PreCommandSetup(flags)
	if err != nil {
		return
	}

	var resultItems []utils.AqlSearchResultItem
	var itemsFound []utils.AqlSearchResultItem

	log.Info("Searching artifacts...")
	for i := 0; i < len(searchSpec.Files); i++ {
		switch searchSpec.Get(i).GetSpecType() {
		case utils.WILDCARD, utils.SIMPLE:
			isRecursive, e := cliutils.StringToBool(searchSpec.Get(i).Recursive, true)
			if e != nil {
				err = e
				return
			}
			itemsFound, e = utils.AqlSearchDefaultReturnFields(searchSpec.Get(i).Pattern,
				isRecursive, searchSpec.Get(i).Props, flags)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, itemsFound...)
		case utils.AQL:
			itemsFound, err = utils.AqlSearchBySpec(searchSpec.Get(i).Aql, flags)
			if err != nil {
				return
			}
			resultItems = append(resultItems, itemsFound...)
		}
	}

	result = aqlResultToSearchResult(resultItems)
	utils.LogSearchResults(len(resultItems))
	return
}
Esempio n. 2
0
func Download(downloadSpec *utils.SpecFiles, flags *DownloadFlags) (err error) {
	err = utils.PreCommandSetup(flags)
	if err != nil {
		return
	}

	isCollectBuildInfo := len(flags.BuildName) > 0 && len(flags.BuildNumber) > 0
	if isCollectBuildInfo && !flags.DryRun {
		if err = utils.SaveBuildGeneralDetails(flags.BuildName, flags.BuildNumber); err != nil {
			return
		}
	}
	if !flags.DryRun {
		err = ioutils.CreateTempDirPath()
		if err != nil {
			return
		}
		defer ioutils.RemoveTempDir()
	}

	buildDependecies := make([][]utils.DependenciesBuildInfo, flags.Threads)
	log.Info("Searching artifacts...")
	var downloadData []DownloadData
	for i := 0; i < len(downloadSpec.Files); i++ {
		var partialDownloadData []DownloadData
		switch downloadSpec.Get(i).GetSpecType() {
		case utils.WILDCARD, utils.SIMPLE:
			partialDownloadData, err = collectWildcardDependecies(downloadSpec.Get(i), flags)
		case utils.AQL:
			partialDownloadData, err = collectAqlDependecies(downloadSpec.Get(i), flags)
		}
		if err != nil {
			return
		}
		downloadData = append(downloadData, partialDownloadData...)
	}
	utils.LogSearchResults(len(downloadData))
	buildDependecies, err = downloadAqlResult(downloadData, flags)
	if err != nil {
		return
	}
	if isCollectBuildInfo && !flags.DryRun {
		populateFunc := func(tempWrapper *utils.ArtifactBuildInfoWrapper) {
			tempWrapper.Dependencies = stripThreadIdFromBuildInfoDependencies(buildDependecies)
		}
		err = utils.PrepareBuildInfoForSave(flags.BuildName, flags.BuildNumber, populateFunc)
	}
	return
}
Esempio n. 3
0
func GetPathsToDelete(deleteSpec *utils.SpecFiles, flags *DeleteFlags) (resultItems []utils.AqlSearchResultItem, err error) {
	log.Info("Searching artifacts...")
	for i := 0; i < len(deleteSpec.Files); i++ {
		var isDirectoryDeleteBool bool
		isSimpleDirectoryDeleteBool, e := isSimpleDirectoryDelete(deleteSpec.Get(i))
		if e != nil {
			err = e
			return
		}
		if !isSimpleDirectoryDeleteBool {
			isDirectoryDeleteBool, e = isDirectoryDelete(deleteSpec.Get(i))
			if e != nil {
				err = e
				return
			}
		}
		switch {
		case deleteSpec.Get(i).GetSpecType() == utils.AQL:
			resultItemsTemp, e := utils.AqlSearchBySpec(deleteSpec.Get(i).Aql, flags)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, resultItemsTemp...)

		case isSimpleDirectoryDeleteBool:
			simplePathItem := utils.AqlSearchResultItem{Path: deleteSpec.Get(i).Pattern}
			resultItems = append(resultItems, []utils.AqlSearchResultItem{simplePathItem}...)

		case isDirectoryDeleteBool:
			tempResultItems, e := utils.AqlSearchDefaultReturnFields(deleteSpec.Get(i).Pattern, true, "", flags)
			if e != nil {
				err = e
				return
			}
			paths, e := getDirsForDeleteFromFilesPaths(deleteSpec.Get(i).Pattern, tempResultItems)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, paths...)
		default:
			isRecursive, e := cliutils.StringToBool(deleteSpec.Get(i).Recursive, true)
			if e != nil {
				err = e
				return
			}
			tempResultItems, e := utils.AqlSearchDefaultReturnFields(deleteSpec.Get(i).Pattern,
				isRecursive, deleteSpec.Get(i).Props, flags)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, tempResultItems...)
		}
	}
	utils.LogSearchResults(len(resultItems))
	return
}