// ensureFood checks to see if the default fish food exists.
//
// If the pack does not exist, this function will create it.
// If it does, it will update to the latest.
435924
func ensureFood() error {
	ohai.Ohailn("Installing default fish food...")

	addArgs := []string{
		"https://github.com/fishworks/fish-food",
	}

	rigCmd, _, err := rootCmd.Find([]string{"rig", "add"})
	if err != nil {
		return err
	}
	return rigCmd.RunE(rigCmd, addArgs)
}
1077423
func (f *Feed) typecheck(typ reflect.Type) bool {
	if f.etype == nil {
		f.etype = typ
		return true
	}
	return f.etype == typ
}
679357
func (c *uploadContext) ensureFile(smudgePath, cleanPath, oid string) error {
	if _, err := os.Stat(cleanPath); err == nil {
		return nil
	}

	localPath := filepath.Join(cfg.LocalWorkingDir(), smudgePath)
	file, err := os.Open(localPath)
	if err != nil {
		if c.allowMissing {
			return nil
		}
		return errors.Wrapf(err, "Unable to find source for object %v (try running git lfs fetch --all)", oid)
	}

	defer file.Close()

	stat, err := file.Stat()
	if err != nil {
		return err
	}

	cleaned, err := c.gitfilter.Clean(file, file.Name(), stat.Size(), nil)
	if cleaned != nil {
		cleaned.Teardown()
	}

	if err != nil {
		return err
	}
	return nil
}
114975
func NotExist(values ...interface{}) (failureMessage string) {
	if !isNil(values[0]) {
		failureMessage = fmt.Sprintf("Expected `%v` is exist.", values[0])
	}
	return
}
1095583
func (g *GenOpts) CheckOpts() error {
	if !filepath.IsAbs(g.Target) {
		if _, err := filepath.Abs(g.Target); err != nil {
			return fmt.Errorf("could not locate target %s: %v", g.Target, err)
		}
	}
	if filepath.IsAbs(g.ServerPackage) {
		return fmt.Errorf("you shouldn't specify an absolute path in --server-package: %s", g.ServerPackage)
	}
	if !filepath.IsAbs(g.Spec) && !strings.HasPrefix(g.Spec, "http://") && !strings.HasPrefix(g.Spec, "https://") {
		if _, err := filepath.Abs(g.Spec); err != nil {
			return fmt.Errorf("could not locate spec: %s", g.Spec)
		}
	}
	return nil
}
213649
func (r *SqlAnnotationRepo) ensureTagsExist(sess *DBSession, tags []*models.Tag) ([]*models.Tag, error) {
	for _, tag := range tags {
		var existingTag models.Tag

		// check if it exists
		if exists, err := sess.Table("tag").Where(dialect.Quote("key")+"=? AND "+dialect.Quote("value")+"=?", tag.Key, tag.Value).Get(&existingTag); err != nil {
			return nil, err
		} else if exists {
			tag.Id = existingTag.Id
		} else {
			if _, err := sess.Table("tag").Insert(tag); err != nil {
				return nil, err
			}
		}
	}

	return tags, nil
}
1334908
func (srv *Projects) Ensure(c context.Context, req *projects.EnsureRequest) (*projects.Config, error) {
	srv.cfg.Store(req.GetId(), req.GetProject())
	return req.GetProject(), nil
}
1217298
func (a *availablePlugin) CheckHealth() {
	go func() {
		a.healthChan <- a.client.Ping()
	}()
	select {
	case err := <-a.healthChan:
		if err == nil {
			if a.failedHealthChecks > 0 {
				// only log on first ok health check
				log.WithFields(log.Fields{
					"_module":     "control-aplugin",
					"block":       "check-health",
					"plugin_name": a,
				}).Debug("health is ok")
			}
			a.failedHealthChecks = 0
		} else {
			a.healthCheckFailed()
		}
	case <-time.After(DefaultHealthCheckTimeout):
		a.healthCheckFailed()
	}
}
1199109
func (c *ZooKeeperBackend) ensurePath(path string, value []byte) error {
	nodes := strings.Split(path, "/")
	fullPath := ""
	for index, node := range nodes {
		if strings.TrimSpace(node) != "" {
			fullPath += "/" + node
			isLastNode := index+1 == len(nodes)

			// set parent nodes to nil, leaf to value
			// this block reduces round trips by being smart on the leaf create/set
			if exists, _, _ := c.client.Exists(fullPath); !isLastNode && !exists {
				if _, err := c.client.Create(fullPath, nil, int32(0), c.acl); err != nil {
					return err
				}
			} else if isLastNode && !exists {
				if _, err := c.client.Create(fullPath, value, int32(0), c.acl); err != nil {
					return err
				}
			} else if isLastNode && exists {
				if _, err := c.client.Set(fullPath, value, int32(-1)); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
629473
func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDescription, listeners []*elb.Listener) error {
	name := aws.StringValue(loadBalancer.LoadBalancerName)

	actual := loadBalancer.HealthCheck

	// Default AWS settings
	expectedHealthyThreshold := int64(2)
	expectedUnhealthyThreshold := int64(6)
	expectedTimeout := int64(5)
	expectedInterval := int64(10)

	// We only configure a TCP health-check on the first port
	expectedTarget := ""
	for _, listener := range listeners {
		if listener.InstancePort == nil {
			continue
		}
		expectedTarget = "TCP:" + strconv.FormatInt(*listener.InstancePort, 10)
		break
	}

	if expectedTarget == "" {
		return fmt.Errorf("unable to determine health check port for %q (no valid listeners)", name)
	}

	if expectedTarget == orEmpty(actual.Target) &&
		expectedHealthyThreshold == orZero(actual.HealthyThreshold) &&
		expectedUnhealthyThreshold == orZero(actual.UnhealthyThreshold) &&
		expectedTimeout == orZero(actual.Timeout) &&
		expectedInterval == orZero(actual.Interval) {
		return nil
	}

	glog.V(2).Infof("Updating load-balancer health-check for %q", name)

	healthCheck := &elb.HealthCheck{}
	healthCheck.HealthyThreshold = &expectedHealthyThreshold
	healthCheck.UnhealthyThreshold = &expectedUnhealthyThreshold
	healthCheck.Timeout = &expectedTimeout
	healthCheck.Interval = &expectedInterval
	healthCheck.Target = &expectedTarget

	request := &elb.ConfigureHealthCheckInput{}
	request.HealthCheck = healthCheck
	request.LoadBalancerName = loadBalancer.LoadBalancerName

	_, err := c.elb.ConfigureHealthCheck(request)
	if err != nil {
		return fmt.Errorf("error configuring load-balancer health-check for %q: %v", name, err)
	}

	return nil
}
278335
func ensureValidHelper(name string, funcValue reflect.Value) {
	if funcValue.Kind() != reflect.Func {
		panic(fmt.Errorf("Helper must be a function: %s", name))
	}

	funcType := funcValue.Type()

	if funcType.NumOut() != 1 {
		panic(fmt.Errorf("Helper function must return a string or a SafeString: %s", name))
	}

	// @todo Check if first returned value is a string, SafeString or interface{} ?
}
758950
func (runner *runner) EnsureRule(position RulePosition, table Table, chain Chain, args ...string) (bool, error) {
	fullArgs := makeFullArgs(table, chain, args...)

	runner.mu.Lock()
	defer runner.mu.Unlock()

	exists, err := runner.checkRule(table, chain, args...)
	if err != nil {
		return false, err
	}
	if exists {
		return true, nil
	}
	out, err := runner.run(operation(position), fullArgs)
	if err != nil {
		return false, fmt.Errorf("error appending rule: %v: %s", err, out)
	}
	return false, nil
}
883402
func (poc PortOpenCheck) Check() (warnings, errorList []error) {
	klog.V(1).Infof("validating availability of port %d", poc.port)
	errorList = []error{}
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", poc.port))
	if err != nil {
		errorList = append(errorList, errors.Errorf("Port %d is in use", poc.port))
	}
	if ln != nil {
		ln.Close()
	}

	return nil, errorList
}
731493
func (i *item) ensureInfo() error {
	// If lastModified is empty, so is hash. get info on the Item and
	// update the necessary fields at the same time.
	if i.lastModified.IsZero() || i.hash == "" || i.metadata == nil {
		i.infoOnce.Do(func() {
			itemInfo, infoErr := i.getInfo()
			if infoErr != nil {
				i.infoErr = infoErr
				return
			}
			i.hash, i.infoErr = itemInfo.ETag()
			if infoErr != nil {
				i.infoErr = infoErr
				return
			}
			i.lastModified, i.infoErr = itemInfo.LastMod()
			if infoErr != nil {
				i.infoErr = infoErr
				return
			}
			i.metadata, i.infoErr = itemInfo.Metadata()
			if infoErr != nil {
				i.infoErr = infoErr
				return
			}
		})
	}
	return i.infoErr
}
918853
func (c *ReferenceCollection) EnsureLog(name string) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_reference_ensure_log(c.repo.ptr, cname)
	runtime.KeepAlive(c)
	if ret < 0 {
		return MakeGitError(ret)
	}

	return nil
}
970644
func (c *BundlingChecker) PresumeExists(item *Item) {
	c.mu.Lock()
	defer c.mu.Unlock()
	c.existingDigests[string(item.Digest)] = struct{}{}
}
443394
func (d *DeviceMapperDriver) ensureInitialized() error {
	poolPath := d.poolDir()
	if err := os.MkdirAll(poolPath, 0755); err != nil && !os.IsExist(err) {
		return err
	}
	if err := volume.TouchFlagFile(poolPath); err != nil {
		return err
	}
	if d.DeviceSet == nil {
		var (
			thinPoolDev         string
			enableLVMMonitoring string
			dmoptions           []string
		)
		for _, option := range d.options {
			if strings.HasPrefix(option, "dm.") {
				dmoptions = append(dmoptions, option)
				if strings.HasPrefix(option, "dm.thinpooldev=") {
					thinPoolDev = strings.TrimPrefix(option, "dm.thinpooldev=")
					thinPoolDev = fmt.Sprintf("/dev/mapper/%s", strings.TrimPrefix(thinPoolDev, "/dev/mapper/"))
				}
			} else if strings.HasPrefix(option, "enablelvmmonitoring=") {
				enableLVMMonitoring = strings.TrimPrefix(option, "enablelvmmonitoring=")
			} else {
				glog.Errorf("Unable to parse option %s", option)
				return ErrInvalidOption
			}
		}
		dmoptions = append(dmoptions, "dm.fs=ext4")

		if err := d.verifyThinpoolDeviceUUID(thinPoolDev); err != nil {
			return err
		}

		deviceSet, err := devmapper.NewDeviceSet(poolPath, true, dmoptions, nil, nil)
		if err != nil {
			if _, thinError := err.(devmapper.ThinpoolInitError); thinError {
				//Try recreating the base image because sometimes something deletes it
				glog.Errorf("Error intializing thin pool device, %s, attempting to create to new base device", err)
				deviceSet, err = devmapper.NewDeviceSet(poolPath, false, d.options, nil, nil)
				if err != nil {
					return err
				}
				err = deviceSet.CreateBaseImage()
				if err != nil {
					return err
				}
			} else {
				return err
			}
		}

		d.DeviceSet = deviceSet
		if err := d.saveThinpoolDeviceUUID(thinPoolDev); err != nil {
			return err
		}
		prefix, err := GetDevicePrefix(poolPath)
		if err != nil {
			return err
		}
		d.DevicePrefix = prefix
		switch enableLVMMonitoring {
		case "y":
			if thinPoolDev != "" {
				glog.V(1).Infof("Enabling LVM Monitoring for thin pool device %s", thinPoolDev)
				cmd := exec.Command("lvchange", "--monitor", "y", thinPoolDev)
				output, err := cmd.CombinedOutput()
				if err != nil {
					glog.Errorf("Could not run command %v: %s (%s)", cmd, string(output), err)
					return err
				}
			} else {
				glog.Warningf("Ignoring option 'enablelvmmonitoring'; no thin pool device specified")
			}
		case "n", "":
			if thinPoolDev != "" {
				glog.V(1).Infof("Disabling LVM Monitoring for thin pool device %s", thinPoolDev)
				cmd := exec.Command("lvchange", "--monitor", "n", thinPoolDev)
				output, err := cmd.CombinedOutput()
				if err != nil {
					glog.Errorf("Could not run command %v: %s (%s)", cmd, string(output), err)
					return err
				}
			} else if enableLVMMonitoring != "" {
				glog.Warningf("Ignoring option 'enablelvmmonitoring'; no thin pool device specified")
			}
		default:
			glog.Errorf("Attribute %s is not defined for enablelvmmonitoring", enableLVMMonitoring)
			return ErrInvalidArg
		}
	}
	if err := os.MkdirAll(d.MetadataDir(), 0755); err != nil && !os.IsExist(err) {
		return err
	}
	return nil
}