func fileOld(info os.FileInfo) bool {
	fileAge := time.Since(info.ModTime())
	days := 5
	hours := days * 24
	ageLimit := time.Duration(hours) * time.Hour
	return fileAge > ageLimit
}
fileOld returns true if the file is older than
the limit defined in the variable `days`
package process
import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"sort"
	"time"
	"github.com/1dustindavis/gorilla/pkg/catalog"
	"github.com/1dustindavis/gorilla/pkg/gorillalog"
	"github.com/1dustindavis/gorilla/pkg/installer"
	"github.com/1dustindavis/gorilla/pkg/manifest"
)
func firstItem(itemName string, catalogsMap map[int]map[string]catalog.Item) (catalog.Item, error) {
	keys := make([]int, 0)
	for k := range catalogsMap {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	for _, k := range keys {
		if item, exists := catalogsMap[k][itemName]; exists {
			validInstallItem := (item.Installer.Type != "" && item.Installer.Location != "")
			validUninstallItem := (item.Uninstaller.Type != "" && item.Uninstaller.Location != "")
			if validInstallItem || validUninstallItem {
				return item, nil
			}
		}
	}
	return catalog.Item{}, fmt.Errorf("did not find a valid item in any catalog; Item name: %v", itemName)
}
func Manifests(manifests []manifest.Item, catalogsMap map[int]map[string]catalog.Item) (installs, uninstalls, updates []string) {
	for _, manifestItem := range manifests {
		for _, item := range manifestItem.Installs {
			_, err := firstItem(item, catalogsMap)
			if err != nil {
				gorillalog.Warn(err)
				continue
			}
			installs = append(installs, item)
		}
		for _, item := range manifestItem.Uninstalls {
			_, err := firstItem(item, catalogsMap)
			if err != nil {
				gorillalog.Warn(err)
				continue
			}
			uninstalls = append(uninstalls, item)
		}
		for _, item := range manifestItem.Updates {
			_, err := firstItem(item, catalogsMap)
			if err != nil {
				gorillalog.Warn(err)
				continue
			}
			updates = append(updates, item)
		}
	}
	return
}
var installerInstall = installer.Install
func Installs(installs []string, catalogsMap map[int]map[string]catalog.Item, urlPackages, cachePath string, CheckOnly bool) {
	for _, item := range installs {
		validItem, err := firstItem(item, catalogsMap)
		if err != nil {
			gorillalog.Warn(err)
			continue
		}
		if len(validItem.Dependencies) > 0 {
			for _, dependency := range validItem.Dependencies {
				validDependency, err := firstItem(dependency, catalogsMap)
				if err != nil {
					gorillalog.Warn(err)
					continue
				}
				installerInstall(validDependency, "install", urlPackages, cachePath, CheckOnly)
			}
		}
		installerInstall(validItem, "install", urlPackages, cachePath, CheckOnly)
	}
}
func Uninstalls(uninstalls []string, catalogsMap map[int]map[string]catalog.Item, urlPackages, cachePath string, CheckOnly bool) {
	for _, item := range uninstalls {
		validItem, err := firstItem(item, catalogsMap)
		if err != nil {
			gorillalog.Warn(err)
			continue
		}
		installerInstall(validItem, "uninstall", urlPackages, cachePath, CheckOnly)
	}
}
func Updates(updates []string, catalogsMap map[int]map[string]catalog.Item, urlPackages, cachePath string, CheckOnly bool) {
	for _, item := range updates {
		validItem, err := firstItem(item, catalogsMap)
		if err != nil {
			gorillalog.Warn(err)
			continue
		}
		installerInstall(validItem, "update", urlPackages, cachePath, CheckOnly)
	}
}
func dirEmpty(path string) bool {
	f, err := os.Open(path)
	if err != nil {
		return false
	}
	defer f.Close()
	_, err = f.Readdir(1)
	return err == io.EOF
}