예제 #1
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
}
예제 #2
0
func collectWildcardDependecies(fileSpec *utils.Files, flags *DownloadFlags) ([]DownloadData, error) {
	isRecursive, err := cliutils.StringToBool(fileSpec.Recursive, true)
	if err != nil {
		return nil, err
	}

	resultItems, err := utils.AqlSearchDefaultReturnFields(fileSpec.Pattern, isRecursive, fileSpec.Props, flags)
	if err != nil {
		return nil, err
	}

	return createDownloadDataList(resultItems, fileSpec)
}
예제 #3
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
}